LSL_Api.cs 738 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770
  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.Assets;
  31. using OpenMetaverse.Packets;
  32. using OpenMetaverse.Rendering;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.CoreModules.World.Land;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Region.Framework.Scenes.Animation;
  38. using OpenSim.Region.Framework.Scenes.Scripting;
  39. using OpenSim.Region.Framework.Scenes.Serialization;
  40. using OpenSim.Region.PhysicsModules.SharedBase;
  41. using OpenSim.Region.ScriptEngine.Interfaces;
  42. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  43. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  44. using OpenSim.Services.Interfaces;
  45. using OpenSim.Services.Connectors.Hypergrid;
  46. using System;
  47. using System.Collections;
  48. using System.Collections.Generic;
  49. using System.Collections.Specialized;
  50. using System.Diagnostics;
  51. using System.Drawing;
  52. using System.Globalization;
  53. using System.Reflection;
  54. using System.Runtime.Remoting.Lifetime;
  55. using System.Text;
  56. using System.Text.RegularExpressions;
  57. using System.Threading;
  58. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  59. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  60. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  61. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  62. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  63. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  64. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  65. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  66. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  67. using PermissionMask = OpenSim.Framework.PermissionMask;
  68. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  69. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  70. using RegionFlags = OpenSim.Framework.RegionFlags;
  71. using RegionInfo = OpenSim.Framework.RegionInfo;
  72. namespace OpenSim.Region.ScriptEngine.Shared.Api
  73. {
  74. /// <summary>
  75. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  76. /// </summary>
  77. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  78. {
  79. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  80. private int m_llRequestAgentDataCacheTimeout;
  81. public int LlRequestAgentDataCacheTimeoutMs
  82. {
  83. get
  84. {
  85. return 1000 * m_llRequestAgentDataCacheTimeout;
  86. }
  87. set
  88. {
  89. m_llRequestAgentDataCacheTimeout = value / 1000;
  90. }
  91. }
  92. protected IScriptEngine m_ScriptEngine;
  93. protected SceneObjectPart m_host;
  94. protected UUID RegionScopeID = UUID.Zero;
  95. /// <summary>
  96. /// The item that hosts this script
  97. /// </summary>
  98. protected TaskInventoryItem m_item;
  99. protected bool throwErrorOnNotImplemented = false;
  100. protected float m_ScriptDelayFactor = 1.0f;
  101. protected float m_ScriptDistanceFactor = 1.0f;
  102. protected float m_MinTimerInterval = 0.5f;
  103. protected float m_recoilScaleFactor = 0.0f;
  104. protected bool m_AllowGodFunctions;
  105. protected double m_timer = Util.GetTimeStampMS();
  106. protected bool m_waitingForScriptAnswer = false;
  107. protected bool m_automaticLinkPermission = false;
  108. protected int m_notecardLineReadCharsMax = 255;
  109. protected int m_scriptConsoleChannel = 0;
  110. protected bool m_scriptConsoleChannelEnabled = false;
  111. protected bool m_debuggerSafe = false;
  112. protected AsyncCommandManager m_AsyncCommands = null;
  113. protected IUrlModule m_UrlModule = null;
  114. protected IMaterialsModule m_materialsModule = null;
  115. protected IEnvironmentModule m_envModule = null;
  116. protected IEmailModule m_emailModule = null;
  117. protected IUserAccountService m_userAccountService = null;
  118. protected IMessageTransferModule m_TransferModule = null;
  119. protected ExpiringCacheOS<UUID, PresenceInfo> m_PresenceInfoCache = new ExpiringCacheOS<UUID, PresenceInfo>(10000);
  120. protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
  121. protected int m_sleepMsOnSetTexture = 200;
  122. protected int m_sleepMsOnSetLinkTexture = 200;
  123. protected int m_sleepMsOnScaleTexture = 200;
  124. protected int m_sleepMsOnOffsetTexture = 200;
  125. protected int m_sleepMsOnRotateTexture = 200;
  126. protected int m_sleepMsOnSetPos = 200;
  127. protected int m_sleepMsOnSetRot = 200;
  128. protected int m_sleepMsOnSetLocalRot = 200;
  129. protected int m_sleepMsOnPreloadSound = 1000;
  130. protected int m_sleepMsOnMakeExplosion = 100;
  131. protected int m_sleepMsOnMakeFountain = 100;
  132. protected int m_sleepMsOnMakeSmoke = 100;
  133. protected int m_sleepMsOnMakeFire = 100;
  134. protected int m_sleepMsOnRezAtRoot = 100;
  135. protected int m_sleepMsOnInstantMessage = 2000;
  136. protected int m_sleepMsOnEmail = 30000;
  137. protected int m_sleepMsOnCreateLink = 1000;
  138. protected int m_sleepMsOnGiveInventory = 3000;
  139. protected int m_sleepMsOnRequestAgentData = 100;
  140. protected int m_sleepMsOnRequestInventoryData = 1000;
  141. protected int m_sleepMsOnSetDamage = 5000;
  142. protected int m_sleepMsOnTextBox = 1000;
  143. protected int m_sleepMsOnAdjustSoundVolume = 100;
  144. protected int m_sleepMsOnEjectFromLand = 1000;
  145. protected int m_sleepMsOnAddToLandPassList = 100;
  146. protected int m_sleepMsOnDialog = 1000;
  147. protected int m_sleepMsOnRemoteLoadScript = 3000;
  148. protected int m_sleepMsOnRemoteLoadScriptPin = 3000;
  149. protected int m_sleepMsOnOpenRemoteDataChannel = 1000;
  150. protected int m_sleepMsOnSendRemoteData = 3000;
  151. protected int m_sleepMsOnRemoteDataReply = 3000;
  152. protected int m_sleepMsOnCloseRemoteDataChannel = 1000;
  153. protected int m_sleepMsOnSetPrimitiveParams = 200;
  154. protected int m_sleepMsOnSetLinkPrimitiveParams = 200;
  155. protected int m_sleepMsOnXorBase64Strings = 300;
  156. protected int m_sleepMsOnSetParcelMusicURL = 2000;
  157. protected int m_sleepMsOnGetPrimMediaParams = 1000;
  158. protected int m_sleepMsOnGetLinkMedia = 1000;
  159. protected int m_sleepMsOnSetPrimMediaParams = 1000;
  160. protected int m_sleepMsOnSetLinkMedia = 1000;
  161. protected int m_sleepMsOnClearPrimMedia = 1000;
  162. protected int m_sleepMsOnClearLinkMedia = 1000;
  163. protected int m_sleepMsOnRequestSimulatorData = 1000;
  164. protected int m_sleepMsOnLoadURL = 10000;
  165. protected int m_sleepMsOnParcelMediaCommandList = 2000;
  166. protected int m_sleepMsOnParcelMediaQuery = 2000;
  167. protected int m_sleepMsOnModPow = 1000;
  168. protected int m_sleepMsOnSetPrimURL = 2000;
  169. protected int m_sleepMsOnRefreshPrimURL = 20000;
  170. protected int m_sleepMsOnMapDestination = 1000;
  171. protected int m_sleepMsOnAddToLandBanList = 100;
  172. protected int m_sleepMsOnRemoveFromLandPassList = 100;
  173. protected int m_sleepMsOnRemoveFromLandBanList = 100;
  174. protected int m_sleepMsOnResetLandBanList = 100;
  175. protected int m_sleepMsOnResetLandPassList = 100;
  176. protected int m_sleepMsOnGetParcelPrimOwners = 2000;
  177. protected int m_sleepMsOnGetNumberOfNotecardLines = 100;
  178. protected int m_sleepMsOnGetNotecardLine = 100;
  179. protected string m_internalObjectHost = "lsl.opensim.local";
  180. protected bool m_restrictEmail = false;
  181. protected ISoundModule m_SoundModule = null;
  182. protected float m_avatarHeightCorrection = 0.2f;
  183. protected bool m_useSimpleBoxesInGetBoundingBox = false;
  184. protected bool m_addStatsInGetBoundingBox = false;
  185. //LSL Avatar Bounding Box (lABB), lower (1) and upper (2),
  186. //standing (Std), Groundsitting (Grs), Sitting (Sit),
  187. //along X, Y and Z axes, constants (0) and coefficients (1)
  188. protected float m_lABB1StdX0 = -0.275f;
  189. protected float m_lABB2StdX0 = 0.275f;
  190. protected float m_lABB1StdY0 = -0.35f;
  191. protected float m_lABB2StdY0 = 0.35f;
  192. protected float m_lABB1StdZ0 = -0.1f;
  193. protected float m_lABB1StdZ1 = -0.5f;
  194. protected float m_lABB2StdZ0 = 0.1f;
  195. protected float m_lABB2StdZ1 = 0.5f;
  196. protected float m_lABB1GrsX0 = -0.3875f;
  197. protected float m_lABB2GrsX0 = 0.3875f;
  198. protected float m_lABB1GrsY0 = -0.5f;
  199. protected float m_lABB2GrsY0 = 0.5f;
  200. protected float m_lABB1GrsZ0 = -0.05f;
  201. protected float m_lABB1GrsZ1 = -0.375f;
  202. protected float m_lABB2GrsZ0 = 0.5f;
  203. protected float m_lABB2GrsZ1 = 0.0f;
  204. protected float m_lABB1SitX0 = -0.5875f;
  205. protected float m_lABB2SitX0 = 0.1875f;
  206. protected float m_lABB1SitY0 = -0.35f;
  207. protected float m_lABB2SitY0 = 0.35f;
  208. protected float m_lABB1SitZ0 = -0.35f;
  209. protected float m_lABB1SitZ1 = -0.375f;
  210. protected float m_lABB2SitZ0 = -0.25f;
  211. protected float m_lABB2SitZ1 = 0.25f;
  212. protected float m_primSafetyCoeffX = 2.414214f;
  213. protected float m_primSafetyCoeffY = 2.414214f;
  214. protected float m_primSafetyCoeffZ = 1.618034f;
  215. protected float m_floatToleranceInCastRay = 0.00001f;
  216. protected float m_floatTolerance2InCastRay = 0.001f;
  217. protected DetailLevel m_primLodInCastRay = DetailLevel.Medium;
  218. protected DetailLevel m_sculptLodInCastRay = DetailLevel.Medium;
  219. protected DetailLevel m_meshLodInCastRay = DetailLevel.Highest;
  220. protected DetailLevel m_avatarLodInCastRay = DetailLevel.Medium;
  221. protected int m_maxHitsInCastRay = 16;
  222. protected int m_maxHitsPerPrimInCastRay = 16;
  223. protected int m_maxHitsPerObjectInCastRay = 16;
  224. protected bool m_detectExitsInCastRay = false;
  225. protected bool m_doAttachmentsInCastRay = false;
  226. protected int m_msThrottleInCastRay = 200;
  227. protected int m_msPerRegionInCastRay = 40;
  228. protected int m_msPerAvatarInCastRay = 10;
  229. protected int m_msMinInCastRay = 2;
  230. protected int m_msMaxInCastRay = 40;
  231. protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>();
  232. protected bool m_useMeshCacheInCastRay = true;
  233. protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>();
  234. // protected Timer m_ShoutSayTimer;
  235. protected int m_SayShoutCount = 0;
  236. DateTime m_lastSayShoutCheck;
  237. private int m_whisperdistance = 10;
  238. private int m_saydistance = 20;
  239. private int m_shoutdistance = 100;
  240. private string m_lsl_shard = "OpenSim";
  241. private string m_lsl_user_agent = string.Empty;
  242. private static readonly Dictionary<string, string> MovementAnimationsForLSL =
  243. new Dictionary<string, string> {
  244. {"CROUCH", "Crouching"},
  245. {"CROUCHWALK", "CrouchWalking"},
  246. {"FALLDOWN", "Falling Down"},
  247. {"FLY", "Flying"},
  248. {"FLYSLOW", "FlyingSlow"},
  249. {"HOVER", "Hovering"},
  250. {"HOVER_UP", "Hovering Up"},
  251. {"HOVER_DOWN", "Hovering Down"},
  252. {"JUMP", "Jumping"},
  253. {"LAND", "Landing"},
  254. {"PREJUMP", "PreJumping"},
  255. {"RUN", "Running"},
  256. {"SIT","Sitting"},
  257. {"SITGROUND","Sitting on Ground"},
  258. {"STAND", "Standing"},
  259. {"STANDUP", "Standing Up"},
  260. {"STRIDE","Striding"},
  261. {"SOFT_LAND", "Soft Landing"},
  262. {"TURNLEFT", "Turning Left"},
  263. {"TURNRIGHT", "Turning Right"},
  264. {"WALK", "Walking"}
  265. };
  266. //An array of HTTP/1.1 headers that are not allowed to be used
  267. //as custom headers by llHTTPRequest.
  268. private static readonly HashSet<string> HttpStandardHeaders = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
  269. {
  270. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  271. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  272. "Connection", "Content-Encoding", "Content-Language",
  273. "Content-Length", "Content-Location", "Content-MD5",
  274. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  275. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  276. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  277. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  278. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  279. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  280. "Vary", "Via", "Warning", "WWW-Authenticate"
  281. };
  282. private static readonly HashSet<string> HttpForbiddenInHeaders = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
  283. {
  284. "x-secondlife-shard", "x-secondlife-object-name", "x-secondlife-object-key",
  285. "x-secondlife-region", "x-secondlife-local-position", "x-secondlife-local-velocity",
  286. "x-secondlife-local-rotation", "x-secondlife-owner-name", "x-secondlife-owner-key",
  287. "connection", "content-length", "from", "host", "proxy-authorization",
  288. "referer", "trailer", "transfer-encoding", "via", "authorization"
  289. };
  290. public void Initialize(
  291. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  292. {
  293. m_lastSayShoutCheck = DateTime.UtcNow;
  294. m_ScriptEngine = scriptEngine;
  295. m_host = host;
  296. m_item = item;
  297. m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
  298. LoadConfig();
  299. m_TransferModule =
  300. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  301. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  302. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  303. m_materialsModule = m_ScriptEngine.World.RequestModuleInterface<IMaterialsModule>();
  304. m_emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  305. m_envModule = m_ScriptEngine.World.RequestModuleInterface< IEnvironmentModule>();
  306. m_AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  307. m_userAccountService = World.UserAccountService;
  308. if(World.RegionInfo != null)
  309. RegionScopeID = World.RegionInfo.ScopeID;
  310. }
  311. /// <summary>
  312. /// Load configuration items that affect script, object and run-time behavior. */
  313. /// </summary>
  314. private void LoadConfig()
  315. {
  316. LlRequestAgentDataCacheTimeoutMs = 20000;
  317. IConfig seConfig = m_ScriptEngine.Config;
  318. if (seConfig != null)
  319. {
  320. m_ScriptDelayFactor =
  321. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  322. m_ScriptDistanceFactor =
  323. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  324. m_MinTimerInterval =
  325. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  326. m_automaticLinkPermission =
  327. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  328. m_notecardLineReadCharsMax =
  329. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  330. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  331. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  332. // it by this factor. May be zero to turn off recoil all together.
  333. m_recoilScaleFactor = seConfig.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  334. m_AllowGodFunctions = seConfig.GetBoolean("AllowGodFunctions", false);
  335. }
  336. if (m_notecardLineReadCharsMax > 65535)
  337. m_notecardLineReadCharsMax = 65535;
  338. // load limits for particular subsystems.
  339. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  340. if (seConfigSource != null)
  341. {
  342. IConfig netConfig = seConfigSource.Configs["Network"];
  343. if (netConfig != null)
  344. {
  345. m_lsl_shard = netConfig.GetString("shard", m_lsl_shard);
  346. m_lsl_user_agent = netConfig.GetString("user_agent", m_lsl_user_agent);
  347. }
  348. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  349. if (lslConfig != null)
  350. {
  351. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  352. m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection);
  353. m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox);
  354. m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox);
  355. m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0);
  356. m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0);
  357. m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0);
  358. m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0);
  359. m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0);
  360. m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1);
  361. m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0);
  362. m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1);
  363. m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0);
  364. m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0);
  365. m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0);
  366. m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0);
  367. m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0);
  368. m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1);
  369. m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0);
  370. m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1);
  371. m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0);
  372. m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0);
  373. m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0);
  374. m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0);
  375. m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0);
  376. m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1);
  377. m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0);
  378. m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1);
  379. m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX);
  380. m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY);
  381. m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ);
  382. m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay);
  383. m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay);
  384. m_primLodInCastRay = (DetailLevel)lslConfig.GetInt("PrimDetailLevelInLlCastRay", (int)m_primLodInCastRay);
  385. m_sculptLodInCastRay = (DetailLevel)lslConfig.GetInt("SculptDetailLevelInLlCastRay", (int)m_sculptLodInCastRay);
  386. m_meshLodInCastRay = (DetailLevel)lslConfig.GetInt("MeshDetailLevelInLlCastRay", (int)m_meshLodInCastRay);
  387. m_avatarLodInCastRay = (DetailLevel)lslConfig.GetInt("AvatarDetailLevelInLlCastRay", (int)m_avatarLodInCastRay);
  388. m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay);
  389. m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay);
  390. m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay);
  391. m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay);
  392. m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay);
  393. m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay);
  394. m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay);
  395. m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay);
  396. m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay);
  397. m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay);
  398. m_useMeshCacheInCastRay = lslConfig.GetBoolean("UseMeshCacheInLlCastRay", m_useMeshCacheInCastRay);
  399. }
  400. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  401. if (smtpConfig != null)
  402. {
  403. // there's an smtp config, so load in the snooze time.
  404. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  405. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  406. }
  407. IConfig chatConfig = seConfigSource.Configs["SMTP"];
  408. if(chatConfig != null)
  409. {
  410. m_whisperdistance = chatConfig.GetInt("whisper_distance", m_whisperdistance);
  411. m_saydistance = chatConfig.GetInt("say_distance", m_saydistance);
  412. m_shoutdistance = chatConfig.GetInt("shout_distance", m_shoutdistance);
  413. }
  414. }
  415. m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000;
  416. }
  417. public override Object InitializeLifetimeService()
  418. {
  419. ILease lease = (ILease)base.InitializeLifetimeService();
  420. if (lease.CurrentState == LeaseState.Initial)
  421. {
  422. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  423. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  424. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  425. }
  426. return lease;
  427. }
  428. protected SceneObjectPart MonitoringObject()
  429. {
  430. UUID m = m_host.ParentGroup.MonitoringObject;
  431. if (m == UUID.Zero)
  432. return null;
  433. SceneObjectPart p = m_ScriptEngine.World.GetSceneObjectPart(m);
  434. if (p == null)
  435. m_host.ParentGroup.MonitoringObject = UUID.Zero;
  436. return p;
  437. }
  438. protected virtual void ScriptSleep(int delay)
  439. {
  440. delay = (int)(delay * m_ScriptDelayFactor);
  441. if (delay < 10)
  442. return;
  443. Sleep(delay);
  444. }
  445. protected virtual void Sleep(int delay)
  446. {
  447. if (m_item == null) // Some unit tests don't set this
  448. Thread.Sleep(delay);
  449. else
  450. m_ScriptEngine.SleepScript(m_item.ItemID, delay);
  451. }
  452. /// <summary>
  453. /// Check for co-operative termination.
  454. /// </summary>
  455. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  456. public Scene World
  457. {
  458. get { return m_ScriptEngine.World; }
  459. }
  460. [DebuggerNonUserCode]
  461. public void state(string newState)
  462. {
  463. m_ScriptEngine.SetState(m_item.ItemID, newState);
  464. }
  465. /// <summary>
  466. /// Reset the named script. The script must be present
  467. /// in the same prim.
  468. /// </summary>
  469. [DebuggerNonUserCode]
  470. public void llResetScript()
  471. {
  472. m_host.AddScriptLPS(1);
  473. // We need to tell the URL module, if we hav one, to release
  474. // the allocated URLs
  475. if (m_UrlModule != null)
  476. m_UrlModule.ScriptRemoved(m_item.ItemID);
  477. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  478. }
  479. public void llResetOtherScript(string name)
  480. {
  481. UUID item;
  482. if ((item = GetScriptByName(name)) == UUID.Zero)
  483. {
  484. m_host.AddScriptLPS(1);
  485. Error("llResetOtherScript", "Can't find script '" + name + "'");
  486. return;
  487. }
  488. if(item == m_item.ItemID)
  489. llResetScript();
  490. else
  491. {
  492. m_host.AddScriptLPS(1);
  493. m_ScriptEngine.ResetScript(item);
  494. }
  495. }
  496. public LSL_Integer llGetScriptState(string name)
  497. {
  498. UUID item;
  499. m_host.AddScriptLPS(1);
  500. if ((item = GetScriptByName(name)) != UUID.Zero)
  501. {
  502. return m_ScriptEngine.GetScriptState(item) ?1:0;
  503. }
  504. Error("llGetScriptState", "Can't find script '" + name + "'");
  505. // If we didn't find it, then it's safe to
  506. // assume it is not running.
  507. return 0;
  508. }
  509. public void llSetScriptState(string name, int run)
  510. {
  511. UUID item;
  512. m_host.AddScriptLPS(1);
  513. // These functions are supposed to be robust,
  514. // so get the state one step at a time.
  515. if ((item = GetScriptByName(name)) != UUID.Zero)
  516. {
  517. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true, item == m_item.ItemID);
  518. }
  519. else
  520. {
  521. Error("llSetScriptState", "Can't find script '" + name + "'");
  522. }
  523. }
  524. public List<ScenePresence> GetLinkAvatars(int linkType)
  525. {
  526. List<ScenePresence> ret = new List<ScenePresence>();
  527. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  528. return ret;
  529. // List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
  530. // this needs check
  531. List<ScenePresence> avs = m_host.ParentGroup.GetSittingAvatars();
  532. switch (linkType)
  533. {
  534. case ScriptBaseClass.LINK_SET:
  535. return avs;
  536. case ScriptBaseClass.LINK_ROOT:
  537. return ret;
  538. case ScriptBaseClass.LINK_ALL_OTHERS:
  539. return avs;
  540. case ScriptBaseClass.LINK_ALL_CHILDREN:
  541. return avs;
  542. case ScriptBaseClass.LINK_THIS:
  543. return ret;
  544. default:
  545. if (linkType < 0)
  546. return ret;
  547. int partCount = m_host.ParentGroup.GetPartCount();
  548. if (linkType <= partCount)
  549. {
  550. return ret;
  551. }
  552. else
  553. {
  554. linkType = linkType - partCount;
  555. if (linkType > avs.Count)
  556. {
  557. return ret;
  558. }
  559. else
  560. {
  561. ret.Add(avs[linkType-1]);
  562. return ret;
  563. }
  564. }
  565. }
  566. }
  567. /// <summary>
  568. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  569. /// </summary>
  570. /// <remarks>
  571. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  572. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  573. /// The ScenePresences receive linknums in the order in which they sat.
  574. /// </remarks>
  575. /// <returns>
  576. /// The link entity. null if not found.
  577. /// </returns>
  578. /// <param name='part'></param>
  579. /// <param name='linknum'>
  580. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  581. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  582. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  583. /// positive integer is given in this case then null is returned.
  584. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  585. /// of entities, then the entity which corresponds to that linknum is returned.
  586. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  587. /// null is returned.
  588. /// </param>
  589. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  590. {
  591. if (linknum < 0)
  592. {
  593. if (linknum == ScriptBaseClass.LINK_THIS)
  594. return part;
  595. else
  596. return null;
  597. }
  598. int actualPrimCount = part.ParentGroup.PrimCount;
  599. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  600. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  601. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  602. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  603. if (linknum == 0)
  604. {
  605. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  606. return part;
  607. return null;
  608. }
  609. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  610. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  611. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  612. {
  613. if (sittingAvatars.Count > 0)
  614. return part.ParentGroup.RootPart;
  615. else
  616. return null;
  617. }
  618. else if (linknum <= adjustedPrimCount)
  619. {
  620. if (linknum <= actualPrimCount)
  621. {
  622. return part.ParentGroup.GetLinkNumPart(linknum);
  623. }
  624. else
  625. {
  626. return sittingAvatars[linknum - actualPrimCount - 1];
  627. }
  628. }
  629. else
  630. {
  631. return null;
  632. }
  633. }
  634. public List<SceneObjectPart> GetLinkParts(int linkType)
  635. {
  636. return GetLinkParts(m_host, linkType);
  637. }
  638. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  639. {
  640. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  641. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  642. return ret;
  643. switch (linkType)
  644. {
  645. case ScriptBaseClass.LINK_SET:
  646. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  647. case ScriptBaseClass.LINK_ROOT:
  648. ret.Add(part.ParentGroup.RootPart);
  649. return ret;
  650. case ScriptBaseClass.LINK_ALL_OTHERS:
  651. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  652. if (ret.Contains(part))
  653. ret.Remove(part);
  654. return ret;
  655. case ScriptBaseClass.LINK_ALL_CHILDREN:
  656. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  657. if (ret.Contains(part.ParentGroup.RootPart))
  658. ret.Remove(part.ParentGroup.RootPart);
  659. return ret;
  660. case ScriptBaseClass.LINK_THIS:
  661. ret.Add(part);
  662. return ret;
  663. default:
  664. if (linkType < 0)
  665. return ret;
  666. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  667. if (target == null)
  668. return ret;
  669. ret.Add(target);
  670. return ret;
  671. }
  672. }
  673. public List<ISceneEntity> GetLinkEntities(int linkType)
  674. {
  675. return GetLinkEntities(m_host, linkType);
  676. }
  677. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  678. {
  679. List<ISceneEntity> ret;
  680. switch (linkType)
  681. {
  682. case ScriptBaseClass.LINK_SET:
  683. return new List<ISceneEntity>(part.ParentGroup.Parts);
  684. case ScriptBaseClass.LINK_ROOT:
  685. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  686. case ScriptBaseClass.LINK_ALL_OTHERS:
  687. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  688. if (ret.Contains(part))
  689. ret.Remove(part);
  690. return ret;
  691. case ScriptBaseClass.LINK_ALL_CHILDREN:
  692. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  693. if (ret.Contains(part.ParentGroup.RootPart))
  694. ret.Remove(part.ParentGroup.RootPart);
  695. List<ScenePresence> avs = part.ParentGroup.GetSittingAvatars();
  696. if(avs!= null && avs.Count > 0)
  697. ret.AddRange(avs);
  698. return ret;
  699. case ScriptBaseClass.LINK_THIS:
  700. return new List<ISceneEntity>() { part };
  701. default:
  702. if (linkType < 0)
  703. return new List<ISceneEntity>();
  704. ISceneEntity target = GetLinkEntity(part, linkType);
  705. if (target == null)
  706. return new List<ISceneEntity>();
  707. return new List<ISceneEntity>() { target };
  708. }
  709. }
  710. //These are the implementations of the various ll-functions used by the LSL scripts.
  711. public LSL_Float llSin(double f)
  712. {
  713. m_host.AddScriptLPS(1);
  714. return Math.Sin(f);
  715. }
  716. public LSL_Float llCos(double f)
  717. {
  718. m_host.AddScriptLPS(1);
  719. return Math.Cos(f);
  720. }
  721. public LSL_Float llTan(double f)
  722. {
  723. m_host.AddScriptLPS(1);
  724. return Math.Tan(f);
  725. }
  726. public LSL_Float llAtan2(LSL_Float x, LSL_Float y)
  727. {
  728. m_host.AddScriptLPS(1);
  729. return Math.Atan2(x, y);
  730. }
  731. public LSL_Float llSqrt(double f)
  732. {
  733. m_host.AddScriptLPS(1);
  734. return Math.Sqrt(f);
  735. }
  736. public LSL_Float llPow(double fbase, double fexponent)
  737. {
  738. m_host.AddScriptLPS(1);
  739. return (double)Math.Pow(fbase, fexponent);
  740. }
  741. public LSL_Integer llAbs(LSL_Integer i)
  742. {
  743. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  744. m_host.AddScriptLPS(1);
  745. if (i == Int32.MinValue)
  746. return i;
  747. else
  748. return (int)Math.Abs(i);
  749. }
  750. public LSL_Float llFabs(double f)
  751. {
  752. m_host.AddScriptLPS(1);
  753. return (double)Math.Abs(f);
  754. }
  755. public LSL_Float llFrand(double mag)
  756. {
  757. m_host.AddScriptLPS(1);
  758. lock (Util.RandomClass)
  759. {
  760. return Util.RandomClass.NextDouble() * mag;
  761. }
  762. }
  763. public LSL_Integer llFloor(double f)
  764. {
  765. m_host.AddScriptLPS(1);
  766. return (int)Math.Floor(f);
  767. }
  768. public LSL_Integer llCeil(double f)
  769. {
  770. m_host.AddScriptLPS(1);
  771. return (int)Math.Ceiling(f);
  772. }
  773. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  774. public LSL_Integer llRound(double f)
  775. {
  776. m_host.AddScriptLPS(1);
  777. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  778. }
  779. //This next group are vector operations involving squaring and square root. ckrinke
  780. public LSL_Float llVecMag(LSL_Vector v)
  781. {
  782. m_host.AddScriptLPS(1);
  783. return LSL_Vector.Mag(v);
  784. }
  785. public LSL_Vector llVecNorm(LSL_Vector v)
  786. {
  787. m_host.AddScriptLPS(1);
  788. return LSL_Vector.Norm(v);
  789. }
  790. private double VecDist(LSL_Vector a, LSL_Vector b)
  791. {
  792. double dx = a.x - b.x;
  793. double dy = a.y - b.y;
  794. double dz = a.z - b.z;
  795. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  796. }
  797. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  798. {
  799. m_host.AddScriptLPS(1);
  800. return VecDist(a, b);
  801. }
  802. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  803. // Utility function for llRot2Euler
  804. public LSL_Vector llRot2Euler(LSL_Rotation q1)
  805. {
  806. m_host.AddScriptLPS(1);
  807. LSL_Vector eul = new LSL_Vector();
  808. double sqw = q1.s*q1.s;
  809. double sqx = q1.x*q1.x;
  810. double sqy = q1.z*q1.z;
  811. double sqz = q1.y*q1.y;
  812. double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  813. double test = q1.x*q1.z + q1.y*q1.s;
  814. if (test > 0.4999*unit) { // singularity at north pole
  815. eul.z = 2 * Math.Atan2(q1.x,q1.s);
  816. eul.y = Math.PI/2;
  817. eul.x = 0;
  818. return eul;
  819. }
  820. if (test < -0.4999*unit) { // singularity at south pole
  821. eul.z = -2 * Math.Atan2(q1.x,q1.s);
  822. eul.y = -Math.PI/2;
  823. eul.x = 0;
  824. return eul;
  825. }
  826. eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
  827. eul.y = Math.Asin(2*test/unit);
  828. eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
  829. return eul;
  830. }
  831. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  832. {
  833. m_host.AddScriptLPS(1);
  834. double x,y,z,s;
  835. v.x *= 0.5;
  836. v.y *= 0.5;
  837. v.z *= 0.5;
  838. double c1 = Math.Cos(v.x);
  839. double c2 = Math.Cos(v.y);
  840. double c1c2 = c1 * c2;
  841. double s1 = Math.Sin(v.x);
  842. double s2 = Math.Sin(v.y);
  843. double s1s2 = s1 * s2;
  844. double c1s2 = c1 * s2;
  845. double s1c2 = s1 * c2;
  846. double c3 = Math.Cos(v.z);
  847. double s3 = Math.Sin(v.z);
  848. x = s1c2 * c3 + c1s2 * s3;
  849. y = c1s2 * c3 - s1c2 * s3;
  850. z = s1s2 * c3 + c1c2 * s3;
  851. s = c1c2 * c3 - s1s2 * s3;
  852. return new LSL_Rotation(x, y, z, s);
  853. }
  854. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  855. {
  856. m_host.AddScriptLPS(1);
  857. double s;
  858. double tr = fwd.x + left.y + up.z + 1.0;
  859. if (tr >= 1.0)
  860. {
  861. s = 0.5 / Math.Sqrt(tr);
  862. return new LSL_Rotation(
  863. (left.z - up.y) * s,
  864. (up.x - fwd.z) * s,
  865. (fwd.y - left.x) * s,
  866. 0.25 / s);
  867. }
  868. else
  869. {
  870. double max = (left.y > up.z) ? left.y : up.z;
  871. if (max < fwd.x)
  872. {
  873. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  874. double x = s * 0.5;
  875. s = 0.5 / s;
  876. return new LSL_Rotation(
  877. x,
  878. (fwd.y + left.x) * s,
  879. (up.x + fwd.z) * s,
  880. (left.z - up.y) * s);
  881. }
  882. else if (max == left.y)
  883. {
  884. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  885. double y = s * 0.5;
  886. s = 0.5 / s;
  887. return new LSL_Rotation(
  888. (fwd.y + left.x) * s,
  889. y,
  890. (left.z + up.y) * s,
  891. (up.x - fwd.z) * s);
  892. }
  893. else
  894. {
  895. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  896. double z = s * 0.5;
  897. s = 0.5 / s;
  898. return new LSL_Rotation(
  899. (up.x + fwd.z) * s,
  900. (left.z + up.y) * s,
  901. z,
  902. (fwd.y - left.x) * s);
  903. }
  904. }
  905. }
  906. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  907. {
  908. m_host.AddScriptLPS(1);
  909. double x, y, z, m;
  910. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  911. // m is always greater than zero
  912. // if m is not equal to 1 then Rotation needs to be normalized
  913. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  914. {
  915. m = 1.0 / Math.Sqrt(m);
  916. r.x *= m;
  917. r.y *= m;
  918. r.z *= m;
  919. r.s *= m;
  920. }
  921. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  922. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  923. y = 2 * (r.x * r.y + r.z * r.s);
  924. z = 2 * (r.x * r.z - r.y * r.s);
  925. return (new LSL_Vector(x, y, z));
  926. }
  927. public LSL_Vector llRot2Left(LSL_Rotation r)
  928. {
  929. m_host.AddScriptLPS(1);
  930. double x, y, z, m;
  931. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  932. // m is always greater than zero
  933. // if m is not equal to 1 then Rotation needs to be normalized
  934. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  935. {
  936. m = 1.0 / Math.Sqrt(m);
  937. r.x *= m;
  938. r.y *= m;
  939. r.z *= m;
  940. r.s *= m;
  941. }
  942. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  943. x = 2 * (r.x * r.y - r.z * r.s);
  944. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  945. z = 2 * (r.x * r.s + r.y * r.z);
  946. return (new LSL_Vector(x, y, z));
  947. }
  948. public LSL_Vector llRot2Up(LSL_Rotation r)
  949. {
  950. m_host.AddScriptLPS(1);
  951. double x, y, z, m;
  952. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  953. // m is always greater than zero
  954. // if m is not equal to 1 then Rotation needs to be normalized
  955. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  956. {
  957. m = 1.0 / Math.Sqrt(m);
  958. r.x *= m;
  959. r.y *= m;
  960. r.z *= m;
  961. r.s *= m;
  962. }
  963. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  964. x = 2 * (r.x * r.z + r.y * r.s);
  965. y = 2 * (-r.x * r.s + r.y * r.z);
  966. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  967. return (new LSL_Vector(x, y, z));
  968. }
  969. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  970. {
  971. //A and B should both be normalized
  972. m_host.AddScriptLPS(1);
  973. // This method mimics the 180 errors found in SL
  974. // See www.euclideanspace.com... angleBetween
  975. // Eliminate zero length
  976. LSL_Float vec_a_mag = LSL_Vector.MagSquare(a);
  977. LSL_Float vec_b_mag = LSL_Vector.MagSquare(b);
  978. if (vec_a_mag < 1e-12 ||
  979. vec_b_mag < 1e-12)
  980. {
  981. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  982. }
  983. // Normalize
  984. a = llVecNorm(a);
  985. b = llVecNorm(b);
  986. // Calculate axis and rotation angle
  987. LSL_Vector axis = a % b;
  988. LSL_Float cos_theta = a * b;
  989. // Check if parallel
  990. if (cos_theta > 0.99999)
  991. {
  992. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  993. }
  994. // Check if anti-parallel
  995. else if (cos_theta < -0.99999)
  996. {
  997. LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (a.x / (a * a) * a);
  998. if (LSL_Vector.MagSquare(orthog_axis) < 1e-12)
  999. orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
  1000. return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
  1001. }
  1002. else // other rotation
  1003. {
  1004. LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
  1005. axis = llVecNorm(axis);
  1006. double x, y, z, s, t;
  1007. s = Math.Cos(theta);
  1008. t = Math.Sin(theta);
  1009. x = axis.x * t;
  1010. y = axis.y * t;
  1011. z = axis.z * t;
  1012. return new LSL_Rotation(x,y,z,s);
  1013. }
  1014. }
  1015. public void llWhisper(int channelID, string text)
  1016. {
  1017. m_host.AddScriptLPS(1);
  1018. if (text.Length > 1023)
  1019. text = text.Substring(0, 1023);
  1020. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1021. World.SimChat(binText,
  1022. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1023. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1024. if (wComm != null)
  1025. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1026. }
  1027. private void CheckSayShoutTime()
  1028. {
  1029. DateTime now = DateTime.UtcNow;
  1030. if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
  1031. {
  1032. m_lastSayShoutCheck = now;
  1033. m_SayShoutCount = 0;
  1034. }
  1035. else
  1036. m_SayShoutCount++;
  1037. }
  1038. public void llSay(int channelID, string text)
  1039. {
  1040. m_host.AddScriptLPS(1);
  1041. if (channelID == 0)
  1042. // m_SayShoutCount++;
  1043. CheckSayShoutTime();
  1044. if (m_SayShoutCount >= 11)
  1045. ScriptSleep(2000);
  1046. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  1047. {
  1048. Console.WriteLine(text);
  1049. }
  1050. else
  1051. {
  1052. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1053. World.SimChat(binText,
  1054. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1055. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1056. if (wComm != null)
  1057. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1058. }
  1059. }
  1060. public void llShout(int channelID, string text)
  1061. {
  1062. m_host.AddScriptLPS(1);
  1063. if (channelID == 0)
  1064. // m_SayShoutCount++;
  1065. CheckSayShoutTime();
  1066. if (m_SayShoutCount >= 11)
  1067. ScriptSleep(2000);
  1068. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1069. World.SimChat(binText,
  1070. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1071. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1072. if (wComm != null)
  1073. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1074. }
  1075. public void llRegionSay(int channelID, string text)
  1076. {
  1077. if (channelID == 0)
  1078. {
  1079. Error("llRegionSay", "Cannot use on channel 0");
  1080. return;
  1081. }
  1082. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1083. m_host.AddScriptLPS(1);
  1084. // debug channel is also sent to avatars
  1085. if (channelID == ScriptBaseClass.DEBUG_CHANNEL)
  1086. {
  1087. World.SimChat(binText,
  1088. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1089. }
  1090. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1091. if (wComm != null)
  1092. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1093. }
  1094. public void llRegionSayTo(string target, int channel, string msg)
  1095. {
  1096. if (msg.Length > 1023)
  1097. msg = msg.Substring(0, 1023);
  1098. m_host.AddScriptLPS(1);
  1099. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  1100. return;
  1101. UUID.TryParse(target, out UUID TargetID);
  1102. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1103. if (wComm != null)
  1104. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  1105. }
  1106. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  1107. {
  1108. m_host.AddScriptLPS(1);
  1109. UUID.TryParse(ID, out UUID keyID);
  1110. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1111. if (wComm != null)
  1112. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  1113. else
  1114. return -1;
  1115. }
  1116. public void llListenControl(int number, int active)
  1117. {
  1118. m_host.AddScriptLPS(1);
  1119. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1120. if (wComm != null)
  1121. wComm.ListenControl(m_item.ItemID, number, active);
  1122. }
  1123. public void llListenRemove(int number)
  1124. {
  1125. m_host.AddScriptLPS(1);
  1126. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1127. if (wComm != null)
  1128. wComm.ListenRemove(m_item.ItemID, number);
  1129. }
  1130. public void llSensor(string name, string id, int type, double range, double arc)
  1131. {
  1132. m_host.AddScriptLPS(1);
  1133. UUID keyID = UUID.Zero;
  1134. UUID.TryParse(id, out keyID);
  1135. m_AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  1136. }
  1137. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  1138. {
  1139. m_host.AddScriptLPS(1);
  1140. UUID keyID = UUID.Zero;
  1141. UUID.TryParse(id, out keyID);
  1142. m_AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  1143. }
  1144. public void llSensorRemove()
  1145. {
  1146. m_host.AddScriptLPS(1);
  1147. m_AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  1148. }
  1149. public string resolveName(UUID objecUUID)
  1150. {
  1151. // try avatar username surname
  1152. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, objecUUID);
  1153. if (account != null)
  1154. {
  1155. string avatarname = account.Name;
  1156. return avatarname;
  1157. }
  1158. // try an scene object
  1159. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  1160. if (SOP != null)
  1161. {
  1162. string objectname = SOP.Name;
  1163. return objectname;
  1164. }
  1165. World.Entities.TryGetValue(objecUUID, out EntityBase SensedObject);
  1166. if (SensedObject == null)
  1167. {
  1168. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  1169. if (groups != null)
  1170. {
  1171. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  1172. if (gr != null)
  1173. return gr.GroupName;
  1174. }
  1175. return String.Empty;
  1176. }
  1177. return SensedObject.Name;
  1178. }
  1179. public LSL_String llDetectedName(int number)
  1180. {
  1181. m_host.AddScriptLPS(1);
  1182. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1183. if (detectedParams == null)
  1184. return String.Empty;
  1185. return detectedParams.Name;
  1186. }
  1187. public LSL_Key llDetectedKey(int number)
  1188. {
  1189. m_host.AddScriptLPS(1);
  1190. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1191. if (detectedParams == null)
  1192. return String.Empty;
  1193. return detectedParams.Key.ToString();
  1194. }
  1195. public LSL_Key llDetectedOwner(int number)
  1196. {
  1197. m_host.AddScriptLPS(1);
  1198. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1199. if (detectedParams == null)
  1200. return String.Empty;
  1201. return detectedParams.Owner.ToString();
  1202. }
  1203. public LSL_Integer llDetectedType(int number)
  1204. {
  1205. m_host.AddScriptLPS(1);
  1206. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1207. if (detectedParams == null)
  1208. return 0;
  1209. return new LSL_Integer(detectedParams.Type);
  1210. }
  1211. public LSL_Vector llDetectedPos(int number)
  1212. {
  1213. m_host.AddScriptLPS(1);
  1214. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1215. if (detectedParams == null)
  1216. return new LSL_Vector();
  1217. return detectedParams.Position;
  1218. }
  1219. public LSL_Vector llDetectedVel(int number)
  1220. {
  1221. m_host.AddScriptLPS(1);
  1222. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1223. if (detectedParams == null)
  1224. return new LSL_Vector();
  1225. return detectedParams.Velocity;
  1226. }
  1227. public LSL_Vector llDetectedGrab(int number)
  1228. {
  1229. m_host.AddScriptLPS(1);
  1230. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1231. if (parms == null)
  1232. return new LSL_Vector(0, 0, 0);
  1233. return parms.OffsetPos;
  1234. }
  1235. public LSL_Rotation llDetectedRot(int number)
  1236. {
  1237. m_host.AddScriptLPS(1);
  1238. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1239. if (detectedParams == null)
  1240. return new LSL_Rotation();
  1241. return detectedParams.Rotation;
  1242. }
  1243. public LSL_Integer llDetectedGroup(int number)
  1244. {
  1245. m_host.AddScriptLPS(1);
  1246. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1247. if (detectedParams == null)
  1248. return new LSL_Integer(0);
  1249. if (m_host.GroupID == detectedParams.Group)
  1250. return new LSL_Integer(1);
  1251. return new LSL_Integer(0);
  1252. }
  1253. public LSL_Integer llDetectedLinkNumber(int number)
  1254. {
  1255. m_host.AddScriptLPS(1);
  1256. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1257. if (parms == null)
  1258. return new LSL_Integer(0);
  1259. return new LSL_Integer(parms.LinkNum);
  1260. }
  1261. /// <summary>
  1262. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1263. /// </summary>
  1264. public LSL_Vector llDetectedTouchBinormal(int index)
  1265. {
  1266. m_host.AddScriptLPS(1);
  1267. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1268. if (detectedParams == null)
  1269. return new LSL_Vector();
  1270. return detectedParams.TouchBinormal;
  1271. }
  1272. /// <summary>
  1273. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1274. /// </summary>
  1275. public LSL_Integer llDetectedTouchFace(int index)
  1276. {
  1277. m_host.AddScriptLPS(1);
  1278. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1279. if (detectedParams == null)
  1280. return new LSL_Integer(-1);
  1281. return new LSL_Integer(detectedParams.TouchFace);
  1282. }
  1283. /// <summary>
  1284. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1285. /// </summary>
  1286. public LSL_Vector llDetectedTouchNormal(int index)
  1287. {
  1288. m_host.AddScriptLPS(1);
  1289. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1290. if (detectedParams == null)
  1291. return new LSL_Vector();
  1292. return detectedParams.TouchNormal;
  1293. }
  1294. /// <summary>
  1295. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1296. /// </summary>
  1297. public LSL_Vector llDetectedTouchPos(int index)
  1298. {
  1299. m_host.AddScriptLPS(1);
  1300. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1301. if (detectedParams == null)
  1302. return new LSL_Vector();
  1303. return detectedParams.TouchPos;
  1304. }
  1305. /// <summary>
  1306. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1307. /// </summary>
  1308. public LSL_Vector llDetectedTouchST(int index)
  1309. {
  1310. m_host.AddScriptLPS(1);
  1311. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1312. if (detectedParams == null)
  1313. return new LSL_Vector(-1.0, -1.0, 0.0);
  1314. return detectedParams.TouchST;
  1315. }
  1316. /// <summary>
  1317. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1318. /// </summary>
  1319. public LSL_Vector llDetectedTouchUV(int index)
  1320. {
  1321. m_host.AddScriptLPS(1);
  1322. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1323. if (detectedParams == null)
  1324. return new LSL_Vector(-1.0, -1.0, 0.0);
  1325. return detectedParams.TouchUV;
  1326. }
  1327. [DebuggerNonUserCode]
  1328. public virtual void llDie()
  1329. {
  1330. m_host.AddScriptLPS(1);
  1331. if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
  1332. }
  1333. public LSL_Float llGround(LSL_Vector offset)
  1334. {
  1335. m_host.AddScriptLPS(1);
  1336. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1337. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1338. LSL_Vector vsn = llGroundNormal(offset);
  1339. // Clamp to valid position
  1340. if (pos.X < 0)
  1341. pos.X = 0;
  1342. else if (pos.X >= World.Heightmap.Width)
  1343. pos.X = World.Heightmap.Width - 1;
  1344. if (pos.Y < 0)
  1345. pos.Y = 0;
  1346. else if (pos.Y >= World.Heightmap.Height)
  1347. pos.Y = World.Heightmap.Height - 1;
  1348. //Get the height for the integer coordinates from the Heightmap
  1349. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1350. //Calculate the difference between the actual coordinates and the integer coordinates
  1351. float xdiff = pos.X - (float)((int)pos.X);
  1352. float ydiff = pos.Y - (float)((int)pos.Y);
  1353. //Use the equation of the tangent plane to adjust the height to account for slope
  1354. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1355. }
  1356. public LSL_Float llCloud(LSL_Vector offset)
  1357. {
  1358. m_host.AddScriptLPS(1);
  1359. float cloudCover = 0f;
  1360. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1361. if (module != null)
  1362. {
  1363. Vector3 pos = m_host.GetWorldPosition();
  1364. int x = (int)(pos.X + offset.x);
  1365. int y = (int)(pos.Y + offset.y);
  1366. cloudCover = module.CloudCover(x, y, 0);
  1367. }
  1368. return cloudCover;
  1369. }
  1370. public LSL_Vector llWind(LSL_Vector offset)
  1371. {
  1372. m_host.AddScriptLPS(1);
  1373. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1374. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1375. if (module != null)
  1376. {
  1377. Vector3 pos = m_host.GetWorldPosition();
  1378. int x = (int)(pos.X + offset.x);
  1379. int y = (int)(pos.Y + offset.y);
  1380. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1381. wind.x = windSpeed.X;
  1382. wind.y = windSpeed.Y;
  1383. }
  1384. return wind;
  1385. }
  1386. public void llSetStatus(int status, int value)
  1387. {
  1388. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  1389. return;
  1390. m_host.AddScriptLPS(1);
  1391. int statusrotationaxis = 0;
  1392. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1393. {
  1394. if (value != 0)
  1395. {
  1396. SceneObjectGroup group = m_host.ParentGroup;
  1397. bool allow = true;
  1398. int maxprims = World.m_linksetPhysCapacity;
  1399. bool checkShape = (maxprims > 0 && group.PrimCount > maxprims);
  1400. foreach (SceneObjectPart part in group.Parts)
  1401. {
  1402. if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  1403. continue;
  1404. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1405. {
  1406. allow = false;
  1407. break;
  1408. }
  1409. if (checkShape)
  1410. {
  1411. if (--maxprims < 0)
  1412. {
  1413. allow = false;
  1414. break;
  1415. }
  1416. }
  1417. }
  1418. if (!allow)
  1419. return;
  1420. if (m_host.ParentGroup.RootPart.PhysActor != null &&
  1421. m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
  1422. return;
  1423. m_host.ScriptSetPhysicsStatus(true);
  1424. }
  1425. else
  1426. {
  1427. m_host.ScriptSetPhysicsStatus(false);
  1428. }
  1429. }
  1430. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1431. {
  1432. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1433. }
  1434. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1435. {
  1436. m_host.AddFlag(PrimFlags.CastShadows);
  1437. }
  1438. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1439. {
  1440. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1441. }
  1442. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1443. {
  1444. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1445. }
  1446. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1447. {
  1448. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1449. }
  1450. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1451. m_host.BlockGrab = value != 0;
  1452. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1453. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1454. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1455. {
  1456. if (value != 0)
  1457. m_host.SetDieAtEdge(true);
  1458. else
  1459. m_host.SetDieAtEdge(false);
  1460. }
  1461. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1462. {
  1463. if (value != 0)
  1464. m_host.SetReturnAtEdge(true);
  1465. else
  1466. m_host.SetReturnAtEdge(false);
  1467. }
  1468. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1469. {
  1470. if (value != 0)
  1471. m_host.SetStatusSandbox(true);
  1472. else
  1473. m_host.SetStatusSandbox(false);
  1474. }
  1475. if (statusrotationaxis != 0)
  1476. {
  1477. m_host.SetAxisRotation(statusrotationaxis, value);
  1478. }
  1479. }
  1480. private bool IsPhysical()
  1481. {
  1482. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1483. }
  1484. public LSL_Integer llGetStatus(int status)
  1485. {
  1486. m_host.AddScriptLPS(1);
  1487. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1488. switch (status)
  1489. {
  1490. case ScriptBaseClass.STATUS_PHYSICS:
  1491. return IsPhysical() ? 1 : 0;
  1492. case ScriptBaseClass.STATUS_PHANTOM:
  1493. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1494. {
  1495. return 1;
  1496. }
  1497. return 0;
  1498. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1499. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1500. {
  1501. return 1;
  1502. }
  1503. return 0;
  1504. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1505. return m_host.BlockGrab ? 1 : 0;
  1506. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1507. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1508. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1509. if (m_host.GetDieAtEdge())
  1510. return 1;
  1511. else
  1512. return 0;
  1513. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1514. if (m_host.GetReturnAtEdge())
  1515. return 1;
  1516. else
  1517. return 0;
  1518. case ScriptBaseClass.STATUS_ROTATE_X:
  1519. // if (m_host.GetAxisRotation(2) != 0)
  1520. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1521. return 1;
  1522. else
  1523. return 0;
  1524. case ScriptBaseClass.STATUS_ROTATE_Y:
  1525. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1526. return 1;
  1527. else
  1528. return 0;
  1529. case ScriptBaseClass.STATUS_ROTATE_Z:
  1530. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1531. return 1;
  1532. else
  1533. return 0;
  1534. case ScriptBaseClass.STATUS_SANDBOX:
  1535. if (m_host.GetStatusSandbox())
  1536. return 1;
  1537. else
  1538. return 0;
  1539. }
  1540. return 0;
  1541. }
  1542. public LSL_Integer llScaleByFactor(double scaling_factor)
  1543. {
  1544. m_host.AddScriptLPS(1);
  1545. SceneObjectGroup group = m_host.ParentGroup;
  1546. if(scaling_factor < 1e-6)
  1547. return ScriptBaseClass.FALSE;
  1548. if(scaling_factor > 1e6)
  1549. return ScriptBaseClass.FALSE;
  1550. if (group == null || group.IsDeleted || group.inTransit)
  1551. return ScriptBaseClass.FALSE;
  1552. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  1553. return ScriptBaseClass.FALSE;
  1554. if (group.RootPart.KeyframeMotion != null)
  1555. return ScriptBaseClass.FALSE;
  1556. if(group.GroupResize(scaling_factor))
  1557. return ScriptBaseClass.TRUE;
  1558. else
  1559. return ScriptBaseClass.FALSE;
  1560. }
  1561. public LSL_Float llGetMaxScaleFactor()
  1562. {
  1563. m_host.AddScriptLPS(1);
  1564. SceneObjectGroup group = m_host.ParentGroup;
  1565. if (group == null || group.IsDeleted || group.inTransit)
  1566. return 1.0f;
  1567. return (LSL_Float)group.GetMaxGroupResizeScale();
  1568. }
  1569. public LSL_Float llGetMinScaleFactor()
  1570. {
  1571. m_host.AddScriptLPS(1);
  1572. SceneObjectGroup group = m_host.ParentGroup;
  1573. if (group == null || group.IsDeleted || group.inTransit)
  1574. return 1.0f;
  1575. return (LSL_Float)group.GetMinGroupResizeScale();
  1576. }
  1577. public void llSetScale(LSL_Vector scale)
  1578. {
  1579. m_host.AddScriptLPS(1);
  1580. SetScale(m_host, scale);
  1581. }
  1582. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1583. {
  1584. // TODO: this needs to trigger a persistance save as well
  1585. if (part == null || part.ParentGroup.IsDeleted)
  1586. return;
  1587. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1588. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1589. if (pa != null && pa.IsPhysical)
  1590. {
  1591. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1592. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1593. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1594. }
  1595. else
  1596. {
  1597. // If not physical, then we clamp the scale to the non-physical min/max
  1598. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1599. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1600. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1601. }
  1602. Vector3 tmp = part.Scale;
  1603. tmp.X = (float)scale.x;
  1604. tmp.Y = (float)scale.y;
  1605. tmp.Z = (float)scale.z;
  1606. part.Scale = tmp;
  1607. part.ParentGroup.HasGroupChanged = true;
  1608. part.SendFullUpdateToAllClients();
  1609. }
  1610. public LSL_Vector llGetScale()
  1611. {
  1612. m_host.AddScriptLPS(1);
  1613. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1614. }
  1615. public void llSetClickAction(int action)
  1616. {
  1617. m_host.AddScriptLPS(1);
  1618. m_host.ClickAction = (byte)action;
  1619. m_host.ParentGroup.HasGroupChanged = true;
  1620. m_host.ScheduleFullUpdate();
  1621. return;
  1622. }
  1623. public void llSetColor(LSL_Vector color, int face)
  1624. {
  1625. m_host.AddScriptLPS(1);
  1626. SetColor(m_host, color, face);
  1627. }
  1628. protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
  1629. {
  1630. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1631. return;
  1632. m_host.SetFaceColorAlpha(face, color, null);
  1633. }
  1634. public void llSetContentType(LSL_Key reqid, LSL_Integer type)
  1635. {
  1636. m_host.AddScriptLPS(1);
  1637. if (m_UrlModule == null)
  1638. return;
  1639. if(!UUID.TryParse(reqid, out UUID id))
  1640. return;
  1641. // Make sure the content type is text/plain to start with
  1642. m_UrlModule.HttpContentType(id, "text/plain");
  1643. // Is the object owner online and in the region
  1644. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1645. if (agent == null || agent.IsChildAgent || agent.IsDeleted)
  1646. return; // Fail if the owner is not in the same region
  1647. // Is it the embeded browser?
  1648. string userAgent = m_UrlModule.GetHttpHeader(id, "user-agent");
  1649. if(string.IsNullOrEmpty(userAgent))
  1650. return;
  1651. if (userAgent.IndexOf("SecondLife") < 0)
  1652. return; // Not the embedded browser
  1653. // Use the IP address of the client and check against the request
  1654. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1655. // as the owner is in the region. Same as SL!
  1656. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1657. if (string.IsNullOrEmpty(logonFromIPAddress))
  1658. return;
  1659. string requestFromIPAddress = m_UrlModule.GetHttpHeader(id, "x-remote-ip");
  1660. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1661. if (requestFromIPAddress == null)
  1662. return;
  1663. requestFromIPAddress = requestFromIPAddress.Trim();
  1664. // If the request isnt from the same IP address then the request cannot be from the owner
  1665. if (!requestFromIPAddress.Equals(logonFromIPAddress))
  1666. return;
  1667. switch (type)
  1668. {
  1669. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1670. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1671. break;
  1672. case ScriptBaseClass.CONTENT_TYPE_XML:
  1673. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1674. break;
  1675. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1676. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1677. break;
  1678. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1679. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1680. break;
  1681. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1682. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1683. break;
  1684. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1685. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1686. break;
  1687. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1688. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1689. break;
  1690. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1691. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1692. break;
  1693. default:
  1694. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1695. break;
  1696. }
  1697. }
  1698. public void SetTexGen(SceneObjectPart part, int face,int style)
  1699. {
  1700. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1701. return;
  1702. Primitive.TextureEntry tex = part.Shape.Textures;
  1703. MappingType textype;
  1704. textype = MappingType.Default;
  1705. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1706. textype = MappingType.Planar;
  1707. int nsides = GetNumberOfSides(part);
  1708. if (face >= 0 && face < nsides)
  1709. {
  1710. tex.CreateFace((uint) face);
  1711. tex.FaceTextures[face].TexMapType = textype;
  1712. part.UpdateTextureEntry(tex);
  1713. return;
  1714. }
  1715. else if (face == ScriptBaseClass.ALL_SIDES)
  1716. {
  1717. for (uint i = 0; i < nsides; i++)
  1718. {
  1719. if (tex.FaceTextures[i] != null)
  1720. {
  1721. tex.FaceTextures[i].TexMapType = textype;
  1722. }
  1723. }
  1724. tex.DefaultTexture.TexMapType = textype;
  1725. part.UpdateTextureEntry(tex);
  1726. return;
  1727. }
  1728. }
  1729. public void SetGlow(SceneObjectPart part, int face, float glow)
  1730. {
  1731. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1732. return;
  1733. Primitive.TextureEntry tex = part.Shape.Textures;
  1734. int nsides = GetNumberOfSides(part);
  1735. if (face >= 0 && face < nsides)
  1736. {
  1737. tex.CreateFace((uint) face);
  1738. tex.FaceTextures[face].Glow = glow;
  1739. part.UpdateTextureEntry(tex);
  1740. return;
  1741. }
  1742. else if (face == ScriptBaseClass.ALL_SIDES)
  1743. {
  1744. for (uint i = 0; i < nsides; i++)
  1745. {
  1746. if (tex.FaceTextures[i] != null)
  1747. {
  1748. tex.FaceTextures[i].Glow = glow;
  1749. }
  1750. }
  1751. tex.DefaultTexture.Glow = glow;
  1752. part.UpdateTextureEntry(tex);
  1753. return;
  1754. }
  1755. }
  1756. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1757. {
  1758. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1759. return;
  1760. Shininess sval = new Shininess();
  1761. switch (shiny)
  1762. {
  1763. case 0:
  1764. sval = Shininess.None;
  1765. break;
  1766. case 1:
  1767. sval = Shininess.Low;
  1768. break;
  1769. case 2:
  1770. sval = Shininess.Medium;
  1771. break;
  1772. case 3:
  1773. sval = Shininess.High;
  1774. break;
  1775. default:
  1776. sval = Shininess.None;
  1777. break;
  1778. }
  1779. int nsides = GetNumberOfSides(part);
  1780. Primitive.TextureEntry tex = part.Shape.Textures;
  1781. if (face >= 0 && face < nsides)
  1782. {
  1783. tex.CreateFace((uint) face);
  1784. tex.FaceTextures[face].Shiny = sval;
  1785. tex.FaceTextures[face].Bump = bump;
  1786. part.UpdateTextureEntry(tex);
  1787. return;
  1788. }
  1789. else if (face == ScriptBaseClass.ALL_SIDES)
  1790. {
  1791. for (uint i = 0; i < nsides; i++)
  1792. {
  1793. if (tex.FaceTextures[i] != null)
  1794. {
  1795. tex.FaceTextures[i].Shiny = sval;
  1796. tex.FaceTextures[i].Bump = bump;
  1797. }
  1798. }
  1799. tex.DefaultTexture.Shiny = sval;
  1800. tex.DefaultTexture.Bump = bump;
  1801. part.UpdateTextureEntry(tex);
  1802. return;
  1803. }
  1804. }
  1805. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1806. {
  1807. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1808. return;
  1809. int nsides = GetNumberOfSides(part);
  1810. Primitive.TextureEntry tex = part.Shape.Textures;
  1811. if (face >= 0 && face < nsides)
  1812. {
  1813. tex.CreateFace((uint) face);
  1814. tex.FaceTextures[face].Fullbright = bright;
  1815. part.UpdateTextureEntry(tex);
  1816. return;
  1817. }
  1818. else if (face == ScriptBaseClass.ALL_SIDES)
  1819. {
  1820. for (uint i = 0; i < nsides; i++)
  1821. {
  1822. if (tex.FaceTextures[i] != null)
  1823. {
  1824. tex.FaceTextures[i].Fullbright = bright;
  1825. }
  1826. }
  1827. tex.DefaultTexture.Fullbright = bright;
  1828. part.UpdateTextureEntry(tex);
  1829. return;
  1830. }
  1831. }
  1832. public LSL_Float llGetAlpha(int face)
  1833. {
  1834. m_host.AddScriptLPS(1);
  1835. return GetAlpha(m_host, face);
  1836. }
  1837. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1838. {
  1839. Primitive.TextureEntry tex = part.Shape.Textures;
  1840. int nsides = GetNumberOfSides(part);
  1841. if (face == ScriptBaseClass.ALL_SIDES)
  1842. {
  1843. int i;
  1844. double sum = 0.0;
  1845. for (i = 0 ; i < nsides; i++)
  1846. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1847. return sum;
  1848. }
  1849. if (face >= 0 && face < nsides)
  1850. {
  1851. return (double)tex.GetFace((uint)face).RGBA.A;
  1852. }
  1853. return 0.0;
  1854. }
  1855. public void llSetAlpha(double alpha, int face)
  1856. {
  1857. m_host.AddScriptLPS(1);
  1858. SetAlpha(m_host, alpha, face);
  1859. }
  1860. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1861. {
  1862. m_host.AddScriptLPS(1);
  1863. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1864. if (parts.Count > 0)
  1865. {
  1866. try
  1867. {
  1868. foreach (SceneObjectPart part in parts)
  1869. SetAlpha(part, alpha, face);
  1870. }
  1871. finally { }
  1872. }
  1873. }
  1874. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1875. {
  1876. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1877. return;
  1878. Primitive.TextureEntry tex = part.Shape.Textures;
  1879. int nsides = GetNumberOfSides(part);
  1880. Color4 texcolor;
  1881. if (face >= 0 && face < nsides)
  1882. {
  1883. texcolor = tex.CreateFace((uint)face).RGBA;
  1884. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1885. tex.FaceTextures[face].RGBA = texcolor;
  1886. part.UpdateTextureEntry(tex);
  1887. return;
  1888. }
  1889. else if (face == ScriptBaseClass.ALL_SIDES)
  1890. {
  1891. for (int i = 0; i < nsides; i++)
  1892. {
  1893. if (tex.FaceTextures[i] != null)
  1894. {
  1895. texcolor = tex.FaceTextures[i].RGBA;
  1896. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1897. tex.FaceTextures[i].RGBA = texcolor;
  1898. }
  1899. }
  1900. // In some cases, the default texture can be null, eg when every face
  1901. // has a unique texture
  1902. if (tex.DefaultTexture != null)
  1903. {
  1904. texcolor = tex.DefaultTexture.RGBA;
  1905. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1906. tex.DefaultTexture.RGBA = texcolor;
  1907. }
  1908. part.UpdateTextureEntry(tex);
  1909. return;
  1910. }
  1911. }
  1912. /// <summary>
  1913. /// Set flexi parameters of a part.
  1914. ///
  1915. /// FIXME: Much of this code should probably be within the part itself.
  1916. /// </summary>
  1917. /// <param name="part"></param>
  1918. /// <param name="flexi"></param>
  1919. /// <param name="softness"></param>
  1920. /// <param name="gravity"></param>
  1921. /// <param name="friction"></param>
  1922. /// <param name="wind"></param>
  1923. /// <param name="tension"></param>
  1924. /// <param name="Force"></param>
  1925. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1926. float wind, float tension, LSL_Vector Force)
  1927. {
  1928. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1929. return;
  1930. if (flexi)
  1931. {
  1932. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1933. // work once the prim is already flexi
  1934. part.Shape.FlexiSoftness = softness;
  1935. part.Shape.FlexiGravity = gravity;
  1936. part.Shape.FlexiDrag = friction;
  1937. part.Shape.FlexiWind = wind;
  1938. part.Shape.FlexiTension = tension;
  1939. part.Shape.FlexiForceX = (float)Force.x;
  1940. part.Shape.FlexiForceY = (float)Force.y;
  1941. part.Shape.FlexiForceZ = (float)Force.z;
  1942. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  1943. }
  1944. else
  1945. {
  1946. // Other values not set, they do not seem to be sent to the viewer
  1947. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  1948. part.Shape.PathCurve = (byte)Extrusion.Straight;
  1949. part.Shape.FlexiEntry = false;
  1950. }
  1951. part.ParentGroup.HasGroupChanged = true;
  1952. part.ScheduleFullUpdate();
  1953. }
  1954. /// <summary>
  1955. /// Set a light point on a part
  1956. /// </summary>
  1957. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1958. ///
  1959. /// <param name="part"></param>
  1960. /// <param name="light"></param>
  1961. /// <param name="color"></param>
  1962. /// <param name="intensity"></param>
  1963. /// <param name="radius"></param>
  1964. /// <param name="falloff"></param>
  1965. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1966. {
  1967. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1968. return;
  1969. if (light)
  1970. {
  1971. part.Shape.LightEntry = true;
  1972. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  1973. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  1974. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  1975. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  1976. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  1977. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  1978. }
  1979. else
  1980. {
  1981. part.Shape.LightEntry = false;
  1982. }
  1983. part.ParentGroup.HasGroupChanged = true;
  1984. part.ScheduleFullUpdate();
  1985. }
  1986. public LSL_Vector llGetColor(int face)
  1987. {
  1988. m_host.AddScriptLPS(1);
  1989. return GetColor(m_host, face);
  1990. }
  1991. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  1992. {
  1993. Primitive.TextureEntry tex = part.Shape.Textures;
  1994. Color4 texcolor;
  1995. LSL_Vector rgb = new LSL_Vector();
  1996. int nsides = GetNumberOfSides(part);
  1997. if (face == ScriptBaseClass.ALL_SIDES)
  1998. {
  1999. int i;
  2000. for (i = 0; i < nsides; i++)
  2001. {
  2002. texcolor = tex.GetFace((uint)i).RGBA;
  2003. rgb.x += texcolor.R;
  2004. rgb.y += texcolor.G;
  2005. rgb.z += texcolor.B;
  2006. }
  2007. float invnsides = 1.0f / (float)nsides;
  2008. rgb.x *= invnsides;
  2009. rgb.y *= invnsides;
  2010. rgb.z *= invnsides;
  2011. return rgb;
  2012. }
  2013. if (face >= 0 && face < nsides)
  2014. {
  2015. texcolor = tex.GetFace((uint)face).RGBA;
  2016. rgb.x = texcolor.R;
  2017. rgb.y = texcolor.G;
  2018. rgb.z = texcolor.B;
  2019. return rgb;
  2020. }
  2021. else
  2022. {
  2023. return new LSL_Vector();
  2024. }
  2025. }
  2026. public void llSetTexture(string texture, int face)
  2027. {
  2028. m_host.AddScriptLPS(1);
  2029. SetTexture(m_host, texture, face);
  2030. ScriptSleep(m_sleepMsOnSetTexture);
  2031. }
  2032. public void llSetLinkTexture(int linknumber, string texture, int face)
  2033. {
  2034. m_host.AddScriptLPS(1);
  2035. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  2036. if (parts.Count > 0)
  2037. {
  2038. try
  2039. {
  2040. foreach (SceneObjectPart part in parts)
  2041. SetTexture(part, texture, face);
  2042. }
  2043. finally { }
  2044. }
  2045. ScriptSleep(m_sleepMsOnSetLinkTexture);
  2046. }
  2047. protected void SetTextureParams(SceneObjectPart part, string texture, double scaleU, double ScaleV,
  2048. double offsetU, double offsetV, double rotation, int face)
  2049. {
  2050. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2051. return;
  2052. UUID textureID = new UUID();
  2053. bool dotexture = true;
  2054. if(String.IsNullOrEmpty(texture) || texture == ScriptBaseClass.NULL_KEY)
  2055. dotexture = false;
  2056. else
  2057. {
  2058. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2059. if (textureID == UUID.Zero)
  2060. {
  2061. if (!UUID.TryParse(texture, out textureID))
  2062. dotexture = false;
  2063. }
  2064. }
  2065. Primitive.TextureEntry tex = part.Shape.Textures;
  2066. int nsides = GetNumberOfSides(part);
  2067. if (face >= 0 && face < nsides)
  2068. {
  2069. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2070. if (dotexture)
  2071. texface.TextureID = textureID;
  2072. texface.RepeatU = (float)scaleU;
  2073. texface.RepeatV = (float)ScaleV;
  2074. texface.OffsetU = (float)offsetU;
  2075. texface.OffsetV = (float)offsetV;
  2076. texface.Rotation = (float)rotation;
  2077. tex.FaceTextures[face] = texface;
  2078. part.UpdateTextureEntry(tex);
  2079. return;
  2080. }
  2081. else if (face == ScriptBaseClass.ALL_SIDES)
  2082. {
  2083. for (uint i = 0; i < nsides; i++)
  2084. {
  2085. if (tex.FaceTextures[i] != null)
  2086. {
  2087. if (dotexture)
  2088. tex.FaceTextures[i].TextureID = textureID;
  2089. tex.FaceTextures[i].RepeatU = (float)scaleU;
  2090. tex.FaceTextures[i].RepeatV = (float)ScaleV;
  2091. tex.FaceTextures[i].OffsetU = (float)offsetU;
  2092. tex.FaceTextures[i].OffsetV = (float)offsetV;
  2093. tex.FaceTextures[i].Rotation = (float)rotation;
  2094. }
  2095. }
  2096. if (dotexture)
  2097. tex.DefaultTexture.TextureID = textureID;
  2098. tex.DefaultTexture.RepeatU = (float)scaleU;
  2099. tex.DefaultTexture.RepeatV = (float)ScaleV;
  2100. tex.DefaultTexture.OffsetU = (float)offsetU;
  2101. tex.DefaultTexture.OffsetV = (float)offsetV;
  2102. tex.DefaultTexture.Rotation = (float)rotation;
  2103. part.UpdateTextureEntry(tex);
  2104. return;
  2105. }
  2106. }
  2107. protected void SetTexture(SceneObjectPart part, string texture, int face)
  2108. {
  2109. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2110. return;
  2111. UUID textureID = new UUID();
  2112. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2113. if (textureID == UUID.Zero)
  2114. {
  2115. if (!UUID.TryParse(texture, out textureID))
  2116. return;
  2117. }
  2118. Primitive.TextureEntry tex = part.Shape.Textures;
  2119. int nsides = GetNumberOfSides(part);
  2120. if (face >= 0 && face < nsides)
  2121. {
  2122. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2123. texface.TextureID = textureID;
  2124. tex.FaceTextures[face] = texface;
  2125. part.UpdateTextureEntry(tex);
  2126. return;
  2127. }
  2128. else if (face == ScriptBaseClass.ALL_SIDES)
  2129. {
  2130. for (uint i = 0; i < nsides; i++)
  2131. {
  2132. if (tex.FaceTextures[i] != null)
  2133. {
  2134. tex.FaceTextures[i].TextureID = textureID;
  2135. }
  2136. }
  2137. tex.DefaultTexture.TextureID = textureID;
  2138. part.UpdateTextureEntry(tex);
  2139. return;
  2140. }
  2141. }
  2142. public void llScaleTexture(double u, double v, int face)
  2143. {
  2144. m_host.AddScriptLPS(1);
  2145. ScaleTexture(m_host, u, v, face);
  2146. ScriptSleep(m_sleepMsOnScaleTexture);
  2147. }
  2148. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  2149. {
  2150. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2151. return;
  2152. Primitive.TextureEntry tex = part.Shape.Textures;
  2153. int nsides = GetNumberOfSides(part);
  2154. if (face >= 0 && face < nsides)
  2155. {
  2156. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2157. texface.RepeatU = (float)u;
  2158. texface.RepeatV = (float)v;
  2159. tex.FaceTextures[face] = texface;
  2160. part.UpdateTextureEntry(tex);
  2161. return;
  2162. }
  2163. if (face == ScriptBaseClass.ALL_SIDES)
  2164. {
  2165. for (int i = 0; i < nsides; i++)
  2166. {
  2167. if (tex.FaceTextures[i] != null)
  2168. {
  2169. tex.FaceTextures[i].RepeatU = (float)u;
  2170. tex.FaceTextures[i].RepeatV = (float)v;
  2171. }
  2172. }
  2173. tex.DefaultTexture.RepeatU = (float)u;
  2174. tex.DefaultTexture.RepeatV = (float)v;
  2175. part.UpdateTextureEntry(tex);
  2176. return;
  2177. }
  2178. }
  2179. public void llOffsetTexture(double u, double v, int face)
  2180. {
  2181. m_host.AddScriptLPS(1);
  2182. OffsetTexture(m_host, u, v, face);
  2183. ScriptSleep(m_sleepMsOnOffsetTexture);
  2184. }
  2185. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  2186. {
  2187. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2188. return;
  2189. Primitive.TextureEntry tex = part.Shape.Textures;
  2190. int nsides = GetNumberOfSides(part);
  2191. if (face >= 0 && face < nsides)
  2192. {
  2193. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2194. texface.OffsetU = (float)u;
  2195. texface.OffsetV = (float)v;
  2196. tex.FaceTextures[face] = texface;
  2197. part.UpdateTextureEntry(tex);
  2198. return;
  2199. }
  2200. if (face == ScriptBaseClass.ALL_SIDES)
  2201. {
  2202. for (int i = 0; i < nsides; i++)
  2203. {
  2204. if (tex.FaceTextures[i] != null)
  2205. {
  2206. tex.FaceTextures[i].OffsetU = (float)u;
  2207. tex.FaceTextures[i].OffsetV = (float)v;
  2208. }
  2209. }
  2210. tex.DefaultTexture.OffsetU = (float)u;
  2211. tex.DefaultTexture.OffsetV = (float)v;
  2212. part.UpdateTextureEntry(tex);
  2213. return;
  2214. }
  2215. }
  2216. public void llRotateTexture(double rotation, int face)
  2217. {
  2218. m_host.AddScriptLPS(1);
  2219. RotateTexture(m_host, rotation, face);
  2220. ScriptSleep(m_sleepMsOnRotateTexture);
  2221. }
  2222. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  2223. {
  2224. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2225. return;
  2226. Primitive.TextureEntry tex = part.Shape.Textures;
  2227. int nsides = GetNumberOfSides(part);
  2228. if (face >= 0 && face < nsides)
  2229. {
  2230. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2231. texface.Rotation = (float)rotation;
  2232. tex.FaceTextures[face] = texface;
  2233. part.UpdateTextureEntry(tex);
  2234. return;
  2235. }
  2236. if (face == ScriptBaseClass.ALL_SIDES)
  2237. {
  2238. for (int i = 0; i < nsides; i++)
  2239. {
  2240. if (tex.FaceTextures[i] != null)
  2241. {
  2242. tex.FaceTextures[i].Rotation = (float)rotation;
  2243. }
  2244. }
  2245. tex.DefaultTexture.Rotation = (float)rotation;
  2246. part.UpdateTextureEntry(tex);
  2247. return;
  2248. }
  2249. }
  2250. public LSL_String llGetTexture(int face)
  2251. {
  2252. m_host.AddScriptLPS(1);
  2253. return GetTexture(m_host, face);
  2254. }
  2255. protected LSL_String GetTexture(SceneObjectPart part, int face)
  2256. {
  2257. Primitive.TextureEntry tex = part.Shape.Textures;
  2258. int nsides = GetNumberOfSides(part);
  2259. if (face == ScriptBaseClass.ALL_SIDES)
  2260. {
  2261. face = 0;
  2262. }
  2263. if (face >= 0 && face < nsides)
  2264. {
  2265. Primitive.TextureEntryFace texface;
  2266. texface = tex.GetFace((uint)face);
  2267. string texture = texface.TextureID.ToString();
  2268. lock (part.TaskInventory)
  2269. {
  2270. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  2271. {
  2272. if (inv.Value.AssetID == texface.TextureID)
  2273. {
  2274. texture = inv.Value.Name.ToString();
  2275. break;
  2276. }
  2277. }
  2278. }
  2279. return texture;
  2280. }
  2281. else
  2282. {
  2283. return ScriptBaseClass.NULL_KEY;
  2284. }
  2285. }
  2286. public void llSetPos(LSL_Vector pos)
  2287. {
  2288. m_host.AddScriptLPS(1);
  2289. SetPos(m_host, pos, true);
  2290. ScriptSleep(m_sleepMsOnSetPos);
  2291. }
  2292. /// <summary>
  2293. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  2294. /// Documentation indicates that the use of x/y coordinates up to 10 meters outside the bounds of a region will work but do not specify what happens if there is no adjacent region for the object to move into.
  2295. /// Uses the RegionSize constant here rather than hard-coding 266.0 to alert any developer modifying OpenSim to support variable-sized regions that this method will need tweaking.
  2296. /// </summary>
  2297. /// <param name="pos"></param>
  2298. /// <returns>1 if successful, 0 otherwise.</returns>
  2299. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  2300. {
  2301. m_host.AddScriptLPS(1);
  2302. // BEGIN WORKAROUND
  2303. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  2304. //
  2305. // This workaround is to prevent silent failure of this function.
  2306. // According to the specification on the SL Wiki, providing a position outside of the
  2307. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  2308. {
  2309. return 0;
  2310. }
  2311. // END WORK AROUND
  2312. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  2313. IsPhysical() ||
  2314. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  2315. (
  2316. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  2317. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  2318. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  2319. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  2320. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  2321. )
  2322. )
  2323. {
  2324. return 0;
  2325. }
  2326. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  2327. // this could possibly be done in the above else-if block, but we're doing the check here to keep the code easier to read.
  2328. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  2329. LandData here = World.GetLandData(objectPos);
  2330. LandData there = World.GetLandData(pos);
  2331. // we're only checking prim limits if it's moving to a different parcel under the assumption that if the object got onto the parcel without exceeding the prim limits.
  2332. bool sameParcel = here.GlobalID == there.GlobalID;
  2333. if (!sameParcel && !World.Permissions.CanRezObject(
  2334. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  2335. {
  2336. return 0;
  2337. }
  2338. SetPos(m_host.ParentGroup.RootPart, pos, false);
  2339. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  2340. }
  2341. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2342. // note linked setpos is capped "differently"
  2343. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  2344. {
  2345. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  2346. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  2347. else
  2348. return end;
  2349. }
  2350. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
  2351. {
  2352. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2353. return fromPos;
  2354. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2355. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2356. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2357. if (part.ParentGroup.RootPart == part)
  2358. {
  2359. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2360. targetPos.z = ground;
  2361. }
  2362. if (adjust)
  2363. return SetPosAdjust(fromPos, targetPos);
  2364. return targetPos;
  2365. }
  2366. /// <summary>
  2367. /// set object position, optionally capping the distance.
  2368. /// </summary>
  2369. /// <param name="part"></param>
  2370. /// <param name="targetPos"></param>
  2371. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  2372. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  2373. {
  2374. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted || part.ParentGroup.inTransit)
  2375. return;
  2376. LSL_Vector currentPos = GetPartLocalPos(part);
  2377. LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
  2378. if (part.ParentGroup.RootPart == part)
  2379. {
  2380. SceneObjectGroup parent = part.ParentGroup;
  2381. if (!parent.IsAttachment && !World.Permissions.CanObjectEntry(parent, false, (Vector3)toPos))
  2382. return;
  2383. parent.UpdateGroupPosition((Vector3)toPos);
  2384. }
  2385. else
  2386. {
  2387. part.OffsetPosition = (Vector3)toPos;
  2388. // SceneObjectGroup parent = part.ParentGroup;
  2389. // parent.HasGroupChanged = true;
  2390. // parent.ScheduleGroupForTerseUpdate();
  2391. part.ScheduleTerseUpdate();
  2392. }
  2393. }
  2394. public LSL_Vector llGetPos()
  2395. {
  2396. m_host.AddScriptLPS(1);
  2397. return m_host.GetWorldPosition();
  2398. }
  2399. public LSL_Vector llGetLocalPos()
  2400. {
  2401. m_host.AddScriptLPS(1);
  2402. return GetPartLocalPos(m_host);
  2403. }
  2404. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  2405. {
  2406. m_host.AddScriptLPS(1);
  2407. Vector3 pos;
  2408. if (!part.IsRoot)
  2409. {
  2410. pos = part.OffsetPosition;
  2411. }
  2412. else
  2413. {
  2414. if (part.ParentGroup.IsAttachment)
  2415. pos = part.AttachedPos;
  2416. else
  2417. pos = part.AbsolutePosition;
  2418. }
  2419. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2420. return new LSL_Vector(pos);
  2421. }
  2422. public void llSetRot(LSL_Rotation rot)
  2423. {
  2424. m_host.AddScriptLPS(1);
  2425. // try to let this work as in SL...
  2426. if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
  2427. {
  2428. // special case: If we are root, rotate complete SOG to new rotation
  2429. SetRot(m_host, rot);
  2430. }
  2431. else
  2432. {
  2433. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2434. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2435. if (rootPart != null) // better safe than sorry
  2436. {
  2437. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2438. }
  2439. }
  2440. ScriptSleep(m_sleepMsOnSetRot);
  2441. }
  2442. public void llSetLocalRot(LSL_Rotation rot)
  2443. {
  2444. m_host.AddScriptLPS(1);
  2445. SetRot(m_host, rot);
  2446. ScriptSleep(m_sleepMsOnSetLocalRot);
  2447. }
  2448. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2449. {
  2450. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2451. return;
  2452. bool isroot = (part == part.ParentGroup.RootPart);
  2453. bool isphys;
  2454. PhysicsActor pa = part.PhysActor;
  2455. // keep using physactor ideia of isphysical
  2456. // it should be SOP ideia of that
  2457. // not much of a issue with ubOde
  2458. if (pa != null && pa.IsPhysical)
  2459. isphys = true;
  2460. else
  2461. isphys = false;
  2462. // SL doesn't let scripts rotate root of physical linksets
  2463. if (isroot && isphys)
  2464. return;
  2465. part.UpdateRotation(rot);
  2466. // Update rotation does not move the object in the physics engine if it's a non physical linkset
  2467. // so do a nasty update of parts positions if is a root part rotation
  2468. if (isroot && pa != null) // with if above implies non physical root part
  2469. {
  2470. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2471. }
  2472. else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
  2473. {
  2474. // List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
  2475. List<ScenePresence> sittingavas = part.ParentGroup.GetSittingAvatars();
  2476. if (sittingavas.Count > 0)
  2477. {
  2478. foreach (ScenePresence av in sittingavas)
  2479. {
  2480. if (isroot || part.LocalId == av.ParentID)
  2481. av.SendTerseUpdateToAllClients();
  2482. }
  2483. }
  2484. }
  2485. }
  2486. /// <summary>
  2487. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2488. /// </summary>
  2489. public LSL_Rotation llGetRot()
  2490. {
  2491. // unlinked or root prim then use llRootRotation
  2492. // see llRootRotaion for references.
  2493. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2494. {
  2495. return llGetRootRotation();
  2496. }
  2497. m_host.AddScriptLPS(1);
  2498. Quaternion q = m_host.GetWorldRotation();
  2499. if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
  2500. {
  2501. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2502. if (avatar != null)
  2503. {
  2504. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2505. q = avatar.CameraRotation * q; // Mouselook
  2506. else
  2507. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2508. }
  2509. }
  2510. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2511. }
  2512. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2513. {
  2514. Quaternion q;
  2515. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2516. {
  2517. if (part.ParentGroup.AttachmentPoint != 0)
  2518. {
  2519. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2520. if (avatar != null)
  2521. {
  2522. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2523. q = avatar.CameraRotation; // Mouselook
  2524. else
  2525. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2526. }
  2527. else
  2528. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2529. }
  2530. else
  2531. q = part.ParentGroup.GroupRotation; // just the group rotation
  2532. return new LSL_Rotation(q);
  2533. }
  2534. q = part.GetWorldRotation();
  2535. if (part.ParentGroup.AttachmentPoint != 0)
  2536. {
  2537. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2538. if (avatar != null)
  2539. {
  2540. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2541. q = avatar.CameraRotation * q; // Mouselook
  2542. else
  2543. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2544. }
  2545. }
  2546. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2547. }
  2548. public LSL_Rotation llGetLocalRot()
  2549. {
  2550. return GetPartLocalRot(m_host);
  2551. }
  2552. private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
  2553. {
  2554. m_host.AddScriptLPS(1);
  2555. Quaternion rot = part.RotationOffset;
  2556. return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
  2557. }
  2558. public void llSetForce(LSL_Vector force, int local)
  2559. {
  2560. m_host.AddScriptLPS(1);
  2561. if (!m_host.ParentGroup.IsDeleted)
  2562. {
  2563. if (local != 0)
  2564. force *= llGetRot();
  2565. m_host.ParentGroup.RootPart.SetForce(force);
  2566. }
  2567. }
  2568. public LSL_Vector llGetForce()
  2569. {
  2570. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2571. m_host.AddScriptLPS(1);
  2572. if (!m_host.ParentGroup.IsDeleted)
  2573. {
  2574. force = m_host.ParentGroup.RootPart.GetForce();
  2575. }
  2576. return force;
  2577. }
  2578. public void llSetVelocity(LSL_Vector vel, int local)
  2579. {
  2580. m_host.AddScriptLPS(1);
  2581. m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
  2582. }
  2583. public void llSetAngularVelocity(LSL_Vector avel, int local)
  2584. {
  2585. m_host.AddScriptLPS(1);
  2586. m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
  2587. }
  2588. public LSL_Integer llTarget(LSL_Vector position, double range)
  2589. {
  2590. m_host.AddScriptLPS(1);
  2591. return m_host.ParentGroup.RegisterTargetWaypoint(m_item.ItemID, position, (float)range);
  2592. }
  2593. public void llTargetRemove(int number)
  2594. {
  2595. m_host.AddScriptLPS(1);
  2596. m_host.ParentGroup.UnregisterTargetWaypoint(number);
  2597. }
  2598. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  2599. {
  2600. m_host.AddScriptLPS(1);
  2601. return m_host.ParentGroup.RegisterRotTargetWaypoint(m_item.ItemID, rot, (float)error);
  2602. }
  2603. public void llRotTargetRemove(int number)
  2604. {
  2605. m_host.AddScriptLPS(1);
  2606. m_host.ParentGroup.UnRegisterRotTargetWaypoint(number);
  2607. }
  2608. public void llMoveToTarget(LSL_Vector target, double tau)
  2609. {
  2610. m_host.AddScriptLPS(1);
  2611. m_host.ParentGroup.MoveToTarget(target, (float)tau);
  2612. }
  2613. public void llStopMoveToTarget()
  2614. {
  2615. m_host.AddScriptLPS(1);
  2616. m_host.ParentGroup.StopMoveToTarget();
  2617. }
  2618. public void llApplyImpulse(LSL_Vector force, LSL_Integer local)
  2619. {
  2620. m_host.AddScriptLPS(1);
  2621. //No energy force yet
  2622. Vector3 v = force;
  2623. if (v.Length() > 20000.0f)
  2624. {
  2625. v.Normalize();
  2626. v = v * 20000.0f;
  2627. }
  2628. m_host.ApplyImpulse(v, local != 0);
  2629. }
  2630. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  2631. {
  2632. m_host.AddScriptLPS(1);
  2633. m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
  2634. }
  2635. public void llSetTorque(LSL_Vector torque, int local)
  2636. {
  2637. m_host.AddScriptLPS(1);
  2638. m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
  2639. }
  2640. public LSL_Vector llGetTorque()
  2641. {
  2642. m_host.AddScriptLPS(1);
  2643. return new LSL_Vector(m_host.ParentGroup.GetTorque());
  2644. }
  2645. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  2646. {
  2647. m_host.AddScriptLPS(1);
  2648. llSetForce(force, local);
  2649. llSetTorque(torque, local);
  2650. }
  2651. public LSL_Vector llGetVel()
  2652. {
  2653. m_host.AddScriptLPS(1);
  2654. Vector3 vel = Vector3.Zero;
  2655. if (m_host.ParentGroup.IsAttachment)
  2656. {
  2657. ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2658. if (avatar != null)
  2659. vel = avatar.GetWorldVelocity();
  2660. }
  2661. else
  2662. {
  2663. vel = m_host.ParentGroup.RootPart.Velocity;
  2664. }
  2665. return new LSL_Vector(vel);
  2666. }
  2667. public LSL_Vector llGetAccel()
  2668. {
  2669. m_host.AddScriptLPS(1);
  2670. return new LSL_Vector(m_host.Acceleration);
  2671. }
  2672. public LSL_Vector llGetOmega()
  2673. {
  2674. m_host.AddScriptLPS(1);
  2675. Vector3 avel = m_host.AngularVelocity;
  2676. return new LSL_Vector(avel.X, avel.Y, avel.Z);
  2677. }
  2678. public LSL_Float llGetTimeOfDay()
  2679. {
  2680. m_host.AddScriptLPS(1);
  2681. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  2682. }
  2683. public LSL_Float llGetWallclock()
  2684. {
  2685. m_host.AddScriptLPS(1);
  2686. return DateTime.Now.TimeOfDay.TotalSeconds;
  2687. }
  2688. public LSL_Float llGetTime()
  2689. {
  2690. m_host.AddScriptLPS(1);
  2691. double ScriptTime = Util.GetTimeStampMS() - m_timer;
  2692. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2693. }
  2694. public void llResetTime()
  2695. {
  2696. m_host.AddScriptLPS(1);
  2697. m_timer = Util.GetTimeStampMS();
  2698. }
  2699. public LSL_Float llGetAndResetTime()
  2700. {
  2701. m_host.AddScriptLPS(1);
  2702. double now = Util.GetTimeStampMS();
  2703. double ScriptTime = now - m_timer;
  2704. m_timer = now;
  2705. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2706. }
  2707. public void llSound(string sound, double volume, int queue, int loop)
  2708. {
  2709. m_host.AddScriptLPS(1);
  2710. Deprecated("llSound", "Use llPlaySound instead");
  2711. }
  2712. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2713. // 20080530 Updated to remove code duplication
  2714. public void llPlaySound(string sound, double volume)
  2715. {
  2716. m_host.AddScriptLPS(1);
  2717. if (m_SoundModule == null)
  2718. return;
  2719. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2720. if(soundID == UUID.Zero)
  2721. return;
  2722. // send the sound, once, to all clients in range
  2723. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, false, false);
  2724. }
  2725. public void llLoopSound(string sound, double volume)
  2726. {
  2727. m_host.AddScriptLPS(1);
  2728. if (m_SoundModule == null)
  2729. return;
  2730. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2731. if(soundID == UUID.Zero)
  2732. return;
  2733. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false,false);
  2734. }
  2735. public void llLoopSoundMaster(string sound, double volume)
  2736. {
  2737. m_host.AddScriptLPS(1);
  2738. if (m_SoundModule == null)
  2739. return;
  2740. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2741. if(soundID == UUID.Zero)
  2742. return;
  2743. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, true, false);
  2744. }
  2745. public void llLoopSoundSlave(string sound, double volume)
  2746. {
  2747. m_host.AddScriptLPS(1);
  2748. if (m_SoundModule == null)
  2749. return;
  2750. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2751. if(soundID == UUID.Zero)
  2752. return;
  2753. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false, true);
  2754. }
  2755. public void llPlaySoundSlave(string sound, double volume)
  2756. {
  2757. m_host.AddScriptLPS(1);
  2758. if (m_SoundModule == null)
  2759. return;
  2760. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2761. if(soundID == UUID.Zero)
  2762. return;
  2763. // send the sound, once, to all clients in range
  2764. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, true, false);
  2765. }
  2766. public void llTriggerSound(string sound, double volume)
  2767. {
  2768. m_host.AddScriptLPS(1);
  2769. if (m_SoundModule == null)
  2770. return;
  2771. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2772. if(soundID == UUID.Zero)
  2773. return;
  2774. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2775. m_SoundModule.SendSound(m_host.UUID, soundID, volume, true, 0, false, false);
  2776. }
  2777. public void llStopSound()
  2778. {
  2779. m_host.AddScriptLPS(1);
  2780. if (m_SoundModule != null)
  2781. m_SoundModule.StopSound(m_host.UUID);
  2782. }
  2783. public void llPreloadSound(string sound)
  2784. {
  2785. m_host.AddScriptLPS(1);
  2786. if (m_SoundModule == null)
  2787. return;
  2788. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2789. if(soundID == UUID.Zero)
  2790. return;
  2791. m_SoundModule.PreloadSound(m_host.UUID, soundID);
  2792. ScriptSleep(m_sleepMsOnPreloadSound);
  2793. }
  2794. /// <summary>
  2795. /// Return a portion of the designated string bounded by
  2796. /// inclusive indices (start and end). As usual, the negative
  2797. /// indices, and the tolerance for out-of-bound values, makes
  2798. /// this more complicated than it might otherwise seem.
  2799. /// </summary>
  2800. public LSL_String llGetSubString(string src, int start, int end)
  2801. {
  2802. m_host.AddScriptLPS(1);
  2803. // Normalize indices (if negative).
  2804. // After normlaization they may still be
  2805. // negative, but that is now relative to
  2806. // the start, rather than the end, of the
  2807. // sequence.
  2808. if (start < 0)
  2809. {
  2810. start = src.Length+start;
  2811. }
  2812. if (end < 0)
  2813. {
  2814. end = src.Length+end;
  2815. }
  2816. // Conventional substring
  2817. if (start <= end)
  2818. {
  2819. // Implies both bounds are out-of-range.
  2820. if (end < 0 || start >= src.Length)
  2821. {
  2822. return String.Empty;
  2823. }
  2824. // If end is positive, then it directly
  2825. // corresponds to the lengt of the substring
  2826. // needed (plus one of course). BUT, it
  2827. // must be within bounds.
  2828. if (end >= src.Length)
  2829. {
  2830. end = src.Length-1;
  2831. }
  2832. if (start < 0)
  2833. {
  2834. return src.Substring(0,end+1);
  2835. }
  2836. // Both indices are positive
  2837. return src.Substring(start, (end+1) - start);
  2838. }
  2839. // Inverted substring (end < start)
  2840. else
  2841. {
  2842. // Implies both indices are below the
  2843. // lower bound. In the inverted case, that
  2844. // means the entire string will be returned
  2845. // unchanged.
  2846. if (start < 0)
  2847. {
  2848. return src;
  2849. }
  2850. // If both indices are greater than the upper
  2851. // bound the result may seem initially counter
  2852. // intuitive.
  2853. if (end >= src.Length)
  2854. {
  2855. return src;
  2856. }
  2857. if (end < 0)
  2858. {
  2859. if (start < src.Length)
  2860. {
  2861. return src.Substring(start);
  2862. }
  2863. else
  2864. {
  2865. return String.Empty;
  2866. }
  2867. }
  2868. else
  2869. {
  2870. if (start < src.Length)
  2871. {
  2872. return src.Substring(0,end+1) + src.Substring(start);
  2873. }
  2874. else
  2875. {
  2876. return src.Substring(0,end+1);
  2877. }
  2878. }
  2879. }
  2880. }
  2881. /// <summary>
  2882. /// Delete substring removes the specified substring bounded
  2883. /// by the inclusive indices start and end. Indices may be
  2884. /// negative (indicating end-relative) and may be inverted,
  2885. /// i.e. end < start.
  2886. /// </summary>
  2887. public LSL_String llDeleteSubString(string src, int start, int end)
  2888. {
  2889. m_host.AddScriptLPS(1);
  2890. // Normalize indices (if negative).
  2891. // After normlaization they may still be
  2892. // negative, but that is now relative to
  2893. // the start, rather than the end, of the
  2894. // sequence.
  2895. if (start < 0)
  2896. {
  2897. start = src.Length+start;
  2898. }
  2899. if (end < 0)
  2900. {
  2901. end = src.Length+end;
  2902. }
  2903. // Conventionally delimited substring
  2904. if (start <= end)
  2905. {
  2906. // If both bounds are outside of the existing
  2907. // string, then return unchanges.
  2908. if (end < 0 || start >= src.Length)
  2909. {
  2910. return src;
  2911. }
  2912. // At least one bound is in-range, so we
  2913. // need to clip the out-of-bound argument.
  2914. if (start < 0)
  2915. {
  2916. start = 0;
  2917. }
  2918. if (end >= src.Length)
  2919. {
  2920. end = src.Length-1;
  2921. }
  2922. return src.Remove(start,end-start+1);
  2923. }
  2924. // Inverted substring
  2925. else
  2926. {
  2927. // In this case, out of bounds means that
  2928. // the existing string is part of the cut.
  2929. if (start < 0 || end >= src.Length)
  2930. {
  2931. return String.Empty;
  2932. }
  2933. if (end > 0)
  2934. {
  2935. if (start < src.Length)
  2936. {
  2937. return src.Remove(start).Remove(0,end+1);
  2938. }
  2939. else
  2940. {
  2941. return src.Remove(0,end+1);
  2942. }
  2943. }
  2944. else
  2945. {
  2946. if (start < src.Length)
  2947. {
  2948. return src.Remove(start);
  2949. }
  2950. else
  2951. {
  2952. return src;
  2953. }
  2954. }
  2955. }
  2956. }
  2957. /// <summary>
  2958. /// Insert string inserts the specified string identified by src
  2959. /// at the index indicated by index. Index may be negative, in
  2960. /// which case it is end-relative. The index may exceed either
  2961. /// string bound, with the result being a concatenation.
  2962. /// </summary>
  2963. public LSL_String llInsertString(string dest, int index, string src)
  2964. {
  2965. m_host.AddScriptLPS(1);
  2966. // Normalize indices (if negative).
  2967. // After normalization they may still be
  2968. // negative, but that is now relative to
  2969. // the start, rather than the end, of the
  2970. // sequence.
  2971. if (index < 0)
  2972. {
  2973. index = dest.Length+index;
  2974. // Negative now means it is less than the lower
  2975. // bound of the string.
  2976. if (index < 0)
  2977. {
  2978. return src+dest;
  2979. }
  2980. }
  2981. if (index >= dest.Length)
  2982. {
  2983. return dest+src;
  2984. }
  2985. // The index is in bounds.
  2986. // In this case the index refers to the index that will
  2987. // be assigned to the first character of the inserted string.
  2988. // So unlike the other string operations, we do not add one
  2989. // to get the correct string length.
  2990. return dest.Substring(0,index)+src+dest.Substring(index);
  2991. }
  2992. public LSL_String llToUpper(string src)
  2993. {
  2994. m_host.AddScriptLPS(1);
  2995. return src.ToUpper();
  2996. }
  2997. public LSL_String llToLower(string src)
  2998. {
  2999. m_host.AddScriptLPS(1);
  3000. return src.ToLower();
  3001. }
  3002. public LSL_Integer llGiveMoney(LSL_Key destination, LSL_Integer amount)
  3003. {
  3004. m_host.AddScriptLPS(1);
  3005. if (m_item.PermsGranter == UUID.Zero)
  3006. return 0;
  3007. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  3008. {
  3009. Error("llGiveMoney", "No permissions to give money");
  3010. return 0;
  3011. }
  3012. UUID toID = new UUID();
  3013. if (!UUID.TryParse(destination, out toID))
  3014. {
  3015. Error("llGiveMoney", "Bad key in llGiveMoney");
  3016. return 0;
  3017. }
  3018. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  3019. if (money == null)
  3020. {
  3021. NotImplemented("llGiveMoney");
  3022. return 0;
  3023. }
  3024. Action<string> act = dontcare =>
  3025. {
  3026. money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID,
  3027. toID, amount,UUID.Zero, out string reason);
  3028. };
  3029. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  3030. return 0;
  3031. }
  3032. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3033. {
  3034. m_host.AddScriptLPS(1);
  3035. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  3036. ScriptSleep(m_sleepMsOnMakeExplosion);
  3037. }
  3038. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  3039. {
  3040. m_host.AddScriptLPS(1);
  3041. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  3042. ScriptSleep(m_sleepMsOnMakeFountain);
  3043. }
  3044. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3045. {
  3046. m_host.AddScriptLPS(1);
  3047. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  3048. ScriptSleep(m_sleepMsOnMakeSmoke);
  3049. }
  3050. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3051. {
  3052. m_host.AddScriptLPS(1);
  3053. Deprecated("llMakeFire", "Use llParticleSystem instead");
  3054. ScriptSleep(m_sleepMsOnMakeFire);
  3055. }
  3056. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3057. {
  3058. doObjectRez(inventory, pos, vel, rot, param, true);
  3059. }
  3060. public void doObjectRez(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param, bool atRoot)
  3061. {
  3062. m_host.AddScriptLPS(1);
  3063. if (string.IsNullOrEmpty(inventory) || Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  3064. return;
  3065. float dist = (float)llVecDist(llGetPos(), pos);
  3066. if (dist > m_ScriptDistanceFactor * 10.0f)
  3067. return;
  3068. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3069. if (item == null)
  3070. {
  3071. Error("llRez(AtRoot/Object)", "Can't find object '" + inventory + "'");
  3072. return;
  3073. }
  3074. if (item.InvType != (int)InventoryType.Object)
  3075. {
  3076. Error("llRez(AtRoot/Object)", "Can't create requested object; object is missing from database");
  3077. return;
  3078. }
  3079. Util.FireAndForget(x =>
  3080. {
  3081. Quaternion wrot = rot;
  3082. wrot.Normalize();
  3083. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, wrot, vel, param, atRoot);
  3084. // If either of these are null, then there was an unknown error.
  3085. if (new_groups == null)
  3086. return;
  3087. bool notAttachment = !m_host.ParentGroup.IsAttachment;
  3088. foreach (SceneObjectGroup group in new_groups)
  3089. {
  3090. // objects rezzed with this method are die_at_edge by default.
  3091. group.RootPart.SetDieAtEdge(true);
  3092. group.ResumeScripts();
  3093. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  3094. "object_rez", new Object[] {
  3095. new LSL_String(
  3096. group.RootPart.UUID.ToString()) },
  3097. new DetectParams[0]));
  3098. if (notAttachment)
  3099. {
  3100. float groupmass = group.GetMass();
  3101. PhysicsActor pa = group.RootPart.PhysActor;
  3102. //Recoil.
  3103. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  3104. {
  3105. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  3106. if (recoil != Vector3.Zero)
  3107. {
  3108. llApplyImpulse(recoil, 0);
  3109. }
  3110. }
  3111. }
  3112. }
  3113. }, null, "LSL_Api.doObjectRez");
  3114. //ScriptSleep((int)((groupmass * velmag) / 10));
  3115. ScriptSleep(m_sleepMsOnRezAtRoot);
  3116. }
  3117. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3118. {
  3119. doObjectRez(inventory, pos, vel, rot, param, false);
  3120. }
  3121. public void llLookAt(LSL_Vector target, double strength, double damping)
  3122. {
  3123. m_host.AddScriptLPS(1);
  3124. // Get the normalized vector to the target
  3125. LSL_Vector from = llGetPos();
  3126. // normalized direction to target
  3127. LSL_Vector dir = llVecNorm(target - from);
  3128. // use vertical to help compute left axis
  3129. // LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
  3130. // find normalized left axis parallel to horizon
  3131. // LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
  3132. LSL_Vector left = new LSL_Vector(-dir.y, dir.x, 0.0f);
  3133. left = llVecNorm(left);
  3134. // make up orthogonal to left and dir
  3135. LSL_Vector up = LSL_Vector.Cross(dir, left);
  3136. // compute rotation based on orthogonal axes
  3137. // and rotate so Z points to target with X below horizont
  3138. LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);
  3139. SceneObjectGroup sog = m_host.ParentGroup;
  3140. if(sog == null || sog.IsDeleted)
  3141. return;
  3142. if (!sog.UsesPhysics || sog.IsAttachment)
  3143. {
  3144. // Do nothing if either value is 0 (this has been checked in SL)
  3145. if (strength <= 0.0 || damping <= 0.0)
  3146. return;
  3147. llSetLocalRot(rot);
  3148. }
  3149. else
  3150. {
  3151. if (strength == 0)
  3152. {
  3153. llSetLocalRot(rot);
  3154. return;
  3155. }
  3156. sog.StartLookAt(rot, (float)strength, (float)damping);
  3157. }
  3158. }
  3159. public void llStopLookAt()
  3160. {
  3161. m_host.AddScriptLPS(1);
  3162. m_host.StopLookAt();
  3163. }
  3164. public void llSetTimerEvent(double sec)
  3165. {
  3166. if (sec != 0.0 && sec < m_MinTimerInterval)
  3167. sec = m_MinTimerInterval;
  3168. m_host.AddScriptLPS(1);
  3169. // Setting timer repeat
  3170. m_AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  3171. }
  3172. public virtual void llSleep(double sec)
  3173. {
  3174. // m_log.Info("llSleep snoozing " + sec + "s.");
  3175. m_host.AddScriptLPS(1);
  3176. Sleep((int)(sec * 1000));
  3177. }
  3178. public LSL_Float llGetMass()
  3179. {
  3180. m_host.AddScriptLPS(1);
  3181. if (m_host.ParentGroup.IsAttachment)
  3182. {
  3183. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  3184. if (attachedAvatar != null)
  3185. {
  3186. return attachedAvatar.GetMass();
  3187. }
  3188. else
  3189. {
  3190. return 0;
  3191. }
  3192. }
  3193. else
  3194. {
  3195. // new SL always returns object mass
  3196. // if (m_host.IsRoot)
  3197. // {
  3198. return m_host.ParentGroup.GetMass();
  3199. // }
  3200. // else
  3201. // {
  3202. // return m_host.GetMass();
  3203. // }
  3204. }
  3205. }
  3206. public LSL_Float llGetMassMKS()
  3207. {
  3208. return 100f * llGetMass();
  3209. }
  3210. public void llCollisionFilter(LSL_String name, LSL_Key id, LSL_Integer accept)
  3211. {
  3212. m_host.AddScriptLPS(1);
  3213. m_host.CollisionFilter.Clear();
  3214. if (!UUID.TryParse(id, out UUID objectID))
  3215. return;
  3216. if (objectID == UUID.Zero && name == "")
  3217. return;
  3218. m_host.CollisionFilter.Add(accept, objectID.ToString() + name);
  3219. }
  3220. public void llTakeControls(int controls, int accept, int pass_on)
  3221. {
  3222. if (m_item.PermsGranter != UUID.Zero)
  3223. {
  3224. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3225. if (presence != null)
  3226. {
  3227. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3228. {
  3229. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  3230. }
  3231. }
  3232. }
  3233. m_host.AddScriptLPS(1);
  3234. }
  3235. public void llReleaseControls()
  3236. {
  3237. m_host.AddScriptLPS(1);
  3238. if (m_item.PermsGranter != UUID.Zero)
  3239. {
  3240. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3241. if (presence != null)
  3242. {
  3243. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3244. {
  3245. // Unregister controls from Presence
  3246. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  3247. // Remove Take Control permission.
  3248. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3249. }
  3250. }
  3251. }
  3252. }
  3253. public void llReleaseURL(string url)
  3254. {
  3255. m_host.AddScriptLPS(1);
  3256. if (m_UrlModule != null)
  3257. m_UrlModule.ReleaseURL(url);
  3258. }
  3259. /// <summary>
  3260. /// Attach the object containing this script to the avatar that owns it.
  3261. /// </summary>
  3262. /// <param name='attachmentPoint'>
  3263. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  3264. /// </param>
  3265. /// <returns>true if the attach suceeded, false if it did not</returns>
  3266. public bool AttachToAvatar(int attachmentPoint)
  3267. {
  3268. SceneObjectGroup grp = m_host.ParentGroup;
  3269. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  3270. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3271. if (attachmentsModule != null)
  3272. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  3273. else
  3274. return false;
  3275. }
  3276. /// <summary>
  3277. /// Detach the object containing this script from the avatar it is attached to.
  3278. /// </summary>
  3279. /// <remarks>
  3280. /// Nothing happens if the object is not attached.
  3281. /// </remarks>
  3282. public void DetachFromAvatar()
  3283. {
  3284. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  3285. }
  3286. private void DetachWrapper(object o)
  3287. {
  3288. if (World.AttachmentsModule != null)
  3289. {
  3290. SceneObjectPart host = (SceneObjectPart)o;
  3291. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  3292. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  3293. }
  3294. }
  3295. public void llAttachToAvatar(LSL_Integer attachmentPoint)
  3296. {
  3297. m_host.AddScriptLPS(1);
  3298. if (m_item.PermsGranter != m_host.OwnerID)
  3299. return;
  3300. SceneObjectGroup grp = m_host.ParentGroup;
  3301. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3302. return;
  3303. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3304. AttachToAvatar(attachmentPoint);
  3305. }
  3306. public void llAttachToAvatarTemp(LSL_Integer attachmentPoint)
  3307. {
  3308. IAttachmentsModule attachmentsModule = World.RequestModuleInterface<IAttachmentsModule>();
  3309. if (attachmentsModule == null)
  3310. return;
  3311. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) == 0)
  3312. return;
  3313. SceneObjectGroup grp = m_host.ParentGroup;
  3314. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3315. return;
  3316. if (!World.TryGetScenePresence(m_item.PermsGranter, out ScenePresence target))
  3317. return;
  3318. if (target.UUID != grp.OwnerID)
  3319. {
  3320. uint effectivePerms = grp.EffectiveOwnerPerms;
  3321. if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
  3322. return;
  3323. grp.SetOwner(target.UUID, target.ControllingClient.ActiveGroupId);
  3324. if (World.Permissions.PropagatePermissions())
  3325. {
  3326. foreach (SceneObjectPart child in grp.Parts)
  3327. {
  3328. child.Inventory.ChangeInventoryOwner(target.UUID);
  3329. child.TriggerScriptChangedEvent(Changed.OWNER);
  3330. child.ApplyNextOwnerPermissions();
  3331. }
  3332. grp.InvalidateEffectivePerms();
  3333. }
  3334. grp.RootPart.ObjectSaleType = 0;
  3335. grp.RootPart.SalePrice = 10;
  3336. grp.HasGroupChanged = true;
  3337. grp.RootPart.SendPropertiesToClient(target.ControllingClient);
  3338. grp.RootPart.ScheduleFullUpdate();
  3339. }
  3340. attachmentsModule.AttachObject(target, grp, (uint)attachmentPoint, false, false, true);
  3341. }
  3342. public void llDetachFromAvatar()
  3343. {
  3344. m_host.AddScriptLPS(1);
  3345. if (m_host.ParentGroup.AttachmentPoint == 0)
  3346. return;
  3347. if (m_item.PermsGranter != m_host.OwnerID)
  3348. return;
  3349. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3350. DetachFromAvatar();
  3351. }
  3352. public void llTakeCamera(string avatar)
  3353. {
  3354. m_host.AddScriptLPS(1);
  3355. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  3356. }
  3357. public void llReleaseCamera(string avatar)
  3358. {
  3359. m_host.AddScriptLPS(1);
  3360. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  3361. }
  3362. public LSL_Key llGetOwner()
  3363. {
  3364. m_host.AddScriptLPS(1);
  3365. return m_host.OwnerID.ToString();
  3366. }
  3367. public void llInstantMessage(string user, string message)
  3368. {
  3369. m_host.AddScriptLPS(1);
  3370. if (!UUID.TryParse(user, out UUID result) || result == UUID.Zero)
  3371. {
  3372. Error("llInstantMessage","An invalid key was passed to llInstantMessage");
  3373. ScriptSleep(2000);
  3374. return;
  3375. }
  3376. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  3377. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  3378. // but I don't think we have a list of scenes available from here.
  3379. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  3380. // user is a UUID
  3381. // TODO: figure out values for client, fromSession, and imSessionID
  3382. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  3383. UUID friendTransactionID = UUID.Random();
  3384. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  3385. GridInstantMessage msg = new GridInstantMessage
  3386. {
  3387. fromAgentID = new Guid(m_host.OwnerID.ToString()), // fromAgentID.Guid;
  3388. toAgentID = new Guid(user), // toAgentID.Guid;
  3389. imSessionID = new Guid(m_host.UUID.ToString()), // This is the item we're mucking with here
  3390. timestamp = (uint)Util.UnixTimeSinceEpoch(),
  3391. fromAgentName = m_host.Name//client.FirstName + " " + client.LastName;// fromAgentName;
  3392. };
  3393. if (message != null && message.Length > 1024)
  3394. msg.message = message.Substring(0, 1024);
  3395. else
  3396. msg.message = message;
  3397. msg.dialog = (byte)19; // MessageFromObject
  3398. msg.fromGroup = false;// fromGroup;
  3399. msg.offline = (byte)0; //offline;
  3400. msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
  3401. msg.Position = new Vector3(m_host.AbsolutePosition);
  3402. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  3403. Vector3 pos = m_host.AbsolutePosition;
  3404. msg.binaryBucket
  3405. = Util.StringToBytes256(
  3406. "{0}/{1}/{2}/{3}",
  3407. World.RegionInfo.RegionName,
  3408. (int)Math.Floor(pos.X),
  3409. (int)Math.Floor(pos.Y),
  3410. (int)Math.Floor(pos.Z));
  3411. if (m_TransferModule != null)
  3412. {
  3413. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3414. }
  3415. ScriptSleep(m_sleepMsOnInstantMessage);
  3416. }
  3417. public void llEmail(string address, string subject, string message)
  3418. {
  3419. m_host.AddScriptLPS(1);
  3420. if (m_emailModule == null)
  3421. {
  3422. Error("llEmail", "Email module not configured");
  3423. return;
  3424. }
  3425. // this is a fire and forget no event is sent to script
  3426. Action<string> act = eventID =>
  3427. {
  3428. //Restrict email destination to the avatars registered email address?
  3429. //The restriction only applies if the destination address is not local.
  3430. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  3431. {
  3432. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, m_host.OwnerID);
  3433. if (account == null)
  3434. return;
  3435. if (String.IsNullOrEmpty(account.Email))
  3436. return;
  3437. address = account.Email;
  3438. }
  3439. m_emailModule.SendEmail(m_host.UUID, address, subject, message);
  3440. // no dataserver event
  3441. };
  3442. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  3443. m_item.ItemID, act);
  3444. ScriptSleep(m_sleepMsOnEmail);
  3445. }
  3446. public void llGetNextEmail(string address, string subject)
  3447. {
  3448. m_host.AddScriptLPS(1);
  3449. if (m_emailModule == null)
  3450. {
  3451. Error("llGetNextEmail", "Email module not configured");
  3452. return;
  3453. }
  3454. Email email;
  3455. email = m_emailModule.GetNextEmail(m_host.UUID, address, subject);
  3456. if (email == null)
  3457. return;
  3458. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  3459. new EventParams("email",
  3460. new Object[] {
  3461. new LSL_String(email.time),
  3462. new LSL_String(email.sender),
  3463. new LSL_String(email.subject),
  3464. new LSL_String(email.message),
  3465. new LSL_Integer(email.numLeft)},
  3466. new DetectParams[0]));
  3467. }
  3468. public void llTargetedEmail(LSL_Integer target, LSL_String subject, LSL_String message)
  3469. {
  3470. m_host.AddScriptLPS(1);
  3471. SceneObjectGroup parent = m_host.ParentGroup;
  3472. if (parent == null || parent.IsDeleted)
  3473. return;
  3474. if (m_emailModule == null)
  3475. {
  3476. Error("llTargetedEmail", "Email module not configured");
  3477. return;
  3478. }
  3479. if (subject.Length + message.Length > 4096)
  3480. {
  3481. Error("llTargetedEmail", "Message is too large");
  3482. return;
  3483. }
  3484. // this is a fire and forget no event is sent to script
  3485. Action<string> act = eventID =>
  3486. {
  3487. UserAccount account = null;
  3488. if (target == ScriptBaseClass.TARGETED_EMAIL_OBJECT_OWNER)
  3489. {
  3490. if(parent.OwnerID == parent.GroupID)
  3491. return;
  3492. account = m_userAccountService.GetUserAccount(RegionScopeID, parent.OwnerID);
  3493. }
  3494. else if (target == ScriptBaseClass.TARGETED_EMAIL_ROOT_CREATOR)
  3495. {
  3496. // non standard avoid creator spam
  3497. if(m_item.CreatorID == parent.RootPart.CreatorID)
  3498. {
  3499. account = m_userAccountService.GetUserAccount(RegionScopeID, parent.RootPart.CreatorID);
  3500. }
  3501. else
  3502. return;
  3503. }
  3504. else
  3505. return;
  3506. if (account == null)
  3507. {
  3508. return;
  3509. }
  3510. string address = account.Email;
  3511. if (String.IsNullOrEmpty(address))
  3512. {
  3513. return;
  3514. }
  3515. m_emailModule.SendEmail(m_host.UUID, address, subject, message);
  3516. };
  3517. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  3518. m_item.ItemID, act);
  3519. ScriptSleep(m_sleepMsOnEmail);
  3520. }
  3521. public LSL_Key llGetKey()
  3522. {
  3523. m_host.AddScriptLPS(1);
  3524. return m_host.UUID.ToString();
  3525. }
  3526. public LSL_Key llGenerateKey()
  3527. {
  3528. m_host.AddScriptLPS(1);
  3529. return UUID.Random().ToString();
  3530. }
  3531. public void llSetBuoyancy(double buoyancy)
  3532. {
  3533. m_host.AddScriptLPS(1);
  3534. if (!m_host.ParentGroup.IsDeleted)
  3535. {
  3536. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  3537. }
  3538. }
  3539. /// <summary>
  3540. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  3541. /// </summary>
  3542. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  3543. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  3544. /// <param name="tau">Number of seconds over which to reach target</param>
  3545. public void llSetHoverHeight(double height, int water, double tau)
  3546. {
  3547. m_host.AddScriptLPS(1);
  3548. PIDHoverType hoverType = PIDHoverType.Ground;
  3549. if (water != 0)
  3550. {
  3551. hoverType = PIDHoverType.GroundAndWater;
  3552. }
  3553. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  3554. }
  3555. public void llStopHover()
  3556. {
  3557. m_host.AddScriptLPS(1);
  3558. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3559. }
  3560. public void llMinEventDelay(double delay)
  3561. {
  3562. m_host.AddScriptLPS(1);
  3563. try
  3564. {
  3565. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3566. }
  3567. catch (NotImplementedException)
  3568. {
  3569. // Currently not implemented in DotNetEngine only XEngine
  3570. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3571. }
  3572. }
  3573. public void llSoundPreload(string sound)
  3574. {
  3575. m_host.AddScriptLPS(1);
  3576. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3577. }
  3578. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3579. {
  3580. m_host.AddScriptLPS(1);
  3581. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3582. // set the rotation of the object, copy that behavior
  3583. SceneObjectGroup sog = m_host.ParentGroup;
  3584. if(sog == null || sog.IsDeleted)
  3585. return;
  3586. if (strength == 0 || !sog.UsesPhysics || sog.IsAttachment)
  3587. {
  3588. llSetLocalRot(target);
  3589. }
  3590. else
  3591. {
  3592. sog.RotLookAt(target, (float)strength, (float)damping);
  3593. }
  3594. }
  3595. public LSL_Integer llStringLength(string str)
  3596. {
  3597. m_host.AddScriptLPS(1);
  3598. if(str == null || str.Length <= 0)
  3599. return 0;
  3600. return str.Length;
  3601. }
  3602. public void llStartAnimation(string anim)
  3603. {
  3604. m_host.AddScriptLPS(1);
  3605. if (m_item.PermsGranter == UUID.Zero)
  3606. return;
  3607. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3608. {
  3609. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3610. if (presence != null)
  3611. {
  3612. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3613. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3614. if (animID == UUID.Zero)
  3615. presence.Animator.AddAnimation(anim, m_host.UUID);
  3616. else
  3617. presence.Animator.AddAnimation(animID, m_host.UUID);
  3618. }
  3619. }
  3620. }
  3621. public void llStopAnimation(string anim)
  3622. {
  3623. m_host.AddScriptLPS(1);
  3624. if (m_item.PermsGranter == UUID.Zero)
  3625. return;
  3626. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3627. {
  3628. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3629. if (presence != null)
  3630. {
  3631. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3632. if (animID == UUID.Zero)
  3633. presence.Animator.RemoveAnimation(anim);
  3634. else
  3635. presence.Animator.RemoveAnimation(animID, true);
  3636. }
  3637. }
  3638. }
  3639. public void llStartObjectAnimation(string anim)
  3640. {
  3641. m_host.AddScriptLPS(1);
  3642. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3643. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3644. if (animID == UUID.Zero)
  3645. animID = DefaultAvatarAnimations.GetDefaultAnimation(anim);
  3646. if (animID != UUID.Zero)
  3647. m_host.AddAnimation(animID, anim);
  3648. }
  3649. public void llStopObjectAnimation(string anim)
  3650. {
  3651. m_host.AddScriptLPS(1);
  3652. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim, AssetType.Animation);
  3653. if (animID == UUID.Zero)
  3654. animID = DefaultAvatarAnimations.GetDefaultAnimation(anim);
  3655. if (animID != UUID.Zero)
  3656. m_host.RemoveAnimation(animID);
  3657. }
  3658. public LSL_List llGetObjectAnimationNames()
  3659. {
  3660. m_host.AddScriptLPS(1);
  3661. LSL_List ret = new LSL_List();
  3662. if(m_host.AnimationsNames == null || m_host.AnimationsNames.Count == 0)
  3663. return ret;
  3664. foreach (string name in m_host.AnimationsNames.Values)
  3665. ret.Add(new LSL_String(name));
  3666. return ret;
  3667. }
  3668. public void llPointAt(LSL_Vector pos)
  3669. {
  3670. m_host.AddScriptLPS(1);
  3671. }
  3672. public void llStopPointAt()
  3673. {
  3674. m_host.AddScriptLPS(1);
  3675. }
  3676. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3677. {
  3678. m_host.AddScriptLPS(1);
  3679. TargetOmega(m_host, axis, spinrate, gain);
  3680. }
  3681. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3682. {
  3683. PhysicsActor pa = part.PhysActor;
  3684. if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d )
  3685. spinrate = 0.0d;
  3686. part.UpdateAngularVelocity(axis * spinrate);
  3687. }
  3688. public LSL_Integer llGetStartParameter()
  3689. {
  3690. m_host.AddScriptLPS(1);
  3691. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3692. }
  3693. public void llRequestPermissions(string agent, int perm)
  3694. {
  3695. if (!UUID.TryParse(agent, out UUID agentID))
  3696. return;
  3697. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3698. {
  3699. llReleaseControls();
  3700. m_item.PermsGranter = UUID.Zero;
  3701. m_item.PermsMask = 0;
  3702. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3703. "run_time_permissions", new Object[] {
  3704. new LSL_Integer(0) },
  3705. new DetectParams[0]));
  3706. return;
  3707. }
  3708. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3709. llReleaseControls();
  3710. m_host.AddScriptLPS(1);
  3711. int implicitPerms = 0;
  3712. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3713. {
  3714. // When attached, certain permissions are implicit if requested from owner
  3715. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3716. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3717. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3718. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3719. ScriptBaseClass.PERMISSION_ATTACH |
  3720. ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS;
  3721. }
  3722. else
  3723. {
  3724. if (m_host.ParentGroup.HasSittingAvatar(agentID))
  3725. {
  3726. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3727. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3728. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3729. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3730. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3731. }
  3732. else
  3733. {
  3734. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3735. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3736. }
  3737. if (World.GetExtraSetting("auto_grant_all_perms") == "true")
  3738. {
  3739. implicitPerms = perm;
  3740. }
  3741. }
  3742. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3743. {
  3744. m_host.TaskInventory.LockItemsForWrite(true);
  3745. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3746. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3747. m_host.TaskInventory.LockItemsForWrite(false);
  3748. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3749. "run_time_permissions", new Object[] {
  3750. new LSL_Integer(perm) },
  3751. new DetectParams[0]));
  3752. return;
  3753. }
  3754. ScenePresence presence = World.GetScenePresence(agentID);
  3755. if (presence != null)
  3756. {
  3757. // If permissions are being requested from an NPC and were not implicitly granted above then
  3758. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3759. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3760. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3761. {
  3762. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3763. {
  3764. lock (m_host.TaskInventory)
  3765. {
  3766. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3767. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3768. }
  3769. m_ScriptEngine.PostScriptEvent(
  3770. m_item.ItemID,
  3771. new EventParams(
  3772. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3773. }
  3774. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3775. // the question!
  3776. return;
  3777. }
  3778. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3779. if (ownerName == String.Empty)
  3780. ownerName = "(hippos)";
  3781. if (!m_waitingForScriptAnswer)
  3782. {
  3783. m_host.TaskInventory.LockItemsForWrite(true);
  3784. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3785. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3786. m_host.TaskInventory.LockItemsForWrite(false);
  3787. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3788. m_waitingForScriptAnswer=true;
  3789. }
  3790. presence.ControllingClient.SendScriptQuestion(
  3791. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3792. return;
  3793. }
  3794. // Requested agent is not in range, refuse perms
  3795. m_ScriptEngine.PostScriptEvent(
  3796. m_item.ItemID,
  3797. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3798. }
  3799. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3800. {
  3801. if (taskID != m_host.UUID)
  3802. return;
  3803. client.OnScriptAnswer -= handleScriptAnswer;
  3804. m_waitingForScriptAnswer = false;
  3805. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3806. llReleaseControls();
  3807. m_host.TaskInventory.LockItemsForWrite(true);
  3808. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3809. m_host.TaskInventory.LockItemsForWrite(false);
  3810. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3811. "run_time_permissions", new Object[] {
  3812. new LSL_Integer(answer) },
  3813. new DetectParams[0]));
  3814. }
  3815. public LSL_Key llGetPermissionsKey()
  3816. {
  3817. m_host.AddScriptLPS(1);
  3818. return m_item.PermsGranter.ToString();
  3819. }
  3820. public LSL_Integer llGetPermissions()
  3821. {
  3822. m_host.AddScriptLPS(1);
  3823. int perms = m_item.PermsMask;
  3824. if (m_automaticLinkPermission)
  3825. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3826. return perms;
  3827. }
  3828. public LSL_Integer llGetLinkNumber()
  3829. {
  3830. m_host.AddScriptLPS(1);
  3831. if (m_host.ParentGroup.PrimCount > 1)
  3832. {
  3833. return m_host.LinkNum;
  3834. }
  3835. else
  3836. {
  3837. return 0;
  3838. }
  3839. }
  3840. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3841. {
  3842. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3843. if (parts.Count > 0)
  3844. {
  3845. try
  3846. {
  3847. foreach (SceneObjectPart part in parts)
  3848. part.SetFaceColorAlpha(face, color, null);
  3849. }
  3850. finally { }
  3851. }
  3852. }
  3853. public void llCreateLink(LSL_Key target, LSL_Integer parent)
  3854. {
  3855. m_host.AddScriptLPS(1);
  3856. if (!UUID.TryParse(target, out UUID targetID))
  3857. return;
  3858. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3859. && !m_automaticLinkPermission)
  3860. {
  3861. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3862. return;
  3863. }
  3864. CreateLink(target, parent);
  3865. }
  3866. public void CreateLink(string target, int parent)
  3867. {
  3868. if (!UUID.TryParse(target, out UUID targetID))
  3869. return;
  3870. SceneObjectPart targetPart = World.GetSceneObjectPart(targetID);
  3871. if (targetPart == null)
  3872. return;
  3873. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3874. return; // Fail silently if attached
  3875. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3876. return;
  3877. SceneObjectGroup parentPrim = null, childPrim = null;
  3878. if (parent != 0)
  3879. {
  3880. parentPrim = m_host.ParentGroup;
  3881. childPrim = targetPart.ParentGroup;
  3882. }
  3883. else
  3884. {
  3885. parentPrim = targetPart.ParentGroup;
  3886. childPrim = m_host.ParentGroup;
  3887. }
  3888. // Required for linking
  3889. childPrim.RootPart.ClearUpdateSchedule();
  3890. parentPrim.LinkToGroup(childPrim, true);
  3891. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3892. parentPrim.RootPart.CreateSelected = false;
  3893. parentPrim.HasGroupChanged = true;
  3894. parentPrim.ScheduleGroupForFullUpdate();
  3895. IClientAPI client = null;
  3896. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3897. if (sp != null)
  3898. client = sp.ControllingClient;
  3899. if (client != null)
  3900. parentPrim.SendPropertiesToClient(client);
  3901. ScriptSleep(m_sleepMsOnCreateLink);
  3902. }
  3903. public void llBreakLink(int linknum)
  3904. {
  3905. m_host.AddScriptLPS(1);
  3906. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3907. && !m_automaticLinkPermission)
  3908. {
  3909. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3910. return;
  3911. }
  3912. BreakLink(linknum);
  3913. }
  3914. public void BreakLink(int linknum)
  3915. {
  3916. if (linknum < ScriptBaseClass.LINK_THIS)
  3917. return;
  3918. SceneObjectGroup parentSOG = m_host.ParentGroup;
  3919. if (parentSOG.AttachmentPoint != 0)
  3920. return; // Fail silently if attached
  3921. SceneObjectPart childPrim = null;
  3922. switch (linknum)
  3923. {
  3924. case ScriptBaseClass.LINK_ROOT:
  3925. case ScriptBaseClass.LINK_SET:
  3926. case ScriptBaseClass.LINK_ALL_OTHERS:
  3927. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3928. break;
  3929. case ScriptBaseClass.LINK_THIS: // not as spec
  3930. childPrim = m_host;
  3931. break;
  3932. default:
  3933. childPrim = parentSOG.GetLinkNumPart(linknum);
  3934. break;
  3935. }
  3936. if (linknum == ScriptBaseClass.LINK_ROOT)
  3937. {
  3938. List<ScenePresence> avs = parentSOG.GetSittingAvatars();
  3939. foreach (ScenePresence av in avs)
  3940. av.StandUp();
  3941. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentSOG.Parts);
  3942. parts.Remove(parentSOG.RootPart);
  3943. if (parts.Count > 0)
  3944. {
  3945. try
  3946. {
  3947. foreach (SceneObjectPart part in parts)
  3948. {
  3949. parentSOG.DelinkFromGroup(part.LocalId, true);
  3950. }
  3951. }
  3952. finally { }
  3953. }
  3954. parentSOG.HasGroupChanged = true;
  3955. parentSOG.ScheduleGroupForFullUpdate();
  3956. parentSOG.TriggerScriptChangedEvent(Changed.LINK);
  3957. if (parts.Count > 0)
  3958. {
  3959. SceneObjectPart newRoot = parts[0];
  3960. parts.Remove(newRoot);
  3961. try
  3962. {
  3963. foreach (SceneObjectPart part in parts)
  3964. {
  3965. part.ClearUpdateSchedule();
  3966. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3967. }
  3968. }
  3969. finally { }
  3970. newRoot.ParentGroup.HasGroupChanged = true;
  3971. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3972. }
  3973. }
  3974. else
  3975. {
  3976. if (childPrim == null)
  3977. return;
  3978. List<ScenePresence> avs = parentSOG.GetSittingAvatars();
  3979. foreach (ScenePresence av in avs)
  3980. av.StandUp();
  3981. parentSOG.DelinkFromGroup(childPrim.LocalId, true);
  3982. }
  3983. }
  3984. public void llBreakAllLinks()
  3985. {
  3986. m_host.AddScriptLPS(1);
  3987. TaskInventoryItem item = m_item;
  3988. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3989. && !m_automaticLinkPermission)
  3990. {
  3991. Error("llBreakAllLinks","Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3992. return;
  3993. }
  3994. BreakAllLinks();
  3995. }
  3996. public void BreakAllLinks()
  3997. {
  3998. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3999. if (parentPrim.AttachmentPoint != 0)
  4000. return; // Fail silently if attached
  4001. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  4002. parts.Remove(parentPrim.RootPart);
  4003. foreach (SceneObjectPart part in parts)
  4004. {
  4005. parentPrim.DelinkFromGroup(part.LocalId, true);
  4006. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  4007. }
  4008. parentPrim.HasGroupChanged = true;
  4009. parentPrim.ScheduleGroupForFullUpdate();
  4010. }
  4011. public LSL_Key llGetLinkKey(int linknum)
  4012. {
  4013. m_host.AddScriptLPS(1);
  4014. if(linknum < 0)
  4015. {
  4016. if (linknum == ScriptBaseClass.LINK_THIS)
  4017. return m_host.UUID.ToString();
  4018. return ScriptBaseClass.NULL_KEY;
  4019. }
  4020. if (linknum < 2)
  4021. return m_host.ParentGroup.RootPart.UUID.ToString();
  4022. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  4023. if (part != null)
  4024. {
  4025. return part.UUID.ToString();
  4026. }
  4027. else
  4028. {
  4029. if (linknum > m_host.ParentGroup.PrimCount)
  4030. {
  4031. linknum -= m_host.ParentGroup.PrimCount + 1;
  4032. List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
  4033. if (avatars.Count > linknum)
  4034. {
  4035. return avatars[linknum].UUID.ToString();
  4036. }
  4037. }
  4038. return ScriptBaseClass.NULL_KEY;
  4039. }
  4040. }
  4041. /// <summary>
  4042. /// Returns the name of the child prim or seated avatar matching the
  4043. /// specified link number.
  4044. /// </summary>
  4045. /// <param name="linknum">
  4046. /// The number of a link in the linkset or a link-related constant.
  4047. /// </param>
  4048. /// <returns>
  4049. /// The name determined to match the specified link number.
  4050. /// </returns>
  4051. /// <remarks>
  4052. /// The rules governing the returned name are not simple. The only
  4053. /// time a blank name is returned is if the target prim has a blank
  4054. /// name. If no prim with the given link number can be found then
  4055. /// usually NULL_KEY is returned but there are exceptions.
  4056. ///
  4057. /// In a single unlinked prim, A call with 0 returns the name, all
  4058. /// other values for link number return NULL_KEY
  4059. ///
  4060. /// In link sets it is more complicated.
  4061. ///
  4062. /// If the script is in the root prim:-
  4063. /// A zero link number returns NULL_KEY.
  4064. /// Positive link numbers return the name of the prim, or NULL_KEY
  4065. /// if a prim does not exist at that position.
  4066. /// Negative link numbers return the name of the first child prim.
  4067. ///
  4068. /// If the script is in a child prim:-
  4069. /// Link numbers 0 or 1 return the name of the root prim.
  4070. /// Positive link numbers return the name of the prim or NULL_KEY
  4071. /// if a prim does not exist at that position.
  4072. /// Negative numbers return the name of the root prim.
  4073. ///
  4074. /// References
  4075. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  4076. /// Mentions NULL_KEY being returned
  4077. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  4078. /// Mentions using the LINK_* constants, some of which are negative
  4079. /// </remarks>
  4080. public LSL_String llGetLinkName(int linknum)
  4081. {
  4082. m_host.AddScriptLPS(1);
  4083. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  4084. if (entity != null)
  4085. return entity.Name;
  4086. else
  4087. return ScriptBaseClass.NULL_KEY;
  4088. }
  4089. public LSL_Integer llGetInventoryNumber(int type)
  4090. {
  4091. m_host.AddScriptLPS(1);
  4092. int count = 0;
  4093. m_host.TaskInventory.LockItemsForRead(true);
  4094. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4095. {
  4096. if (inv.Value.Type == type || type == -1)
  4097. {
  4098. count = count + 1;
  4099. }
  4100. }
  4101. m_host.TaskInventory.LockItemsForRead(false);
  4102. return count;
  4103. }
  4104. public LSL_String llGetInventoryName(int type, int number)
  4105. {
  4106. m_host.AddScriptLPS(1);
  4107. ArrayList keys = new ArrayList();
  4108. m_host.TaskInventory.LockItemsForRead(true);
  4109. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4110. {
  4111. if (inv.Value.Type == type || type == -1)
  4112. {
  4113. keys.Add(inv.Value.Name);
  4114. }
  4115. }
  4116. m_host.TaskInventory.LockItemsForRead(false);
  4117. if (keys.Count == 0)
  4118. {
  4119. return String.Empty;
  4120. }
  4121. keys.Sort();
  4122. if (keys.Count > number)
  4123. {
  4124. return (string)keys[number];
  4125. }
  4126. return String.Empty;
  4127. }
  4128. public LSL_Float llGetEnergy()
  4129. {
  4130. m_host.AddScriptLPS(1);
  4131. // TODO: figure out real energy value
  4132. return 1.0f;
  4133. }
  4134. public void llGiveInventory(LSL_Key destination, LSL_String inventory)
  4135. {
  4136. m_host.AddScriptLPS(1);
  4137. UUID destId = UUID.Zero;
  4138. if (!UUID.TryParse(destination, out destId))
  4139. {
  4140. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  4141. return;
  4142. }
  4143. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  4144. if (item == null)
  4145. {
  4146. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  4147. return;
  4148. }
  4149. UUID objId = item.ItemID;
  4150. // check if destination is an object
  4151. if (World.GetSceneObjectPart(destId) != null)
  4152. {
  4153. // destination is an object
  4154. World.MoveTaskInventoryItem(destId, m_host, objId);
  4155. }
  4156. else
  4157. {
  4158. ScenePresence presence = World.GetScenePresence(destId);
  4159. if (presence == null)
  4160. {
  4161. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, destId);
  4162. if (account == null)
  4163. {
  4164. GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
  4165. if(info == null || info.Online == false)
  4166. {
  4167. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  4168. return;
  4169. }
  4170. }
  4171. }
  4172. // destination is an avatar
  4173. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out string message);
  4174. if (agentItem == null)
  4175. {
  4176. llSay(0, message);
  4177. return;
  4178. }
  4179. byte[] bucket = new byte[1];
  4180. bucket[0] = (byte)item.Type;
  4181. GridInstantMessage msg = new GridInstantMessage(World,
  4182. m_host.OwnerID, m_host.Name, destId,
  4183. (byte)InstantMessageDialog.TaskInventoryOffered,
  4184. m_host.OwnerID == m_host.GroupID, "'"+item.Name+"'. ("+m_host.Name+" is located at "+
  4185. World.RegionInfo.RegionName+" "+ m_host.AbsolutePosition.ToString() + ")",
  4186. agentItem.ID, true, m_host.AbsolutePosition,
  4187. bucket, true);
  4188. if (World.TryGetScenePresence(destId, out ScenePresence sp))
  4189. {
  4190. sp.ControllingClient.SendInstantMessage(msg);
  4191. }
  4192. else
  4193. {
  4194. if (m_TransferModule != null)
  4195. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  4196. }
  4197. //This delay should only occur when giving inventory to avatars.
  4198. ScriptSleep(m_sleepMsOnGiveInventory);
  4199. }
  4200. }
  4201. [DebuggerNonUserCode]
  4202. public void llRemoveInventory(string name)
  4203. {
  4204. m_host.AddScriptLPS(1);
  4205. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4206. if (item == null)
  4207. return;
  4208. if (item.ItemID == m_item.ItemID)
  4209. throw new ScriptDeleteException();
  4210. else
  4211. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  4212. }
  4213. public void llSetText(string text, LSL_Vector color, double alpha)
  4214. {
  4215. m_host.AddScriptLPS(1);
  4216. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  4217. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  4218. }
  4219. public LSL_Float llWater(LSL_Vector offset)
  4220. {
  4221. m_host.AddScriptLPS(1);
  4222. return World.RegionInfo.RegionSettings.WaterHeight;
  4223. }
  4224. public void llPassTouches(int pass)
  4225. {
  4226. m_host.AddScriptLPS(1);
  4227. if (pass != 0)
  4228. m_host.PassTouches = true;
  4229. else
  4230. m_host.PassTouches = false;
  4231. }
  4232. public LSL_Key llRequestAgentData(string id, int data)
  4233. {
  4234. m_host.AddScriptLPS(1);
  4235. if (UUID.TryParse(id, out UUID uuid) && uuid != UUID.Zero)
  4236. {
  4237. if (uuid == UUID.Zero)
  4238. return string.Empty;
  4239. //pre process fast local avatars
  4240. switch(data)
  4241. {
  4242. case ScriptBaseClass.DATA_ONLINE:
  4243. World.TryGetScenePresence(uuid, out ScenePresence sp);
  4244. if (sp != null)
  4245. {
  4246. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  4247. m_item.ItemID, "1");
  4248. ScriptSleep(m_sleepMsOnRequestAgentData);
  4249. return ftid;
  4250. }
  4251. break;
  4252. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4253. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4254. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4255. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4256. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4257. break;
  4258. default:
  4259. return string.Empty; // Raise no event
  4260. }
  4261. Action<string> act = eventID =>
  4262. {
  4263. UserAccount account = null;
  4264. string reply;
  4265. if (data == ScriptBaseClass.DATA_ONLINE)
  4266. {
  4267. World.TryGetScenePresence(uuid, out ScenePresence sp);
  4268. if(sp != null)
  4269. reply = "1";
  4270. else
  4271. {
  4272. account = m_userAccountService.GetUserAccount(RegionScopeID, uuid);
  4273. if (account == null)
  4274. reply = "0";
  4275. else
  4276. {
  4277. PresenceInfo pinfo = null;
  4278. if (!m_PresenceInfoCache.TryGetValue(uuid, out pinfo))
  4279. {
  4280. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4281. if (pinfos != null && pinfos.Length > 0)
  4282. {
  4283. foreach (PresenceInfo p in pinfos)
  4284. {
  4285. if (p.RegionID != UUID.Zero)
  4286. {
  4287. pinfo = p;
  4288. }
  4289. }
  4290. }
  4291. m_PresenceInfoCache.AddOrUpdate(uuid, pinfo, m_llRequestAgentDataCacheTimeout);
  4292. }
  4293. reply = pinfo == null ? "0" : "1";
  4294. }
  4295. }
  4296. }
  4297. else
  4298. {
  4299. if (account == null)
  4300. account = m_userAccountService.GetUserAccount(RegionScopeID, uuid);
  4301. if (account == null)
  4302. reply = "0";
  4303. else
  4304. switch (data)
  4305. {
  4306. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4307. reply = account.FirstName + " " + account.LastName;
  4308. break;
  4309. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4310. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  4311. born = born.AddSeconds(account.Created);
  4312. reply = born.ToString("yyyy-MM-dd");
  4313. break;
  4314. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4315. reply = "0,0,0,0,0,0";
  4316. break;
  4317. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4318. reply = account.UserLevel.ToString();
  4319. break;
  4320. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4321. reply = "0";
  4322. break;
  4323. default:
  4324. reply = "0"; // Raise no event
  4325. break;
  4326. }
  4327. }
  4328. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  4329. };
  4330. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  4331. m_item.ItemID, act);
  4332. ScriptSleep(m_sleepMsOnRequestAgentData);
  4333. return tid.ToString();
  4334. }
  4335. else
  4336. {
  4337. Error("llRequestAgentData","Invalid UUID passed to llRequestAgentData.");
  4338. }
  4339. return "";
  4340. }
  4341. //bad if lm is HG
  4342. public LSL_Key llRequestInventoryData(LSL_String name)
  4343. {
  4344. m_host.AddScriptLPS(1);
  4345. Action<string> act = eventID =>
  4346. {
  4347. string reply = String.Empty;
  4348. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  4349. {
  4350. if (item.Type == 3 && item.Name == name)
  4351. {
  4352. AssetBase a = World.AssetService.Get(item.AssetID.ToString());
  4353. if(a != null)
  4354. {
  4355. AssetLandmark lm = new AssetLandmark(a);
  4356. if(lm != null)
  4357. {
  4358. float rx = (uint)(lm.RegionHandle >> 32);
  4359. float ry = (uint)lm.RegionHandle;
  4360. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4361. region = lm.Position + new Vector3(rx, ry, 0) - region;
  4362. reply = region.ToString();
  4363. }
  4364. }
  4365. break;
  4366. }
  4367. }
  4368. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  4369. };
  4370. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  4371. m_item.ItemID, act);
  4372. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4373. return tid.ToString();
  4374. }
  4375. public void llSetDamage(double damage)
  4376. {
  4377. m_host.AddScriptLPS(1);
  4378. m_host.ParentGroup.Damage = (float)damage;
  4379. }
  4380. public void llTeleportAgentHome(string agent)
  4381. {
  4382. m_host.AddScriptLPS(1);
  4383. UUID agentId = new UUID();
  4384. if (UUID.TryParse(agent, out agentId))
  4385. {
  4386. ScenePresence presence = World.GetScenePresence(agentId);
  4387. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4388. {
  4389. // agent must not be a god
  4390. if (presence.GodController.UserLevel >= 200) return;
  4391. // agent must be over the owners land
  4392. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  4393. {
  4394. if (!World.TeleportClientHome(agentId, presence.ControllingClient))
  4395. {
  4396. // They can't be teleported home for some reason
  4397. GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
  4398. if (regionInfo != null)
  4399. {
  4400. World.RequestTeleportLocation(
  4401. presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
  4402. (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
  4403. }
  4404. }
  4405. }
  4406. }
  4407. }
  4408. ScriptSleep(m_sleepMsOnSetDamage);
  4409. }
  4410. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4411. {
  4412. m_host.AddScriptLPS(1);
  4413. UUID agentId = new UUID();
  4414. if (UUID.TryParse(agent, out agentId))
  4415. {
  4416. ScenePresence presence = World.GetScenePresence(agentId);
  4417. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4418. {
  4419. if (destination == String.Empty)
  4420. destination = World.RegionInfo.RegionName;
  4421. if (m_item.PermsGranter == agentId)
  4422. {
  4423. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4424. {
  4425. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4426. }
  4427. }
  4428. // agent must be wearing the object
  4429. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  4430. {
  4431. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4432. }
  4433. else
  4434. {
  4435. // agent must not be a god
  4436. if (presence.IsViewerUIGod) return;
  4437. // agent must be over the owners land
  4438. ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  4439. ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  4440. if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
  4441. {
  4442. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4443. }
  4444. }
  4445. }
  4446. }
  4447. }
  4448. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4449. {
  4450. m_host.AddScriptLPS(1);
  4451. UUID agentId = new UUID();
  4452. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  4453. if (UUID.TryParse(agent, out agentId))
  4454. {
  4455. // This function is owner only!
  4456. if (m_host.OwnerID != agentId)
  4457. return;
  4458. ScenePresence presence = World.GetScenePresence(agentId);
  4459. if (presence == null || presence.PresenceType == PresenceType.Npc)
  4460. return;
  4461. // Can't TP sitting avatars
  4462. if (presence.ParentID != 0) // Sitting
  4463. return;
  4464. if (m_item.PermsGranter == agentId)
  4465. {
  4466. // If attached using llAttachToAvatarTemp, cowardly refuse
  4467. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
  4468. return;
  4469. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4470. {
  4471. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4472. }
  4473. }
  4474. }
  4475. }
  4476. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  4477. {
  4478. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  4479. // The destinaion is not an asset ID and also doesn't name a landmark.
  4480. // Use it as a sim name
  4481. if (assetID == UUID.Zero)
  4482. {
  4483. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4484. return;
  4485. }
  4486. AssetBase lma = World.AssetService.Get(assetID.ToString());
  4487. if (lma == null)
  4488. return;
  4489. if (lma.Type != (sbyte)AssetType.Landmark)
  4490. return;
  4491. AssetLandmark lm = new AssetLandmark(lma);
  4492. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4493. }
  4494. public void llTextBox(string agent, string message, int chatChannel)
  4495. {
  4496. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  4497. if (dm == null)
  4498. return;
  4499. m_host.AddScriptLPS(1);
  4500. UUID av = new UUID();
  4501. if (!UUID.TryParse(agent,out av))
  4502. {
  4503. Error("llTextBox", "First parameter must be a key");
  4504. return;
  4505. }
  4506. if (message == string.Empty)
  4507. {
  4508. Error("llTextBox", "Empty message");
  4509. }
  4510. else if (Encoding.UTF8.GetByteCount(message) > 512)
  4511. {
  4512. Error("llTextBox", "Message longer than 512 bytes");
  4513. }
  4514. else
  4515. {
  4516. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  4517. ScriptSleep(m_sleepMsOnTextBox);
  4518. }
  4519. }
  4520. public void llModifyLand(int action, int brush)
  4521. {
  4522. m_host.AddScriptLPS(1);
  4523. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  4524. if (tm != null)
  4525. {
  4526. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action);
  4527. }
  4528. }
  4529. public void llCollisionSound(LSL_String impact_sound, LSL_Float impact_volume)
  4530. {
  4531. m_host.AddScriptLPS(1);
  4532. if(impact_sound == "")
  4533. {
  4534. m_host.CollisionSoundVolume = (float)impact_volume;
  4535. m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
  4536. m_host.CollisionSoundType = -1; // disable all sounds
  4537. m_host.aggregateScriptEvents();
  4538. return;
  4539. }
  4540. // TODO: Parameter check logic required.
  4541. UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  4542. if(soundId != UUID.Zero)
  4543. {
  4544. m_host.CollisionSound = soundId;
  4545. m_host.CollisionSoundVolume = (float)impact_volume;
  4546. m_host.CollisionSoundType = 1;
  4547. }
  4548. else
  4549. m_host.CollisionSoundType = -1;
  4550. m_host.aggregateScriptEvents();
  4551. }
  4552. public LSL_String llGetAnimation(LSL_Key id)
  4553. {
  4554. // This should only return a value if the avatar is in the same region
  4555. m_host.AddScriptLPS(1);
  4556. if(!UUID.TryParse(id, out UUID avatar))
  4557. return "";
  4558. ScenePresence presence = World.GetScenePresence(avatar);
  4559. if (presence == null)
  4560. return "";
  4561. if (m_host.RegionHandle == presence.RegionHandle)
  4562. {
  4563. if (presence != null)
  4564. {
  4565. // if (presence.SitGround)
  4566. // return "Sitting on Ground";
  4567. // if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
  4568. // return "Sitting";
  4569. string movementAnimation = presence.Animator.CurrentMovementAnimation;
  4570. if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out string lslMovementAnimation))
  4571. return lslMovementAnimation;
  4572. }
  4573. }
  4574. return String.Empty;
  4575. }
  4576. public void llMessageLinked(int linknumber, int num, string msg, string id)
  4577. {
  4578. m_host.AddScriptLPS(1);
  4579. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4580. UUID partItemID;
  4581. foreach (SceneObjectPart part in parts)
  4582. {
  4583. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  4584. {
  4585. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  4586. {
  4587. partItemID = item.ItemID;
  4588. int linkNumber = m_host.LinkNum;
  4589. if (m_host.ParentGroup.PrimCount == 1)
  4590. linkNumber = 0;
  4591. object[] resobj = new object[]
  4592. {
  4593. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  4594. };
  4595. m_ScriptEngine.PostScriptEvent(partItemID,
  4596. new EventParams("link_message",
  4597. resobj, new DetectParams[0]));
  4598. }
  4599. }
  4600. }
  4601. }
  4602. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  4603. {
  4604. m_host.AddScriptLPS(1);
  4605. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  4606. bool pushAllowed = false;
  4607. bool pusheeIsAvatar = false;
  4608. UUID targetID = UUID.Zero;
  4609. if (!UUID.TryParse(target,out targetID))
  4610. return;
  4611. ScenePresence pusheeav = null;
  4612. Vector3 PusheePos = Vector3.Zero;
  4613. SceneObjectPart pusheeob = null;
  4614. ScenePresence avatar = World.GetScenePresence(targetID);
  4615. if (avatar != null)
  4616. {
  4617. pusheeIsAvatar = true;
  4618. // Pushee doesn't have a physics actor
  4619. if (avatar.PhysicsActor == null)
  4620. return;
  4621. // Pushee is in GodMode this pushing object isn't owned by them
  4622. if (avatar.IsViewerUIGod && m_host.OwnerID != targetID)
  4623. return;
  4624. pusheeav = avatar;
  4625. // Find pushee position
  4626. // Pushee Linked?
  4627. SceneObjectPart sitPart = pusheeav.ParentPart;
  4628. if (sitPart != null)
  4629. PusheePos = sitPart.AbsolutePosition;
  4630. else
  4631. PusheePos = pusheeav.AbsolutePosition;
  4632. }
  4633. if (!pusheeIsAvatar)
  4634. {
  4635. // not an avatar so push is not affected by parcel flags
  4636. pusheeob = World.GetSceneObjectPart((UUID)target);
  4637. // We can't find object
  4638. if (pusheeob == null)
  4639. return;
  4640. // Object not pushable. Not an attachment and has no physics component
  4641. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  4642. return;
  4643. PusheePos = pusheeob.AbsolutePosition;
  4644. pushAllowed = true;
  4645. }
  4646. else
  4647. {
  4648. if (pushrestricted)
  4649. {
  4650. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4651. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  4652. if (targetlandObj == null)
  4653. return;
  4654. // Need provisions for Group Owned here
  4655. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4656. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  4657. {
  4658. pushAllowed = true;
  4659. }
  4660. }
  4661. else
  4662. {
  4663. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4664. if (targetlandObj == null)
  4665. {
  4666. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4667. pushAllowed = true;
  4668. }
  4669. else
  4670. {
  4671. // Parcel push restriction
  4672. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4673. {
  4674. // Need provisions for Group Owned here
  4675. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4676. targetlandObj.LandData.IsGroupOwned ||
  4677. m_host.OwnerID == targetID)
  4678. {
  4679. pushAllowed = true;
  4680. }
  4681. //ParcelFlags.RestrictPushObject
  4682. //pushAllowed = true;
  4683. }
  4684. else
  4685. {
  4686. // Parcel isn't push restricted
  4687. pushAllowed = true;
  4688. }
  4689. }
  4690. }
  4691. }
  4692. if (pushAllowed)
  4693. {
  4694. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4695. float distance_term = distance * distance * distance; // Script Energy
  4696. // use total object mass and not part
  4697. float pusher_mass = m_host.ParentGroup.GetMass();
  4698. float PUSH_ATTENUATION_DISTANCE = 17f;
  4699. float PUSH_ATTENUATION_SCALE = 5f;
  4700. float distance_attenuation = 1f;
  4701. if (distance > PUSH_ATTENUATION_DISTANCE)
  4702. {
  4703. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4704. distance_attenuation = 1f / normalized_units;
  4705. }
  4706. Vector3 applied_linear_impulse = impulse;
  4707. {
  4708. float impulse_length = applied_linear_impulse.Length();
  4709. float desired_energy = impulse_length * pusher_mass;
  4710. if (desired_energy > 0f)
  4711. desired_energy += distance_term;
  4712. float scaling_factor = 1f;
  4713. scaling_factor *= distance_attenuation;
  4714. applied_linear_impulse *= scaling_factor;
  4715. }
  4716. if (pusheeIsAvatar)
  4717. {
  4718. if (pusheeav != null)
  4719. {
  4720. PhysicsActor pa = pusheeav.PhysicsActor;
  4721. if (pa != null)
  4722. {
  4723. if (local != 0)
  4724. {
  4725. // applied_linear_impulse *= m_host.GetWorldRotation();
  4726. applied_linear_impulse *= pusheeav.GetWorldRotation();
  4727. }
  4728. pa.AddForce(applied_linear_impulse, true);
  4729. }
  4730. }
  4731. }
  4732. else
  4733. {
  4734. if (pusheeob != null)
  4735. {
  4736. if (pusheeob.PhysActor != null)
  4737. {
  4738. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4739. }
  4740. }
  4741. }
  4742. }
  4743. }
  4744. public void llPassCollisions(int pass)
  4745. {
  4746. m_host.AddScriptLPS(1);
  4747. if (pass == 1)
  4748. {
  4749. m_host.PassCollisions = true;
  4750. }
  4751. else
  4752. {
  4753. m_host.PassCollisions = false;
  4754. }
  4755. }
  4756. public LSL_String llGetScriptName()
  4757. {
  4758. m_host.AddScriptLPS(1);
  4759. return m_item.Name ?? String.Empty;
  4760. }
  4761. public LSL_Integer llGetLinkNumberOfSides(int link)
  4762. {
  4763. m_host.AddScriptLPS(1);
  4764. SceneObjectPart linkedPart;
  4765. if (link == ScriptBaseClass.LINK_ROOT)
  4766. linkedPart = m_host.ParentGroup.RootPart;
  4767. else if (link == ScriptBaseClass.LINK_THIS)
  4768. linkedPart = m_host;
  4769. else
  4770. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4771. return GetNumberOfSides(linkedPart);
  4772. }
  4773. public LSL_Integer llGetNumberOfSides()
  4774. {
  4775. m_host.AddScriptLPS(1);
  4776. return m_host.GetNumberOfSides();
  4777. }
  4778. protected int GetNumberOfSides(SceneObjectPart part)
  4779. {
  4780. return part.GetNumberOfSides();
  4781. }
  4782. /* The new / changed functions were tested with the following LSL script:
  4783. default
  4784. {
  4785. state_entry()
  4786. {
  4787. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4788. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4789. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4790. // convert back and forth between quaternion <-> vector and angle
  4791. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4792. llOwnerSay("Old rotation was: "+(string) rot);
  4793. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4794. llSetRot(rot); // to check the parameters in the prim
  4795. }
  4796. }
  4797. */
  4798. // Xantor 29/apr/2008
  4799. // Returns rotation described by rotating angle radians about axis.
  4800. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4801. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4802. {
  4803. m_host.AddScriptLPS(1);
  4804. double x, y, z, s, t;
  4805. s = Math.Cos(angle * 0.5);
  4806. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4807. axis = LSL_Vector.Norm(axis);
  4808. x = axis.x * t;
  4809. y = axis.y * t;
  4810. z = axis.z * t;
  4811. return new LSL_Rotation(x,y,z,s);
  4812. }
  4813. /// <summary>
  4814. /// Returns the axis of rotation for a quaternion
  4815. /// </summary>
  4816. /// <returns></returns>
  4817. /// <param name='rot'></param>
  4818. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4819. {
  4820. m_host.AddScriptLPS(1);
  4821. rot.Normalize();
  4822. double s = Math.Sqrt(1 - rot.s * rot.s);
  4823. if (s < 1e-8)
  4824. return new LSL_Vector(0, 0, 0);
  4825. double invS = 1.0 / s;
  4826. if (rot.s < 0)
  4827. invS = -invS;
  4828. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4829. }
  4830. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4831. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4832. {
  4833. m_host.AddScriptLPS(1);
  4834. rot.Normalize();
  4835. double angle = 2 * Math.Acos(rot.s);
  4836. if (angle > Math.PI)
  4837. angle = 2 * Math.PI - angle;
  4838. return angle;
  4839. }
  4840. public LSL_Float llAcos(LSL_Float val)
  4841. {
  4842. m_host.AddScriptLPS(1);
  4843. return (double)Math.Acos(val);
  4844. }
  4845. public LSL_Float llAsin(LSL_Float val)
  4846. {
  4847. m_host.AddScriptLPS(1);
  4848. return (double)Math.Asin(val);
  4849. }
  4850. // jcochran 5/jan/2012
  4851. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4852. {
  4853. m_host.AddScriptLPS(1);
  4854. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4855. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4856. double aa_bb = aa * bb;
  4857. if (aa_bb == 0) return 0.0;
  4858. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4859. double quotient = (ab * ab) / aa_bb;
  4860. if (quotient >= 1.0) return 0.0;
  4861. return Math.Acos(2 * quotient - 1);
  4862. }
  4863. public LSL_Key llGetInventoryKey(string name)
  4864. {
  4865. m_host.AddScriptLPS(1);
  4866. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4867. if (item == null)
  4868. return ScriptBaseClass.NULL_KEY;
  4869. if ((item.CurrentPermissions
  4870. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4871. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4872. {
  4873. return item.AssetID.ToString();
  4874. }
  4875. return ScriptBaseClass.NULL_KEY;
  4876. }
  4877. public void llAllowInventoryDrop(LSL_Integer add)
  4878. {
  4879. m_host.AddScriptLPS(1);
  4880. if (add != 0)
  4881. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4882. else
  4883. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4884. // Update the object flags
  4885. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4886. }
  4887. public LSL_Vector llGetTextureOffset(int face)
  4888. {
  4889. m_host.AddScriptLPS(1);
  4890. return GetTextureOffset(m_host, face);
  4891. }
  4892. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4893. {
  4894. Primitive.TextureEntry tex = part.Shape.Textures;
  4895. LSL_Vector offset = new LSL_Vector();
  4896. if (face == ScriptBaseClass.ALL_SIDES)
  4897. {
  4898. face = 0;
  4899. }
  4900. if (face >= 0 && face < GetNumberOfSides(part))
  4901. {
  4902. offset.x = tex.GetFace((uint)face).OffsetU;
  4903. offset.y = tex.GetFace((uint)face).OffsetV;
  4904. offset.z = 0.0;
  4905. return offset;
  4906. }
  4907. else
  4908. {
  4909. return offset;
  4910. }
  4911. }
  4912. public LSL_Vector llGetTextureScale(int side)
  4913. {
  4914. m_host.AddScriptLPS(1);
  4915. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4916. LSL_Vector scale;
  4917. if (side == -1)
  4918. {
  4919. side = 0;
  4920. }
  4921. scale.x = tex.GetFace((uint)side).RepeatU;
  4922. scale.y = tex.GetFace((uint)side).RepeatV;
  4923. scale.z = 0.0;
  4924. return scale;
  4925. }
  4926. public LSL_Float llGetTextureRot(int face)
  4927. {
  4928. m_host.AddScriptLPS(1);
  4929. return GetTextureRot(m_host, face);
  4930. }
  4931. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4932. {
  4933. Primitive.TextureEntry tex = part.Shape.Textures;
  4934. if (face == -1)
  4935. {
  4936. face = 0;
  4937. }
  4938. if (face >= 0 && face < GetNumberOfSides(part))
  4939. {
  4940. return tex.GetFace((uint)face).Rotation;
  4941. }
  4942. else
  4943. {
  4944. return 0.0;
  4945. }
  4946. }
  4947. public LSL_Integer llSubStringIndex(string source, string pattern)
  4948. {
  4949. m_host.AddScriptLPS(1);
  4950. if (string.IsNullOrEmpty(source))
  4951. return -1;
  4952. if (string.IsNullOrEmpty(pattern))
  4953. return 0;
  4954. return source.IndexOf(pattern);
  4955. }
  4956. public LSL_Key llGetOwnerKey(string id)
  4957. {
  4958. m_host.AddScriptLPS(1);
  4959. UUID key = new UUID();
  4960. if (UUID.TryParse(id, out key))
  4961. {
  4962. try
  4963. {
  4964. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4965. if (obj == null)
  4966. return id; // the key is for an agent so just return the key
  4967. else
  4968. return obj.OwnerID.ToString();
  4969. }
  4970. catch (KeyNotFoundException)
  4971. {
  4972. return id; // The Object/Agent not in the region so just return the key
  4973. }
  4974. }
  4975. else
  4976. {
  4977. return ScriptBaseClass.NULL_KEY;
  4978. }
  4979. }
  4980. public LSL_Vector llGetCenterOfMass()
  4981. {
  4982. m_host.AddScriptLPS(1);
  4983. return new LSL_Vector(m_host.GetCenterOfMass());
  4984. }
  4985. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4986. {
  4987. m_host.AddScriptLPS(1);
  4988. if (stride <= 0)
  4989. {
  4990. stride = 1;
  4991. }
  4992. return src.Sort(stride, ascending);
  4993. }
  4994. public LSL_Integer llGetListLength(LSL_List src)
  4995. {
  4996. m_host.AddScriptLPS(1);
  4997. return src.Length;
  4998. }
  4999. public LSL_Integer llList2Integer(LSL_List src, int index)
  5000. {
  5001. m_host.AddScriptLPS(1);
  5002. if (index < 0)
  5003. index = src.Length + index;
  5004. if (index >= src.Length || index < 0)
  5005. return 0;
  5006. object item = src.Data[index];
  5007. // Vectors & Rotations always return zero in SL, but
  5008. // keys don't always return zero, it seems to be a bit complex.
  5009. if (item is LSL_Vector || item is LSL_Rotation)
  5010. return 0;
  5011. try
  5012. {
  5013. if (item is LSL_Integer)
  5014. return (LSL_Integer)item;
  5015. else if (item is LSL_Float)
  5016. return Convert.ToInt32(((LSL_Float)item).value);;
  5017. return new LSL_Integer(item.ToString());
  5018. }
  5019. catch (FormatException)
  5020. {
  5021. return 0;
  5022. }
  5023. }
  5024. public LSL_Float llList2Float(LSL_List src, int index)
  5025. {
  5026. m_host.AddScriptLPS(1);
  5027. if (index < 0)
  5028. index = src.Length + index;
  5029. if (index >= src.Length || index < 0)
  5030. return 0;
  5031. object item = src.Data[index];
  5032. // Vectors & Rotations always return zero in SL
  5033. if(item is LSL_Vector || item is LSL_Rotation)
  5034. return 0;
  5035. // valid keys seem to get parsed as integers then converted to floats
  5036. if (item is LSL_Key)
  5037. {
  5038. string s = item.ToString();
  5039. if(UUID.TryParse(s, out UUID uuidt))
  5040. return Convert.ToDouble(new LSL_Integer(s).value);
  5041. // we can't do this because a string is also a LSL_Key for now :(
  5042. // else
  5043. // return 0;
  5044. }
  5045. try
  5046. {
  5047. if (item is LSL_Integer)
  5048. return Convert.ToDouble(((LSL_Integer)item).value);
  5049. else if (item is LSL_Float)
  5050. return Convert.ToDouble(((LSL_Float)item).value);
  5051. else if (item is LSL_String)
  5052. {
  5053. string str = ((LSL_String)item).m_string;
  5054. Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
  5055. if (m != Match.Empty)
  5056. {
  5057. str = m.Value;
  5058. if (!Double.TryParse(str, out double d))
  5059. return 0.0;
  5060. return d;
  5061. }
  5062. return 0.0;
  5063. }
  5064. return Convert.ToDouble(item);
  5065. }
  5066. catch (FormatException)
  5067. {
  5068. return 0.0;
  5069. }
  5070. }
  5071. public LSL_String llList2String(LSL_List src, int index)
  5072. {
  5073. m_host.AddScriptLPS(1);
  5074. if (index < 0)
  5075. index = src.Length + index;
  5076. if (index >= src.Length || index < 0)
  5077. return String.Empty;
  5078. return src.Data[index].ToString();
  5079. }
  5080. public LSL_Key llList2Key(LSL_List src, int index)
  5081. {
  5082. m_host.AddScriptLPS(1);
  5083. if (index < 0)
  5084. index = src.Length + index;
  5085. if (index >= src.Length || index < 0)
  5086. return String.Empty;
  5087. object item = src.Data[index];
  5088. // SL spits out an empty string for types other than key & string
  5089. // At the time of patching, LSL_Key is currently LSL_String,
  5090. // so the OR check may be a little redundant, but it's being done
  5091. // for completion and should LSL_Key ever be implemented
  5092. // as it's own struct
  5093. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  5094. // type 'obj' and wrongly returns ""
  5095. if (!(item is LSL_String ||
  5096. item is LSL_Key ||
  5097. item.ToString() == "00000000-0000-0000-0000-000000000000"))
  5098. {
  5099. return String.Empty;
  5100. }
  5101. return item.ToString();
  5102. }
  5103. public LSL_Vector llList2Vector(LSL_List src, int index)
  5104. {
  5105. m_host.AddScriptLPS(1);
  5106. if (index < 0)
  5107. index = src.Length + index;
  5108. if (index >= src.Length || index < 0)
  5109. return new LSL_Vector(0, 0, 0);
  5110. object item = src.Data[index];
  5111. if (item.GetType() == typeof(LSL_Vector))
  5112. return (LSL_Vector)item;
  5113. // SL spits always out ZERO_VECTOR for anything other than
  5114. // strings or vectors. Although keys always return ZERO_VECTOR,
  5115. // it is currently difficult to make the distinction between
  5116. // a string, a key as string and a string that by coincidence
  5117. // is a string, so we're going to leave that up to the
  5118. // LSL_Vector constructor.
  5119. if(item is LSL_Vector)
  5120. return (LSL_Vector) item;
  5121. if (item is LSL_String || item is string) // xengine sees string
  5122. return new LSL_Vector(item.ToString());
  5123. return new LSL_Vector(0, 0, 0);
  5124. }
  5125. public LSL_Rotation llList2Rot(LSL_List src, int index)
  5126. {
  5127. m_host.AddScriptLPS(1);
  5128. if (index < 0)
  5129. index = src.Length + index;
  5130. if (index >= src.Length || index < 0)
  5131. return new LSL_Rotation(0, 0, 0, 1);
  5132. object item = src.Data[index];
  5133. // SL spits always out ZERO_ROTATION for anything other than
  5134. // strings or vectors. Although keys always return ZERO_ROTATION,
  5135. // it is currently difficult to make the distinction between
  5136. // a string, a key as string and a string that by coincidence
  5137. // is a string, so we're going to leave that up to the
  5138. // LSL_Rotation constructor.
  5139. if (item.GetType() == typeof(LSL_Rotation))
  5140. return (LSL_Rotation)item;
  5141. if (item is LSL_String || item is string) // xengine sees string)
  5142. return new LSL_Rotation(src.Data[index].ToString());
  5143. return new LSL_Rotation(0, 0, 0, 1);
  5144. }
  5145. public LSL_List llList2List(LSL_List src, int start, int end)
  5146. {
  5147. m_host.AddScriptLPS(1);
  5148. return src.GetSublist(start, end);
  5149. }
  5150. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  5151. {
  5152. return src.DeleteSublist(start, end);
  5153. }
  5154. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  5155. {
  5156. m_host.AddScriptLPS(1);
  5157. if (index < 0)
  5158. {
  5159. index = src.Length + index;
  5160. }
  5161. if (index >= src.Length)
  5162. {
  5163. return 0;
  5164. }
  5165. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  5166. return 1;
  5167. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  5168. return 2;
  5169. if (src.Data[index] is LSL_String || src.Data[index] is String)
  5170. {
  5171. if (UUID.TryParse(src.Data[index].ToString(), out UUID tuuid))
  5172. {
  5173. return 4;
  5174. }
  5175. else
  5176. {
  5177. return 3;
  5178. }
  5179. }
  5180. if (src.Data[index] is LSL_Vector)
  5181. return 5;
  5182. if (src.Data[index] is LSL_Rotation)
  5183. return 6;
  5184. if (src.Data[index] is LSL_List)
  5185. return 7;
  5186. return 0;
  5187. }
  5188. /// <summary>
  5189. /// Process the supplied list and return the
  5190. /// content of the list formatted as a comma
  5191. /// separated list. There is a space after
  5192. /// each comma.
  5193. /// </summary>
  5194. public LSL_String llList2CSV(LSL_List src)
  5195. {
  5196. m_host.AddScriptLPS(1);
  5197. return string.Join(", ",
  5198. (new List<object>(src.Data)).ConvertAll<string>(o =>
  5199. {
  5200. return o.ToString();
  5201. }).ToArray());
  5202. }
  5203. /// <summary>
  5204. /// The supplied string is scanned for commas
  5205. /// and converted into a list. Commas are only
  5206. /// effective if they are encountered outside
  5207. /// of '<' '>' delimiters. Any whitespace
  5208. /// before or after an element is trimmed.
  5209. /// </summary>
  5210. public LSL_List llCSV2List(string src)
  5211. {
  5212. LSL_List result = new LSL_List();
  5213. int parens = 0;
  5214. int start = 0;
  5215. int length = 0;
  5216. m_host.AddScriptLPS(1);
  5217. for (int i = 0; i < src.Length; i++)
  5218. {
  5219. switch (src[i])
  5220. {
  5221. case '<':
  5222. parens++;
  5223. length++;
  5224. break;
  5225. case '>':
  5226. if (parens > 0)
  5227. parens--;
  5228. length++;
  5229. break;
  5230. case ',':
  5231. if (parens == 0)
  5232. {
  5233. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5234. start += length+1;
  5235. length = 0;
  5236. }
  5237. else
  5238. {
  5239. length++;
  5240. }
  5241. break;
  5242. default:
  5243. length++;
  5244. break;
  5245. }
  5246. }
  5247. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5248. return result;
  5249. }
  5250. /// <summary>
  5251. /// Randomizes the list, be arbitrarily reordering
  5252. /// sublists of stride elements. As the stride approaches
  5253. /// the size of the list, the options become very
  5254. /// limited.
  5255. /// </summary>
  5256. /// <remarks>
  5257. /// This could take a while for very large list
  5258. /// sizes.
  5259. /// </remarks>
  5260. public LSL_List llListRandomize(LSL_List src, int stride)
  5261. {
  5262. LSL_List result;
  5263. BetterRandom rand = new BetterRandom();
  5264. int chunkk;
  5265. int[] chunks;
  5266. m_host.AddScriptLPS(1);
  5267. if (stride <= 0)
  5268. {
  5269. stride = 1;
  5270. }
  5271. // Stride MUST be a factor of the list length
  5272. // If not, then return the src list. This also
  5273. // traps those cases where stride > length.
  5274. if (src.Length != stride && src.Length % stride == 0)
  5275. {
  5276. chunkk = src.Length/stride;
  5277. chunks = new int[chunkk];
  5278. for (int i = 0; i < chunkk; i++)
  5279. {
  5280. chunks[i] = i;
  5281. }
  5282. // Knuth shuffle the chunkk index
  5283. for (int i = chunkk - 1; i > 0; i--)
  5284. {
  5285. // Elect an unrandomized chunk to swap
  5286. int index = rand.Next(i + 1);
  5287. // and swap position with first unrandomized chunk
  5288. int tmp = chunks[i];
  5289. chunks[i] = chunks[index];
  5290. chunks[index] = tmp;
  5291. }
  5292. // Construct the randomized list
  5293. result = new LSL_List();
  5294. for (int i = 0; i < chunkk; i++)
  5295. {
  5296. for (int j = 0; j < stride; j++)
  5297. {
  5298. result.Add(src.Data[chunks[i] * stride + j]);
  5299. }
  5300. }
  5301. }
  5302. else
  5303. {
  5304. object[] array = new object[src.Length];
  5305. Array.Copy(src.Data, 0, array, 0, src.Length);
  5306. result = new LSL_List(array);
  5307. }
  5308. return result;
  5309. }
  5310. /// <summary>
  5311. /// Elements in the source list starting with 0 and then
  5312. /// every i+stride. If the stride is negative then the scan
  5313. /// is backwards producing an inverted result.
  5314. /// Only those elements that are also in the specified
  5315. /// range are included in the result.
  5316. /// </summary>
  5317. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  5318. {
  5319. LSL_List result = new LSL_List();
  5320. int[] si = new int[2];
  5321. int[] ei = new int[2];
  5322. bool twopass = false;
  5323. m_host.AddScriptLPS(1);
  5324. // First step is always to deal with negative indices
  5325. if (start < 0)
  5326. start = src.Length+start;
  5327. if (end < 0)
  5328. end = src.Length+end;
  5329. // Out of bounds indices are OK, just trim them
  5330. // accordingly
  5331. if (start > src.Length)
  5332. start = src.Length;
  5333. if (end > src.Length)
  5334. end = src.Length;
  5335. if (stride == 0)
  5336. stride = 1;
  5337. // There may be one or two ranges to be considered
  5338. if (start != end)
  5339. {
  5340. if (start <= end)
  5341. {
  5342. si[0] = start;
  5343. ei[0] = end;
  5344. }
  5345. else
  5346. {
  5347. si[1] = start;
  5348. ei[1] = src.Length;
  5349. si[0] = 0;
  5350. ei[0] = end;
  5351. twopass = true;
  5352. }
  5353. // The scan always starts from the beginning of the
  5354. // source list, but members are only selected if they
  5355. // fall within the specified sub-range. The specified
  5356. // range values are inclusive.
  5357. // A negative stride reverses the direction of the
  5358. // scan producing an inverted list as a result.
  5359. if (stride > 0)
  5360. {
  5361. for (int i = 0; i < src.Length; i += stride)
  5362. {
  5363. if (i<=ei[0] && i>=si[0])
  5364. result.Add(src.Data[i]);
  5365. if (twopass && i>=si[1] && i<=ei[1])
  5366. result.Add(src.Data[i]);
  5367. }
  5368. }
  5369. else if (stride < 0)
  5370. {
  5371. for (int i = src.Length - 1; i >= 0; i += stride)
  5372. {
  5373. if (i <= ei[0] && i >= si[0])
  5374. result.Add(src.Data[i]);
  5375. if (twopass && i >= si[1] && i <= ei[1])
  5376. result.Add(src.Data[i]);
  5377. }
  5378. }
  5379. }
  5380. else
  5381. {
  5382. if (start%stride == 0)
  5383. {
  5384. result.Add(src.Data[start]);
  5385. }
  5386. }
  5387. return result;
  5388. }
  5389. public LSL_Integer llGetRegionAgentCount()
  5390. {
  5391. m_host.AddScriptLPS(1);
  5392. int count = 0;
  5393. World.ForEachRootScenePresence(delegate(ScenePresence sp) {
  5394. count++;
  5395. });
  5396. return new LSL_Integer(count);
  5397. }
  5398. public LSL_Vector llGetRegionCorner()
  5399. {
  5400. m_host.AddScriptLPS(1);
  5401. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  5402. }
  5403. public LSL_String llGetEnv(LSL_String name)
  5404. {
  5405. m_host.AddScriptLPS(1);
  5406. string sname = name;
  5407. sname = sname.ToLower();
  5408. switch(sname)
  5409. {
  5410. case "agent_limit":
  5411. return World.RegionInfo.RegionSettings.AgentLimit.ToString();
  5412. case "dynamic_pathfinding":
  5413. return "0";
  5414. case "estate_id":
  5415. return World.RegionInfo.EstateSettings.EstateID.ToString();
  5416. case "estate_name":
  5417. return World.RegionInfo.EstateSettings.EstateName;
  5418. case "frame_number":
  5419. return World.Frame.ToString();
  5420. case "region_cpu_ratio":
  5421. return "1";
  5422. case "region_idle":
  5423. return "0";
  5424. case "region_product_name":
  5425. if (World.RegionInfo.RegionType != String.Empty)
  5426. return World.RegionInfo.RegionType;
  5427. else
  5428. return "";
  5429. case "region_product_sku":
  5430. return "OpenSim";
  5431. case "region_start_time":
  5432. return World.UnixStartTime.ToString();
  5433. case "region_up_time":
  5434. int time = Util.UnixTimeSinceEpoch() - World.UnixStartTime;
  5435. return time.ToString();
  5436. case "sim_channel":
  5437. return "OpenSim";
  5438. case "sim_version":
  5439. return World.GetSimulatorVersion();
  5440. case "simulator_hostname":
  5441. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  5442. return UrlModule.ExternalHostNameForLSL;
  5443. case "region_max_prims":
  5444. return World.RegionInfo.ObjectCapacity.ToString();
  5445. case "region_object_bonus":
  5446. return World.RegionInfo.RegionSettings.ObjectBonus.ToString();
  5447. case "whisper_range":
  5448. return m_whisperdistance.ToString();
  5449. case "chat_range":
  5450. return m_saydistance.ToString();
  5451. case "shout_range":
  5452. return m_shoutdistance.ToString();
  5453. default:
  5454. return "";
  5455. }
  5456. }
  5457. /// <summary>
  5458. /// Insert the list identified by <paramref name="src"/> into the
  5459. /// list designated by <paramref name="dest"/> such that the first
  5460. /// new element has the index specified by <paramref name="index"/>
  5461. /// </summary>
  5462. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  5463. {
  5464. LSL_List pref;
  5465. LSL_List suff;
  5466. m_host.AddScriptLPS(1);
  5467. if (index < 0)
  5468. {
  5469. index = index+dest.Length;
  5470. if (index < 0)
  5471. {
  5472. index = 0;
  5473. }
  5474. }
  5475. if (index != 0)
  5476. {
  5477. pref = dest.GetSublist(0,index-1);
  5478. if (index < dest.Length)
  5479. {
  5480. suff = dest.GetSublist(index,-1);
  5481. return pref + src + suff;
  5482. }
  5483. else
  5484. {
  5485. return pref + src;
  5486. }
  5487. }
  5488. else
  5489. {
  5490. if (index < dest.Length)
  5491. {
  5492. suff = dest.GetSublist(index,-1);
  5493. return src + suff;
  5494. }
  5495. else
  5496. {
  5497. return src;
  5498. }
  5499. }
  5500. }
  5501. /// <summary>
  5502. /// Returns the index of the first occurrence of test
  5503. /// in src.
  5504. /// </summary>
  5505. /// <param name="src">Source list</param>
  5506. /// <param name="test">List to search for</param>
  5507. /// <returns>
  5508. /// The index number of the point in src where test was found if it was found.
  5509. /// Otherwise returns -1
  5510. /// </returns>
  5511. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  5512. {
  5513. int index = -1;
  5514. int length = src.Length - test.Length + 1;
  5515. m_host.AddScriptLPS(1);
  5516. // If either list is empty, do not match
  5517. if (src.Length != 0 && test.Length != 0)
  5518. {
  5519. for (int i = 0; i < length; i++)
  5520. {
  5521. int needle = llGetListEntryType(test, 0).value;
  5522. int haystack = llGetListEntryType(src, i).value;
  5523. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  5524. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  5525. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  5526. // Therefore, here we test Equals on both the source and destination objects.
  5527. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  5528. if ((needle == haystack) && (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])))
  5529. {
  5530. int j;
  5531. for (j = 1; j < test.Length; j++)
  5532. {
  5533. needle = llGetListEntryType(test, j).value;
  5534. haystack = llGetListEntryType(src, i+j).value;
  5535. if ((needle != haystack) || (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))))
  5536. break;
  5537. }
  5538. if (j == test.Length)
  5539. {
  5540. index = i;
  5541. break;
  5542. }
  5543. }
  5544. }
  5545. }
  5546. return index;
  5547. }
  5548. public LSL_String llGetObjectName()
  5549. {
  5550. m_host.AddScriptLPS(1);
  5551. return m_host.Name ?? string.Empty;
  5552. }
  5553. public void llSetObjectName(string name)
  5554. {
  5555. m_host.AddScriptLPS(1);
  5556. m_host.Name = name ?? String.Empty;
  5557. }
  5558. public LSL_String llGetDate()
  5559. {
  5560. m_host.AddScriptLPS(1);
  5561. DateTime date = DateTime.Now.ToUniversalTime();
  5562. string result = date.ToString("yyyy-MM-dd");
  5563. return result;
  5564. }
  5565. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  5566. {
  5567. m_host.AddScriptLPS(1);
  5568. if(dir.x == 0 && dir.y == 0)
  5569. return 1; // SL wiki
  5570. float rsx = World.RegionInfo.RegionSizeX;
  5571. float rsy = World.RegionInfo.RegionSizeY;
  5572. // can understand what sl does if position is not in region, so do something :)
  5573. float px = (float)Util.Clamp(pos.x, 0.5, rsx - 0.5);
  5574. float py = (float)Util.Clamp(pos.y, 0.5, rsy - 0.5);
  5575. float ex, ey;
  5576. if (dir.x == 0)
  5577. {
  5578. ex = px;
  5579. ey = dir.y > 0 ? rsy + 1.0f : -1.0f;
  5580. }
  5581. else if(dir.y == 0)
  5582. {
  5583. ex = dir.x > 0 ? rsx + 1.0f : -1.0f;
  5584. ey = py;
  5585. }
  5586. else
  5587. {
  5588. float dx = (float) dir.x;
  5589. float dy = (float) dir.y;
  5590. float t1 = dx * dx + dy * dy;
  5591. t1 = (float)Math.Sqrt(t1);
  5592. dx /= t1;
  5593. dy /= t1;
  5594. if(dx > 0)
  5595. t1 = (rsx + 1f - px)/dx;
  5596. else
  5597. t1 = -(px + 1f)/dx;
  5598. float t2;
  5599. if(dy > 0)
  5600. t2 = (rsy + 1f - py)/dy;
  5601. else
  5602. t2 = -(py + 1f)/dy;
  5603. if(t1 > t2)
  5604. t1 = t2;
  5605. ex = px + t1 * dx;
  5606. ey = py + t1 * dy;
  5607. }
  5608. ex += World.RegionInfo.WorldLocX;
  5609. ey += World.RegionInfo.WorldLocY;
  5610. if(World.GridService.GetRegionByPosition(RegionScopeID, (int)ex, (int)ey) != null)
  5611. return 0;
  5612. return 1;
  5613. }
  5614. /// <summary>
  5615. /// Not fully implemented yet. Still to do:-
  5616. /// AGENT_BUSY
  5617. /// Remove as they are done
  5618. /// </summary>
  5619. public LSL_Integer llGetAgentInfo(LSL_Key id)
  5620. {
  5621. m_host.AddScriptLPS(1);
  5622. UUID key = new UUID();
  5623. if (!UUID.TryParse(id, out key))
  5624. {
  5625. return 0;
  5626. }
  5627. int flags = 0;
  5628. ScenePresence agent = World.GetScenePresence(key);
  5629. if (agent == null)
  5630. {
  5631. return 0;
  5632. }
  5633. if (agent.IsChildAgent || agent.IsDeleted)
  5634. return 0; // Fail if they are not in the same region
  5635. try
  5636. {
  5637. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  5638. if (agent.SetAlwaysRun)
  5639. {
  5640. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  5641. }
  5642. if (agent.HasAttachments())
  5643. {
  5644. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  5645. if (agent.HasScriptedAttachments())
  5646. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  5647. }
  5648. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  5649. {
  5650. flags |= ScriptBaseClass.AGENT_FLYING;
  5651. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  5652. }
  5653. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  5654. {
  5655. flags |= ScriptBaseClass.AGENT_AWAY;
  5656. }
  5657. UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
  5658. UUID[] anims = agent.Animator.GetAnimationArray();
  5659. if (Array.Exists<UUID>(anims, a => { return a == busy; }))
  5660. {
  5661. flags |= ScriptBaseClass.AGENT_BUSY;
  5662. }
  5663. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  5664. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  5665. {
  5666. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  5667. }
  5668. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  5669. {
  5670. flags |= ScriptBaseClass.AGENT_TYPING;
  5671. }
  5672. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5673. if (agentMovementAnimation == "CROUCH")
  5674. {
  5675. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5676. }
  5677. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5678. {
  5679. flags |= ScriptBaseClass.AGENT_WALKING;
  5680. }
  5681. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5682. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5683. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5684. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5685. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5686. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5687. {
  5688. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5689. }
  5690. if (agent.ParentPart != null)
  5691. {
  5692. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5693. flags |= ScriptBaseClass.AGENT_SITTING;
  5694. }
  5695. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5696. == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  5697. {
  5698. flags |= ScriptBaseClass.AGENT_SITTING;
  5699. }
  5700. if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
  5701. {
  5702. flags |= ScriptBaseClass.AGENT_MALE;
  5703. }
  5704. }
  5705. catch
  5706. {
  5707. return 0;
  5708. }
  5709. return flags;
  5710. }
  5711. public LSL_String llGetAgentLanguage(LSL_Key id)
  5712. {
  5713. // This should only return a value if the avatar is in the same region, but eh. idc.
  5714. m_host.AddScriptLPS(1);
  5715. if (World.AgentPreferencesService == null)
  5716. {
  5717. Error("llGetAgentLanguage", "No AgentPreferencesService present");
  5718. }
  5719. else
  5720. {
  5721. UUID key = new UUID();
  5722. if (UUID.TryParse(id, out key))
  5723. {
  5724. return new LSL_String(World.AgentPreferencesService.GetLang(key));
  5725. }
  5726. }
  5727. return new LSL_String("en-us");
  5728. }
  5729. /// <summary>
  5730. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5731. /// The list of options is currently not used in SL
  5732. /// scope is one of:-
  5733. /// AGENT_LIST_REGION - all in the region
  5734. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5735. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5736. /// current parcel.
  5737. /// AGENT_LIST_EXCLUDENPC ignore NPCs (bit mask)
  5738. /// </summary>
  5739. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5740. {
  5741. m_host.AddScriptLPS(1);
  5742. // do our bit masks part
  5743. bool noNPC = (scope & ScriptBaseClass.AGENT_LIST_EXCLUDENPC) !=0;
  5744. // remove bit masks part
  5745. scope &= ~ ScriptBaseClass.AGENT_LIST_EXCLUDENPC;
  5746. // the constants are 1, 2 and 4 so bits are being set, but you
  5747. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5748. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5749. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5750. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5751. LSL_List result = new LSL_List();
  5752. if (!regionWide && !parcelOwned && !parcel)
  5753. {
  5754. result.Add("INVALID_SCOPE");
  5755. return result;
  5756. }
  5757. ILandObject land;
  5758. UUID id = UUID.Zero;
  5759. if (parcel || parcelOwned)
  5760. {
  5761. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5762. if (land == null)
  5763. {
  5764. id = UUID.Zero;
  5765. }
  5766. else
  5767. {
  5768. if (parcelOwned)
  5769. {
  5770. id = land.LandData.OwnerID;
  5771. }
  5772. else
  5773. {
  5774. id = land.LandData.GlobalID;
  5775. }
  5776. }
  5777. }
  5778. World.ForEachRootScenePresence(
  5779. delegate (ScenePresence ssp)
  5780. {
  5781. if(noNPC && ssp.IsNPC)
  5782. return;
  5783. // Gods are not listed in SL
  5784. if (!ssp.IsDeleted && !ssp.IsViewerUIGod && !ssp.IsChildAgent)
  5785. {
  5786. if (!regionWide)
  5787. {
  5788. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5789. if (land != null)
  5790. {
  5791. if (parcelOwned && land.LandData.OwnerID == id ||
  5792. parcel && land.LandData.GlobalID == id)
  5793. {
  5794. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5795. }
  5796. }
  5797. }
  5798. else
  5799. {
  5800. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5801. }
  5802. }
  5803. // Maximum of 100 results
  5804. if (result.Length > 99)
  5805. {
  5806. return;
  5807. }
  5808. }
  5809. );
  5810. return result;
  5811. }
  5812. public void llAdjustSoundVolume(LSL_Float volume)
  5813. {
  5814. m_host.AddScriptLPS(1);
  5815. m_host.AdjustSoundGain(volume);
  5816. ScriptSleep(m_sleepMsOnAdjustSoundVolume);
  5817. }
  5818. public void llSetSoundRadius(double radius)
  5819. {
  5820. m_host.AddScriptLPS(1);
  5821. m_host.SoundRadius = radius;
  5822. }
  5823. public LSL_String llKey2Name(LSL_Key id)
  5824. {
  5825. m_host.AddScriptLPS(1);
  5826. UUID key = new UUID();
  5827. if (UUID.TryParse(id,out key))
  5828. {
  5829. ScenePresence presence = World.GetScenePresence(key);
  5830. if (presence != null)
  5831. {
  5832. return presence.Name;
  5833. //return presence.Name;
  5834. }
  5835. if (World.GetSceneObjectPart(key) != null)
  5836. {
  5837. return World.GetSceneObjectPart(key).Name;
  5838. }
  5839. }
  5840. return String.Empty;
  5841. }
  5842. public LSL_Key llName2Key(LSL_String name)
  5843. {
  5844. m_host.AddScriptLPS(1);
  5845. if(string.IsNullOrWhiteSpace(name))
  5846. return ScriptBaseClass.NULL_KEY;
  5847. int nc = Util.ParseAvatarName(name, out string firstName, out string lastName, out string server);
  5848. if (nc < 2)
  5849. return ScriptBaseClass.NULL_KEY;
  5850. string sname;
  5851. if (nc == 2)
  5852. sname = firstName + " " + lastName;
  5853. else
  5854. sname = firstName + "." + lastName + " @" + server;
  5855. foreach (ScenePresence sp in World.GetScenePresences())
  5856. {
  5857. if (sp.IsDeleted || sp.IsChildAgent)
  5858. continue;
  5859. if (String.Compare(sname, sp.Name, true) == 0)
  5860. return sp.UUID.ToString();
  5861. }
  5862. return ScriptBaseClass.NULL_KEY;
  5863. }
  5864. public LSL_Key llRequestUserKey(LSL_String username)
  5865. {
  5866. m_host.AddScriptLPS(1);
  5867. if (string.IsNullOrWhiteSpace(username))
  5868. return ScriptBaseClass.NULL_KEY;
  5869. int nc = Util.ParseAvatarName(username, out string firstName, out string lastName, out string server);
  5870. if (nc < 2)
  5871. return ScriptBaseClass.NULL_KEY;
  5872. string sname;
  5873. if (nc == 2)
  5874. sname = firstName + " " + lastName;
  5875. else
  5876. sname = firstName + "." + lastName + " @" + server;
  5877. foreach (ScenePresence sp in World.GetScenePresences())
  5878. {
  5879. if (sp.IsDeleted || sp.IsChildAgent)
  5880. continue;
  5881. if (String.Compare(sname, sp.Name, true) == 0)
  5882. {
  5883. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  5884. m_item.ItemID, sp.UUID.ToString());
  5885. return ftid;
  5886. }
  5887. }
  5888. Action<string> act = eventID =>
  5889. {
  5890. string reply = ScriptBaseClass.NULL_KEY;
  5891. UUID userID = UUID.Zero;
  5892. IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
  5893. if (nc == 2)
  5894. {
  5895. if (userManager != null)
  5896. {
  5897. userID = userManager.GetUserIdByName(firstName, lastName);
  5898. if (userID != UUID.Zero)
  5899. reply = userID.ToString();
  5900. }
  5901. }
  5902. else
  5903. {
  5904. string url = "http://" + server;
  5905. if (Uri.TryCreate(url, UriKind.Absolute, out Uri dummy))
  5906. {
  5907. bool notfound = true;
  5908. if (userManager != null)
  5909. {
  5910. string hgfirst = firstName + "." + lastName;
  5911. string hglast = "@" + server;
  5912. userID = userManager.GetUserIdByName(hgfirst, hglast);
  5913. if (userID != UUID.Zero)
  5914. {
  5915. notfound = false;
  5916. reply = userID.ToString();
  5917. }
  5918. }
  5919. if(notfound)
  5920. {
  5921. try
  5922. {
  5923. UserAgentServiceConnector userConnection = new UserAgentServiceConnector(url);
  5924. if (userConnection != null)
  5925. {
  5926. userID = userConnection.GetUUID(firstName, lastName);
  5927. if (userID != UUID.Zero)
  5928. {
  5929. if (userManager != null)
  5930. userManager.AddUser(userID, firstName, lastName, url);
  5931. reply = userID.ToString();
  5932. }
  5933. }
  5934. }
  5935. catch
  5936. {
  5937. reply = ScriptBaseClass.NULL_KEY;
  5938. }
  5939. }
  5940. }
  5941. }
  5942. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  5943. };
  5944. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  5945. ScriptSleep(m_sleepMsOnRequestAgentData);
  5946. return tid.ToString();
  5947. }
  5948. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5949. {
  5950. m_host.AddScriptLPS(1);
  5951. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5952. }
  5953. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5954. {
  5955. m_host.AddScriptLPS(1);
  5956. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5957. try
  5958. {
  5959. foreach (SceneObjectPart part in parts)
  5960. {
  5961. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5962. }
  5963. }
  5964. finally
  5965. {
  5966. }
  5967. }
  5968. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5969. {
  5970. //ALL_SIDES
  5971. if (face == ScriptBaseClass.ALL_SIDES)
  5972. face = 255;
  5973. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation
  5974. {
  5975. Flags = (Primitive.TextureAnimMode)mode,
  5976. Face = (uint)face,
  5977. Length = (float)length,
  5978. Rate = (float)rate,
  5979. SizeX = (uint)sizex,
  5980. SizeY = (uint)sizey,
  5981. Start = (float)start
  5982. };
  5983. part.AddTextureAnimation(pTexAnim);
  5984. part.SendFullUpdateToAllClients();
  5985. part.ParentGroup.HasGroupChanged = true;
  5986. }
  5987. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5988. LSL_Vector bottom_south_west)
  5989. {
  5990. m_host.AddScriptLPS(1);
  5991. if (m_SoundModule != null)
  5992. {
  5993. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5994. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5995. bottom_south_west, top_north_east);
  5996. }
  5997. }
  5998. public void llEjectFromLand(LSL_Key pest)
  5999. {
  6000. m_host.AddScriptLPS(1);
  6001. UUID agentID = new UUID();
  6002. if (UUID.TryParse(pest, out agentID))
  6003. {
  6004. ScenePresence presence = World.GetScenePresence(agentID);
  6005. if (presence != null)
  6006. {
  6007. // agent must be over the owners land
  6008. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  6009. if (land == null)
  6010. return;
  6011. if (m_host.OwnerID == land.LandData.OwnerID)
  6012. {
  6013. Vector3 p = World.GetNearestAllowedPosition(presence, land);
  6014. presence.TeleportOnEject(p);
  6015. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  6016. }
  6017. }
  6018. }
  6019. ScriptSleep(m_sleepMsOnEjectFromLand);
  6020. }
  6021. public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
  6022. {
  6023. return ParseString2List(str, separators, in_spacers, false);
  6024. }
  6025. public LSL_Integer llOverMyLand(string id)
  6026. {
  6027. m_host.AddScriptLPS(1);
  6028. UUID key = new UUID();
  6029. if (UUID.TryParse(id, out key))
  6030. {
  6031. try
  6032. {
  6033. ScenePresence presence = World.GetScenePresence(key);
  6034. if (presence != null) // object is an avatar
  6035. {
  6036. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  6037. return 1;
  6038. }
  6039. else // object is not an avatar
  6040. {
  6041. SceneObjectPart obj = World.GetSceneObjectPart(key);
  6042. if (obj != null &&
  6043. m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  6044. return 1;
  6045. }
  6046. }
  6047. catch { }
  6048. }
  6049. return 0;
  6050. }
  6051. public LSL_Key llGetLandOwnerAt(LSL_Vector pos)
  6052. {
  6053. m_host.AddScriptLPS(1);
  6054. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  6055. if (land == null)
  6056. return ScriptBaseClass.NULL_KEY;
  6057. return land.LandData.OwnerID.ToString();
  6058. }
  6059. /// <summary>
  6060. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  6061. /// only the height of avatars vary and that says:
  6062. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  6063. /// </summary>
  6064. public LSL_Vector llGetAgentSize(LSL_Key id)
  6065. {
  6066. m_host.AddScriptLPS(1);
  6067. if(!UUID.TryParse(id, out UUID avID))
  6068. return ScriptBaseClass.ZERO_VECTOR;
  6069. ScenePresence avatar = World.GetScenePresence(avID);
  6070. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  6071. return ScriptBaseClass.ZERO_VECTOR;
  6072. // agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
  6073. Vector3 s = avatar.Appearance.AvatarSize;
  6074. return new LSL_Vector(s.X, s.Y, s.Z);
  6075. }
  6076. public LSL_Integer llSameGroup(string id)
  6077. {
  6078. m_host.AddScriptLPS(1);
  6079. UUID uuid;
  6080. if (!UUID.TryParse(id, out uuid))
  6081. return 0;
  6082. // Check if it's a group key
  6083. if (uuid == m_host.ParentGroup.RootPart.GroupID)
  6084. return 1;
  6085. // Handle object case
  6086. SceneObjectPart part = World.GetSceneObjectPart(uuid);
  6087. if (part != null)
  6088. {
  6089. if(part.ParentGroup.IsAttachment)
  6090. {
  6091. uuid = part.ParentGroup.AttachedAvatar;
  6092. }
  6093. else
  6094. {
  6095. // This will handle both deed and non-deed and also the no
  6096. // group case
  6097. if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
  6098. return 1;
  6099. return 0;
  6100. }
  6101. }
  6102. // Handle the case where id names an avatar
  6103. ScenePresence presence = World.GetScenePresence(uuid);
  6104. if (presence != null)
  6105. {
  6106. if (presence.IsChildAgent)
  6107. return 0;
  6108. IClientAPI client = presence.ControllingClient;
  6109. if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
  6110. return 1;
  6111. return 0;
  6112. }
  6113. return 0;
  6114. }
  6115. public void llUnSit(string id)
  6116. {
  6117. m_host.AddScriptLPS(1);
  6118. UUID key = new UUID();
  6119. if (UUID.TryParse(id, out key))
  6120. {
  6121. ScenePresence av = World.GetScenePresence(key);
  6122. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  6123. if (av != null)
  6124. {
  6125. if (sittingAvatars.Contains(av))
  6126. {
  6127. // if the avatar is sitting on this object, then
  6128. // we can unsit them. We don't want random scripts unsitting random people
  6129. // Lets avoid the popcorn avatar scenario.
  6130. av.StandUp();
  6131. }
  6132. else
  6133. {
  6134. // If the object owner also owns the parcel
  6135. // or
  6136. // if the land is group owned and the object is group owned by the same group
  6137. // or
  6138. // if the object is owned by a person with estate access.
  6139. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  6140. if (parcel != null)
  6141. {
  6142. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  6143. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  6144. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  6145. {
  6146. av.StandUp();
  6147. }
  6148. }
  6149. }
  6150. }
  6151. }
  6152. }
  6153. public LSL_Vector llGroundSlope(LSL_Vector offset)
  6154. {
  6155. m_host.AddScriptLPS(1);
  6156. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  6157. LSL_Vector vsn = llGroundNormal(offset);
  6158. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  6159. //the height of that point on the plane. The resulting vector gives the slope.
  6160. Vector3 vsl = vsn;
  6161. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  6162. vsl.Normalize();
  6163. //Normalization might be overkill here
  6164. vsn.x = vsl.X;
  6165. vsn.y = vsl.Y;
  6166. vsn.z = vsl.Z;
  6167. return vsn;
  6168. }
  6169. public LSL_Vector llGroundNormal(LSL_Vector offset)
  6170. {
  6171. m_host.AddScriptLPS(1);
  6172. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  6173. // Clamp to valid position
  6174. if (pos.X < 0)
  6175. pos.X = 0;
  6176. else if (pos.X >= World.Heightmap.Width)
  6177. pos.X = World.Heightmap.Width - 1;
  6178. if (pos.Y < 0)
  6179. pos.Y = 0;
  6180. else if (pos.Y >= World.Heightmap.Height)
  6181. pos.Y = World.Heightmap.Height - 1;
  6182. //Find two points in addition to the position to define a plane
  6183. Vector3 p0 = new Vector3(pos.X, pos.Y,
  6184. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6185. Vector3 p1 = new Vector3();
  6186. Vector3 p2 = new Vector3();
  6187. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  6188. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6189. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6190. else
  6191. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6192. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  6193. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  6194. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6195. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6196. else
  6197. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6198. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  6199. //Find normalized vectors from p0 to p1 and p0 to p2
  6200. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  6201. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  6202. v0.Normalize();
  6203. v1.Normalize();
  6204. //Find the cross product of the vectors (the slope normal).
  6205. Vector3 vsn = new Vector3
  6206. {
  6207. X = (v0.Y * v1.Z) - (v0.Z * v1.Y),
  6208. Y = (v0.Z * v1.X) - (v0.X * v1.Z),
  6209. Z = (v0.X * v1.Y) - (v0.Y * v1.X)
  6210. };
  6211. vsn.Normalize();
  6212. //I believe the crossproduct of two normalized vectors is a normalized vector so
  6213. //this normalization may be overkill
  6214. return new LSL_Vector(vsn);
  6215. }
  6216. public LSL_Vector llGroundContour(LSL_Vector offset)
  6217. {
  6218. m_host.AddScriptLPS(1);
  6219. LSL_Vector x = llGroundSlope(offset);
  6220. return new LSL_Vector(-x.y, x.x, 0.0);
  6221. }
  6222. public LSL_Integer llGetAttached()
  6223. {
  6224. m_host.AddScriptLPS(1);
  6225. return m_host.ParentGroup.AttachmentPoint;
  6226. }
  6227. public LSL_List llGetAttachedList(LSL_Key id)
  6228. {
  6229. m_host.AddScriptLPS(1);
  6230. if(!UUID.TryParse(id, out UUID avID))
  6231. return new LSL_List("NOT_FOUND");
  6232. ScenePresence av = World.GetScenePresence(avID);
  6233. if (av == null || av.IsDeleted)
  6234. return new LSL_List("NOT_FOUND");
  6235. if (av.IsChildAgent || av.IsInTransit)
  6236. return new LSL_List("NOT_ON_REGION");
  6237. LSL_List AttachmentsList = new LSL_List();
  6238. List<SceneObjectGroup> Attachments;
  6239. Attachments = av.GetAttachments();
  6240. foreach (SceneObjectGroup Attachment in Attachments)
  6241. {
  6242. if(Attachment.HasPrivateAttachmentPoint)
  6243. continue;
  6244. AttachmentsList.Add(new LSL_Key(Attachment.UUID.ToString()));
  6245. }
  6246. return AttachmentsList;
  6247. }
  6248. public virtual LSL_Integer llGetFreeMemory()
  6249. {
  6250. m_host.AddScriptLPS(1);
  6251. // Make scripts designed for Mono happy
  6252. return 65536;
  6253. }
  6254. public LSL_Integer llGetFreeURLs()
  6255. {
  6256. m_host.AddScriptLPS(1);
  6257. if (m_UrlModule != null)
  6258. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  6259. return new LSL_Integer(0);
  6260. }
  6261. public LSL_String llGetRegionName()
  6262. {
  6263. m_host.AddScriptLPS(1);
  6264. return World.RegionInfo.RegionName;
  6265. }
  6266. public LSL_Float llGetRegionTimeDilation()
  6267. {
  6268. m_host.AddScriptLPS(1);
  6269. return (double)World.TimeDilation;
  6270. }
  6271. /// <summary>
  6272. /// Returns the value reported in the client Statistics window
  6273. /// </summary>
  6274. public LSL_Float llGetRegionFPS()
  6275. {
  6276. m_host.AddScriptLPS(1);
  6277. return World.StatsReporter.LastReportedSimFPS;
  6278. }
  6279. /* particle system rules should be coming into this routine as doubles, that is
  6280. rule[0] should be an integer from this list and rule[1] should be the arg
  6281. for the same integer. wiki.secondlife.com has most of this mapping, but some
  6282. came from http://www.caligari-designs.com/p4u2
  6283. We iterate through the list for 'Count' elements, incrementing by two for each
  6284. iteration and set the members of Primitive.ParticleSystem, one at a time.
  6285. */
  6286. public enum PrimitiveRule : int
  6287. {
  6288. PSYS_PART_FLAGS = 0,
  6289. PSYS_PART_START_COLOR = 1,
  6290. PSYS_PART_START_ALPHA = 2,
  6291. PSYS_PART_END_COLOR = 3,
  6292. PSYS_PART_END_ALPHA = 4,
  6293. PSYS_PART_START_SCALE = 5,
  6294. PSYS_PART_END_SCALE = 6,
  6295. PSYS_PART_MAX_AGE = 7,
  6296. PSYS_SRC_ACCEL = 8,
  6297. PSYS_SRC_PATTERN = 9,
  6298. PSYS_SRC_INNERANGLE = 10,
  6299. PSYS_SRC_OUTERANGLE = 11,
  6300. PSYS_SRC_TEXTURE = 12,
  6301. PSYS_SRC_BURST_RATE = 13,
  6302. PSYS_SRC_BURST_PART_COUNT = 15,
  6303. PSYS_SRC_BURST_RADIUS = 16,
  6304. PSYS_SRC_BURST_SPEED_MIN = 17,
  6305. PSYS_SRC_BURST_SPEED_MAX = 18,
  6306. PSYS_SRC_MAX_AGE = 19,
  6307. PSYS_SRC_TARGET_KEY = 20,
  6308. PSYS_SRC_OMEGA = 21,
  6309. PSYS_SRC_ANGLE_BEGIN = 22,
  6310. PSYS_SRC_ANGLE_END = 23,
  6311. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  6312. PSYS_PART_BLEND_FUNC_DEST = 25,
  6313. PSYS_PART_START_GLOW = 26,
  6314. PSYS_PART_END_GLOW = 27
  6315. }
  6316. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  6317. {
  6318. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  6319. return returnval;
  6320. }
  6321. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  6322. {
  6323. Primitive.ParticleSystem ps = new Primitive.ParticleSystem
  6324. {
  6325. PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f),
  6326. PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f),
  6327. PartStartScaleX = 1.0f,
  6328. PartStartScaleY = 1.0f,
  6329. PartEndScaleX = 1.0f,
  6330. PartEndScaleY = 1.0f,
  6331. BurstSpeedMin = 1.0f,
  6332. BurstSpeedMax = 1.0f,
  6333. BurstRate = 0.1f,
  6334. PartMaxAge = 10.0f,
  6335. BurstPartCount = 1,
  6336. BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA,
  6337. BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA,
  6338. PartStartGlow = 0.0f,
  6339. PartEndGlow = 0.0f
  6340. };
  6341. return ps;
  6342. }
  6343. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  6344. {
  6345. m_host.AddScriptLPS(1);
  6346. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6347. foreach (SceneObjectPart part in parts)
  6348. {
  6349. SetParticleSystem(part, rules, "llLinkParticleSystem");
  6350. }
  6351. }
  6352. public void llParticleSystem(LSL_List rules)
  6353. {
  6354. m_host.AddScriptLPS(1);
  6355. SetParticleSystem(m_host, rules, "llParticleSystem");
  6356. }
  6357. public void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc, bool expire = false)
  6358. {
  6359. if (rules.Length == 0)
  6360. {
  6361. part.RemoveParticleSystem();
  6362. part.ParentGroup.HasGroupChanged = true;
  6363. }
  6364. else
  6365. {
  6366. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  6367. LSL_Vector tempv = new LSL_Vector();
  6368. float tempf = 0;
  6369. int tmpi = 0;
  6370. for (int i = 0; i < rules.Length; i += 2)
  6371. {
  6372. int psystype;
  6373. try
  6374. {
  6375. psystype = rules.GetLSLIntegerItem(i);
  6376. }
  6377. catch (InvalidCastException)
  6378. {
  6379. Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i));
  6380. return;
  6381. }
  6382. switch (psystype)
  6383. {
  6384. case ScriptBaseClass.PSYS_PART_FLAGS:
  6385. try
  6386. {
  6387. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  6388. }
  6389. catch(InvalidCastException)
  6390. {
  6391. Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1));
  6392. return;
  6393. }
  6394. break;
  6395. case ScriptBaseClass.PSYS_PART_START_COLOR:
  6396. try
  6397. {
  6398. tempv = rules.GetVector3Item(i + 1);
  6399. }
  6400. catch(InvalidCastException)
  6401. {
  6402. Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6403. return;
  6404. }
  6405. prules.PartStartColor.R = (float)tempv.x;
  6406. prules.PartStartColor.G = (float)tempv.y;
  6407. prules.PartStartColor.B = (float)tempv.z;
  6408. break;
  6409. case ScriptBaseClass.PSYS_PART_START_ALPHA:
  6410. try
  6411. {
  6412. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6413. }
  6414. catch(InvalidCastException)
  6415. {
  6416. Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6417. return;
  6418. }
  6419. prules.PartStartColor.A = tempf;
  6420. break;
  6421. case ScriptBaseClass.PSYS_PART_END_COLOR:
  6422. try
  6423. {
  6424. tempv = rules.GetVector3Item(i + 1);
  6425. }
  6426. catch(InvalidCastException)
  6427. {
  6428. Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6429. return;
  6430. }
  6431. prules.PartEndColor.R = (float)tempv.x;
  6432. prules.PartEndColor.G = (float)tempv.y;
  6433. prules.PartEndColor.B = (float)tempv.z;
  6434. break;
  6435. case ScriptBaseClass.PSYS_PART_END_ALPHA:
  6436. try
  6437. {
  6438. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6439. }
  6440. catch(InvalidCastException)
  6441. {
  6442. Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6443. return;
  6444. }
  6445. prules.PartEndColor.A = tempf;
  6446. break;
  6447. case ScriptBaseClass.PSYS_PART_START_SCALE:
  6448. try
  6449. {
  6450. tempv = rules.GetVector3Item(i + 1);
  6451. }
  6452. catch(InvalidCastException)
  6453. {
  6454. Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6455. return;
  6456. }
  6457. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  6458. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  6459. break;
  6460. case ScriptBaseClass.PSYS_PART_END_SCALE:
  6461. try
  6462. {
  6463. tempv = rules.GetVector3Item(i + 1);
  6464. }
  6465. catch(InvalidCastException)
  6466. {
  6467. Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6468. return;
  6469. }
  6470. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  6471. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  6472. break;
  6473. case ScriptBaseClass.PSYS_PART_MAX_AGE:
  6474. try
  6475. {
  6476. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6477. }
  6478. catch(InvalidCastException)
  6479. {
  6480. Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6481. return;
  6482. }
  6483. prules.PartMaxAge = tempf;
  6484. break;
  6485. case ScriptBaseClass.PSYS_SRC_ACCEL:
  6486. try
  6487. {
  6488. tempv = rules.GetVector3Item(i + 1);
  6489. }
  6490. catch(InvalidCastException)
  6491. {
  6492. Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1));
  6493. return;
  6494. }
  6495. prules.PartAcceleration.X = (float)tempv.x;
  6496. prules.PartAcceleration.Y = (float)tempv.y;
  6497. prules.PartAcceleration.Z = (float)tempv.z;
  6498. break;
  6499. case ScriptBaseClass.PSYS_SRC_PATTERN:
  6500. try
  6501. {
  6502. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6503. }
  6504. catch(InvalidCastException)
  6505. {
  6506. Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1));
  6507. return;
  6508. }
  6509. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  6510. break;
  6511. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  6512. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  6513. // client tells the difference between the two by looking at the 0x02 bit in
  6514. // the PartFlags variable.
  6515. case ScriptBaseClass.PSYS_SRC_INNERANGLE:
  6516. try
  6517. {
  6518. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6519. }
  6520. catch(InvalidCastException)
  6521. {
  6522. Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6523. return;
  6524. }
  6525. prules.InnerAngle = (float)tempf;
  6526. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6527. break;
  6528. case ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  6529. try
  6530. {
  6531. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6532. }
  6533. catch(InvalidCastException)
  6534. {
  6535. Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6536. return;
  6537. }
  6538. prules.OuterAngle = (float)tempf;
  6539. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6540. break;
  6541. case ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  6542. try
  6543. {
  6544. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6545. }
  6546. catch(InvalidCastException)
  6547. {
  6548. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1));
  6549. return;
  6550. }
  6551. prules.BlendFuncSource = (byte)tmpi;
  6552. break;
  6553. case ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  6554. try
  6555. {
  6556. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6557. }
  6558. catch(InvalidCastException)
  6559. {
  6560. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1));
  6561. return;
  6562. }
  6563. prules.BlendFuncDest = (byte)tmpi;
  6564. break;
  6565. case ScriptBaseClass.PSYS_PART_START_GLOW:
  6566. try
  6567. {
  6568. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6569. }
  6570. catch(InvalidCastException)
  6571. {
  6572. Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6573. return;
  6574. }
  6575. prules.PartStartGlow = (float)tempf;
  6576. break;
  6577. case ScriptBaseClass.PSYS_PART_END_GLOW:
  6578. try
  6579. {
  6580. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6581. }
  6582. catch(InvalidCastException)
  6583. {
  6584. Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6585. return;
  6586. }
  6587. prules.PartEndGlow = (float)tempf;
  6588. break;
  6589. case ScriptBaseClass.PSYS_SRC_TEXTURE:
  6590. try
  6591. {
  6592. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  6593. }
  6594. catch(InvalidCastException)
  6595. {
  6596. Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1));
  6597. return;
  6598. }
  6599. break;
  6600. case ScriptBaseClass.PSYS_SRC_BURST_RATE:
  6601. try
  6602. {
  6603. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6604. }
  6605. catch(InvalidCastException)
  6606. {
  6607. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1));
  6608. return;
  6609. }
  6610. prules.BurstRate = (float)tempf;
  6611. break;
  6612. case ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  6613. try
  6614. {
  6615. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  6616. }
  6617. catch(InvalidCastException)
  6618. {
  6619. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1));
  6620. return;
  6621. }
  6622. break;
  6623. case ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  6624. try
  6625. {
  6626. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6627. }
  6628. catch(InvalidCastException)
  6629. {
  6630. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1));
  6631. return;
  6632. }
  6633. prules.BurstRadius = (float)tempf;
  6634. break;
  6635. case ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  6636. try
  6637. {
  6638. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6639. }
  6640. catch(InvalidCastException)
  6641. {
  6642. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1));
  6643. return;
  6644. }
  6645. prules.BurstSpeedMin = (float)tempf;
  6646. break;
  6647. case ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  6648. try
  6649. {
  6650. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6651. }
  6652. catch(InvalidCastException)
  6653. {
  6654. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1));
  6655. return;
  6656. }
  6657. prules.BurstSpeedMax = (float)tempf;
  6658. break;
  6659. case ScriptBaseClass.PSYS_SRC_MAX_AGE:
  6660. try
  6661. {
  6662. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6663. }
  6664. catch(InvalidCastException)
  6665. {
  6666. Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6667. return;
  6668. }
  6669. prules.MaxAge = (float)tempf;
  6670. break;
  6671. case ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  6672. UUID key = UUID.Zero;
  6673. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  6674. {
  6675. prules.Target = key;
  6676. }
  6677. else
  6678. {
  6679. prules.Target = part.UUID;
  6680. }
  6681. break;
  6682. case ScriptBaseClass.PSYS_SRC_OMEGA:
  6683. // AL: This is an assumption, since it is the only thing that would match.
  6684. try
  6685. {
  6686. tempv = rules.GetVector3Item(i + 1);
  6687. }
  6688. catch(InvalidCastException)
  6689. {
  6690. Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1));
  6691. return;
  6692. }
  6693. prules.AngularVelocity.X = (float)tempv.x;
  6694. prules.AngularVelocity.Y = (float)tempv.y;
  6695. prules.AngularVelocity.Z = (float)tempv.z;
  6696. break;
  6697. case ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  6698. try
  6699. {
  6700. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6701. }
  6702. catch(InvalidCastException)
  6703. {
  6704. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1));
  6705. return;
  6706. }
  6707. prules.InnerAngle = (float)tempf;
  6708. prules.PartFlags |= 0x02; // Set new angle format.
  6709. break;
  6710. case ScriptBaseClass.PSYS_SRC_ANGLE_END:
  6711. try
  6712. {
  6713. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6714. }
  6715. catch (InvalidCastException)
  6716. {
  6717. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1));
  6718. return;
  6719. }
  6720. prules.OuterAngle = (float)tempf;
  6721. prules.PartFlags |= 0x02; // Set new angle format.
  6722. break;
  6723. }
  6724. }
  6725. prules.CRC = 1;
  6726. part.AddNewParticleSystem(prules, expire);
  6727. if(!expire || prules.MaxAge != 0 || prules.MaxAge > 300)
  6728. part.ParentGroup.HasGroupChanged = true;
  6729. }
  6730. part.SendFullUpdateToAllClients();
  6731. }
  6732. private float validParticleScale(float value)
  6733. {
  6734. if (value > 7.96f) return 7.96f;
  6735. return value;
  6736. }
  6737. public void llGroundRepel(double height, int water, double tau)
  6738. {
  6739. m_host.AddScriptLPS(1);
  6740. if (m_host.PhysActor != null)
  6741. {
  6742. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  6743. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  6744. PIDHoverType hoverType = PIDHoverType.Ground;
  6745. if (water != 0)
  6746. {
  6747. hoverType = PIDHoverType.GroundAndWater;
  6748. if (ground < waterLevel)
  6749. height += waterLevel;
  6750. else
  6751. height += ground;
  6752. }
  6753. else
  6754. {
  6755. height += ground;
  6756. }
  6757. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  6758. }
  6759. }
  6760. public void llGiveInventoryList(LSL_Key destination, LSL_String category, LSL_List inventory)
  6761. {
  6762. m_host.AddScriptLPS(1);
  6763. if (!UUID.TryParse(destination, out UUID destID))
  6764. return;
  6765. ScenePresence sp = null;
  6766. bool isNotOwner = true;
  6767. if (!World.TryGetSceneObjectPart(destID, out SceneObjectPart destSop))
  6768. {
  6769. if (!World.TryGetScenePresence(destID, out sp))
  6770. {
  6771. // we could check if it is a grid user and allow the transfer as in older code
  6772. // but that increases security risk
  6773. Error("llGiveInventoryList", "Unable to give list, destination not found");
  6774. ScriptSleep(100);
  6775. return;
  6776. }
  6777. isNotOwner = sp.UUID != m_host.OwnerID;
  6778. }
  6779. List<UUID> itemList = new List<UUID>();
  6780. foreach (Object item in inventory.Data)
  6781. {
  6782. string rawItemString = item.ToString();
  6783. TaskInventoryItem taskItem = null;
  6784. if (UUID.TryParse(rawItemString, out UUID itemID))
  6785. taskItem = m_host.Inventory.GetInventoryItem(itemID);
  6786. else
  6787. taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  6788. if(taskItem == null)
  6789. continue;
  6790. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  6791. continue;
  6792. if (destSop != null)
  6793. {
  6794. if(!World.Permissions.CanDoObjectInvToObjectInv(taskItem, m_host, destSop))
  6795. continue;
  6796. }
  6797. else
  6798. {
  6799. if(isNotOwner)
  6800. {
  6801. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  6802. continue;
  6803. }
  6804. }
  6805. itemList.Add(taskItem.ItemID);
  6806. }
  6807. if (itemList.Count == 0)
  6808. {
  6809. Error("llGiveInventoryList", "Unable to give list, no items found");
  6810. ScriptSleep(100);
  6811. return;
  6812. }
  6813. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList, false);
  6814. if (folderID == UUID.Zero)
  6815. {
  6816. Error("llGiveInventoryList", "Unable to give list");
  6817. ScriptSleep(100);
  6818. return;
  6819. }
  6820. if (destSop != null)
  6821. return;
  6822. if (m_TransferModule != null)
  6823. {
  6824. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  6825. Vector3 pos = m_host.AbsolutePosition;
  6826. GridInstantMessage msg = new GridInstantMessage(World,
  6827. m_host.OwnerID, m_host.Name, destID,
  6828. (byte)InstantMessageDialog.TaskInventoryOffered,
  6829. m_host.OwnerID == m_host.GroupID,
  6830. string.Format("'{0}'", category),
  6831. //string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  6832. folderID, false, pos,
  6833. bucket, false);
  6834. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  6835. }
  6836. ScriptSleep(destSop == null ? 3000 : 100);
  6837. }
  6838. public void llSetVehicleType(int type)
  6839. {
  6840. m_host.AddScriptLPS(1);
  6841. if (!m_host.ParentGroup.IsDeleted)
  6842. {
  6843. m_host.ParentGroup.RootPart.SetVehicleType(type);
  6844. }
  6845. }
  6846. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6847. //CFK 9/28: so these are not complete yet.
  6848. public void llSetVehicleFloatParam(int param, LSL_Float value)
  6849. {
  6850. m_host.AddScriptLPS(1);
  6851. if (!m_host.ParentGroup.IsDeleted)
  6852. {
  6853. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  6854. }
  6855. }
  6856. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6857. //CFK 9/28: so these are not complete yet.
  6858. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  6859. {
  6860. m_host.AddScriptLPS(1);
  6861. if (!m_host.ParentGroup.IsDeleted)
  6862. {
  6863. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  6864. }
  6865. }
  6866. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6867. //CFK 9/28: so these are not complete yet.
  6868. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  6869. {
  6870. m_host.AddScriptLPS(1);
  6871. if (!m_host.ParentGroup.IsDeleted)
  6872. {
  6873. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  6874. }
  6875. }
  6876. public void llSetVehicleFlags(int flags)
  6877. {
  6878. m_host.AddScriptLPS(1);
  6879. if (!m_host.ParentGroup.IsDeleted)
  6880. {
  6881. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  6882. }
  6883. }
  6884. public void llRemoveVehicleFlags(int flags)
  6885. {
  6886. m_host.AddScriptLPS(1);
  6887. if (!m_host.ParentGroup.IsDeleted)
  6888. {
  6889. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  6890. }
  6891. }
  6892. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  6893. {
  6894. // LSL quaternions can normalize to 0, normal Quaternions can't.
  6895. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  6896. rot.s = 1; // ZERO_ROTATION = 0,0,0,1
  6897. part.SitTargetPosition = offset;
  6898. part.SitTargetOrientation = rot;
  6899. part.ParentGroup.HasGroupChanged = true;
  6900. }
  6901. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  6902. {
  6903. m_host.AddScriptLPS(1);
  6904. SitTarget(m_host, offset, rot);
  6905. }
  6906. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  6907. {
  6908. m_host.AddScriptLPS(1);
  6909. if (link == ScriptBaseClass.LINK_ROOT)
  6910. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  6911. else if (link == ScriptBaseClass.LINK_THIS)
  6912. SitTarget(m_host, offset, rot);
  6913. else
  6914. {
  6915. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  6916. if (null != part)
  6917. {
  6918. SitTarget(part, offset, rot);
  6919. }
  6920. }
  6921. }
  6922. public LSL_Key llAvatarOnSitTarget()
  6923. {
  6924. m_host.AddScriptLPS(1);
  6925. return m_host.SitTargetAvatar.ToString();
  6926. }
  6927. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  6928. public LSL_Key llAvatarOnLinkSitTarget(LSL_Integer linknum)
  6929. {
  6930. m_host.AddScriptLPS(1);
  6931. if(linknum == ScriptBaseClass.LINK_SET ||
  6932. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6933. linknum == ScriptBaseClass.LINK_ALL_OTHERS ||
  6934. linknum == 0)
  6935. return ScriptBaseClass.NULL_KEY;
  6936. List<SceneObjectPart> parts = GetLinkParts(linknum);
  6937. if (parts.Count == 0)
  6938. return ScriptBaseClass.NULL_KEY;
  6939. return parts[0].SitTargetAvatar.ToString();
  6940. }
  6941. public void llAddToLandPassList(LSL_Key avatar, LSL_Float hours)
  6942. {
  6943. m_host.AddScriptLPS(1);
  6944. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6945. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  6946. {
  6947. int expires = 0;
  6948. if (hours != 0)
  6949. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  6950. if (UUID.TryParse(avatar, out UUID key))
  6951. {
  6952. int idx = land.LandData.ParcelAccessList.FindIndex(
  6953. delegate(LandAccessEntry e)
  6954. {
  6955. if (e.AgentID == key && e.Flags == AccessList.Access)
  6956. return true;
  6957. return false;
  6958. });
  6959. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  6960. return;
  6961. if (idx != -1)
  6962. land.LandData.ParcelAccessList.RemoveAt(idx);
  6963. LandAccessEntry entry = new LandAccessEntry
  6964. {
  6965. AgentID = key,
  6966. Flags = AccessList.Access,
  6967. Expires = expires
  6968. };
  6969. land.LandData.ParcelAccessList.Add(entry);
  6970. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  6971. }
  6972. }
  6973. ScriptSleep(m_sleepMsOnAddToLandPassList);
  6974. }
  6975. public void llSetTouchText(string text)
  6976. {
  6977. m_host.AddScriptLPS(1);
  6978. if(text.Length <= 9)
  6979. m_host.TouchName = text;
  6980. else
  6981. m_host.TouchName = text.Substring(0, 9);
  6982. }
  6983. public void llSetSitText(string text)
  6984. {
  6985. m_host.AddScriptLPS(1);
  6986. if (text.Length <= 9)
  6987. m_host.SitName = text;
  6988. else
  6989. m_host.SitName = text.Substring(0, 9);
  6990. }
  6991. public void llSetCameraEyeOffset(LSL_Vector offset)
  6992. {
  6993. m_host.AddScriptLPS(1);
  6994. m_host.SetCameraEyeOffset(offset);
  6995. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  6996. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  6997. }
  6998. public void llSetCameraAtOffset(LSL_Vector offset)
  6999. {
  7000. m_host.AddScriptLPS(1);
  7001. m_host.SetCameraAtOffset(offset);
  7002. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  7003. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  7004. }
  7005. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  7006. {
  7007. m_host.AddScriptLPS(1);
  7008. if (link == ScriptBaseClass.LINK_SET ||
  7009. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  7010. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  7011. SceneObjectPart part = null;
  7012. switch (link)
  7013. {
  7014. case ScriptBaseClass.LINK_ROOT:
  7015. part = m_host.ParentGroup.RootPart;
  7016. break;
  7017. case ScriptBaseClass.LINK_THIS:
  7018. part = m_host;
  7019. break;
  7020. default:
  7021. part = m_host.ParentGroup.GetLinkNumPart(link);
  7022. break;
  7023. }
  7024. if (null != part)
  7025. {
  7026. part.SetCameraEyeOffset(eye);
  7027. part.SetCameraAtOffset(at);
  7028. }
  7029. }
  7030. public LSL_String llDumpList2String(LSL_List src, string seperator)
  7031. {
  7032. m_host.AddScriptLPS(1);
  7033. if (src.Length == 0)
  7034. {
  7035. return String.Empty;
  7036. }
  7037. string ret = String.Empty;
  7038. foreach (object o in src.Data)
  7039. {
  7040. ret = ret + o.ToString() + seperator;
  7041. }
  7042. ret = ret.Substring(0, ret.Length - seperator.Length);
  7043. return ret;
  7044. }
  7045. public LSL_Integer llScriptDanger(LSL_Vector pos)
  7046. {
  7047. m_host.AddScriptLPS(1);
  7048. bool result = World.LSLScriptDanger(m_host, pos);
  7049. if (result)
  7050. {
  7051. return 1;
  7052. }
  7053. else
  7054. {
  7055. return 0;
  7056. }
  7057. }
  7058. public void llDialog(LSL_Key avatar, LSL_String message, LSL_List buttons, int chat_channel)
  7059. {
  7060. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  7061. if (dm == null)
  7062. return;
  7063. m_host.AddScriptLPS(1);
  7064. UUID av = new UUID();
  7065. if (!UUID.TryParse(avatar,out av))
  7066. {
  7067. Error("llDialog", "First parameter must be a key");
  7068. return;
  7069. }
  7070. int length = buttons.Length;
  7071. if (length < 1)
  7072. {
  7073. buttons.Add(new LSL_String("Ok"));
  7074. length = 1;
  7075. }
  7076. else if (length > 12)
  7077. {
  7078. Error("llDialog", "No more than 12 buttons can be shown");
  7079. return;
  7080. }
  7081. if (message == string.Empty)
  7082. {
  7083. Error("llDialog", "Empty message");
  7084. }
  7085. else if (Encoding.UTF8.GetByteCount(message) > 512)
  7086. {
  7087. Error("llDialog", "Message longer than 512 bytes");
  7088. }
  7089. string[] buts = new string[length];
  7090. for (int i = 0; i < length; i++)
  7091. {
  7092. if (buttons.Data[i].ToString() == String.Empty)
  7093. {
  7094. Error("llDialog", "Button label cannot be blank");
  7095. return;
  7096. }
  7097. /*
  7098. if (buttons.Data[i].ToString().Length > 24)
  7099. {
  7100. Error("llDialog", "Button label cannot be longer than 24 characters");
  7101. return;
  7102. }
  7103. */
  7104. buts[i] = buttons.Data[i].ToString();
  7105. }
  7106. dm.SendDialogToUser(
  7107. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  7108. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  7109. ScriptSleep(m_sleepMsOnDialog);
  7110. }
  7111. public void llVolumeDetect(int detect)
  7112. {
  7113. m_host.AddScriptLPS(1);
  7114. if (!m_host.ParentGroup.IsDeleted)
  7115. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  7116. }
  7117. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  7118. {
  7119. m_host.AddScriptLPS(1);
  7120. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  7121. ScriptSleep(m_sleepMsOnRemoteLoadScript);
  7122. }
  7123. public void llSetRemoteScriptAccessPin(int pin)
  7124. {
  7125. m_host.AddScriptLPS(1);
  7126. m_host.ScriptAccessPin = pin;
  7127. }
  7128. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  7129. {
  7130. m_host.AddScriptLPS(1);
  7131. UUID destId = UUID.Zero;
  7132. if (!UUID.TryParse(target, out destId))
  7133. {
  7134. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  7135. return;
  7136. }
  7137. // target must be a different prim than the one containing the script
  7138. if (m_host.UUID == destId)
  7139. {
  7140. return;
  7141. }
  7142. // copy the first script found with this inventory name
  7143. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  7144. // make sure the object is a script
  7145. if (item == null || item.Type != 10)
  7146. {
  7147. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  7148. return;
  7149. }
  7150. SceneObjectPart dest = World.GetSceneObjectPart(destId);
  7151. if (dest != null)
  7152. {
  7153. if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
  7154. {
  7155. // the rest of the permission checks are done in RezScript, so check the pin there as well
  7156. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  7157. if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
  7158. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  7159. }
  7160. }
  7161. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  7162. ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
  7163. }
  7164. public void llOpenRemoteDataChannel()
  7165. {
  7166. m_host.AddScriptLPS(1);
  7167. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7168. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  7169. {
  7170. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  7171. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7172. if (xmlRpcRouter != null)
  7173. {
  7174. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  7175. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  7176. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  7177. xmlrpcMod.Port.ToString()));
  7178. }
  7179. object[] resobj = new object[]
  7180. {
  7181. new LSL_Integer(1),
  7182. new LSL_String(channelID.ToString()),
  7183. new LSL_String(ScriptBaseClass.NULL_KEY),
  7184. new LSL_String(String.Empty),
  7185. new LSL_Integer(0),
  7186. new LSL_String(String.Empty)
  7187. };
  7188. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  7189. new DetectParams[0]));
  7190. }
  7191. ScriptSleep(m_sleepMsOnOpenRemoteDataChannel);
  7192. }
  7193. public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
  7194. {
  7195. m_host.AddScriptLPS(1);
  7196. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7197. ScriptSleep(m_sleepMsOnSendRemoteData);
  7198. if (xmlrpcMod == null)
  7199. return "";
  7200. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  7201. }
  7202. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  7203. {
  7204. m_host.AddScriptLPS(1);
  7205. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7206. if (xmlrpcMod != null)
  7207. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  7208. ScriptSleep(m_sleepMsOnRemoteDataReply);
  7209. }
  7210. public void llCloseRemoteDataChannel(string channel)
  7211. {
  7212. m_host.AddScriptLPS(1);
  7213. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7214. if (xmlRpcRouter != null)
  7215. {
  7216. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  7217. }
  7218. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7219. if (xmlrpcMod != null)
  7220. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  7221. ScriptSleep(m_sleepMsOnCloseRemoteDataChannel);
  7222. }
  7223. public LSL_String llMD5String(string src, int nonce)
  7224. {
  7225. m_host.AddScriptLPS(1);
  7226. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
  7227. }
  7228. public LSL_String llSHA1String(string src)
  7229. {
  7230. m_host.AddScriptLPS(1);
  7231. return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
  7232. }
  7233. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  7234. {
  7235. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7236. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7237. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7238. return shapeBlock;
  7239. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  7240. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  7241. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  7242. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  7243. {
  7244. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  7245. }
  7246. shapeBlock.PathCurve = pathcurve;
  7247. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  7248. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  7249. if (cut.x < 0f)
  7250. {
  7251. cut.x = 0f;
  7252. }
  7253. else if (cut.x > 1f)
  7254. {
  7255. cut.x = 1f;
  7256. }
  7257. if (cut.y < 0f)
  7258. {
  7259. cut.y = 0f;
  7260. }
  7261. else if (cut.y > 1f)
  7262. {
  7263. cut.y = 1f;
  7264. }
  7265. if (cut.y - cut.x < 0.02f)
  7266. {
  7267. cut.x = cut.y - 0.02f;
  7268. if (cut.x < 0.0f)
  7269. {
  7270. cut.x = 0.0f;
  7271. cut.y = 0.02f;
  7272. }
  7273. }
  7274. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  7275. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  7276. if (hollow < 0f)
  7277. {
  7278. hollow = 0f;
  7279. }
  7280. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  7281. // Box or Tube) and the hole shape is a square, hollow is limited to
  7282. // a max of 70%. The viewer performs its own check on this value but
  7283. // we need to do it here also so llGetPrimitiveParams can have access
  7284. // to the correct value.
  7285. if (profileshape != (byte)ProfileCurve.Square &&
  7286. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  7287. {
  7288. if (hollow > 0.70f)
  7289. {
  7290. hollow = 0.70f;
  7291. }
  7292. }
  7293. // Otherwise, hollow is limited to 99%.
  7294. else
  7295. {
  7296. if (hollow > 0.99f)
  7297. {
  7298. hollow = 0.99f;
  7299. }
  7300. }
  7301. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  7302. if (twist.x < -1.0f)
  7303. {
  7304. twist.x = -1.0f;
  7305. }
  7306. else if (twist.x > 1.0f)
  7307. {
  7308. twist.x = 1.0f;
  7309. }
  7310. if (twist.y < -1.0f)
  7311. {
  7312. twist.y = -1.0f;
  7313. }
  7314. else if (twist.y > 1.0f)
  7315. {
  7316. twist.y = 1.0f;
  7317. }
  7318. tempFloat = 100.0f * (float)twist.x;
  7319. if (tempFloat >= 0)
  7320. tempFloat += 0.5f;
  7321. else
  7322. tempFloat -= 0.5f;
  7323. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  7324. tempFloat = 100.0f * (float)twist.y;
  7325. if (tempFloat >= 0)
  7326. tempFloat += 0.5f;
  7327. else
  7328. tempFloat -= 0.5f;
  7329. shapeBlock.PathTwist = (sbyte)tempFloat;
  7330. shapeBlock.ObjectLocalID = part.LocalId;
  7331. part.Shape.SculptEntry = false;
  7332. return shapeBlock;
  7333. }
  7334. // Prim type box, cylinder and prism.
  7335. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve)
  7336. {
  7337. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7338. return;
  7339. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7340. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7341. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7342. if (taper_b.x < 0f)
  7343. {
  7344. taper_b.x = 0f;
  7345. }
  7346. else if (taper_b.x > 2f)
  7347. {
  7348. taper_b.x = 2f;
  7349. }
  7350. if (taper_b.y < 0f)
  7351. {
  7352. taper_b.y = 0f;
  7353. }
  7354. else if (taper_b.y > 2f)
  7355. {
  7356. taper_b.y = 2f;
  7357. }
  7358. tempFloat = 100.0f * (2.0f - (float)taper_b.x);
  7359. if (tempFloat >= 0)
  7360. tempFloat += 0.5f;
  7361. else
  7362. tempFloat -= 0.5f;
  7363. shapeBlock.PathScaleX = (byte)tempFloat;
  7364. tempFloat = 100.0f * (2.0f - (float)taper_b.y);
  7365. if (tempFloat >= 0)
  7366. tempFloat += 0.5f;
  7367. else
  7368. tempFloat -= 0.5f;
  7369. shapeBlock.PathScaleY = (byte)tempFloat;
  7370. if (topshear.x < -0.5f)
  7371. {
  7372. topshear.x = -0.5f;
  7373. }
  7374. else if (topshear.x > 0.5f)
  7375. {
  7376. topshear.x = 0.5f;
  7377. }
  7378. if (topshear.y < -0.5f)
  7379. {
  7380. topshear.y = -0.5f;
  7381. }
  7382. else if (topshear.y > 0.5f)
  7383. {
  7384. topshear.y = 0.5f;
  7385. }
  7386. tempFloat = 100.0f * (float)topshear.x;
  7387. if (tempFloat >= 0)
  7388. tempFloat += 0.5f;
  7389. else
  7390. tempFloat -= 0.5f;
  7391. shapeBlock.PathShearX = (byte)tempFloat;
  7392. tempFloat = 100.0f * (float)topshear.y;
  7393. if (tempFloat >= 0)
  7394. tempFloat += 0.5f;
  7395. else
  7396. tempFloat -= 0.5f;
  7397. shapeBlock.PathShearY = (byte)tempFloat;
  7398. part.Shape.SculptEntry = false;
  7399. part.UpdateShape(shapeBlock);
  7400. }
  7401. // Prim type sphere.
  7402. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  7403. {
  7404. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7405. return;
  7406. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7407. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7408. // profile/path swapped for a sphere
  7409. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7410. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7411. shapeBlock.PathScaleX = 100;
  7412. shapeBlock.PathScaleY = 100;
  7413. if (dimple.x < 0f)
  7414. {
  7415. dimple.x = 0f;
  7416. }
  7417. else if (dimple.x > 1f)
  7418. {
  7419. dimple.x = 1f;
  7420. }
  7421. if (dimple.y < 0f)
  7422. {
  7423. dimple.y = 0f;
  7424. }
  7425. else if (dimple.y > 1f)
  7426. {
  7427. dimple.y = 1f;
  7428. }
  7429. if (dimple.y - dimple.x < 0.02f)
  7430. {
  7431. dimple.x = dimple.y - 0.02f;
  7432. if (dimple.x < 0.0f)
  7433. {
  7434. dimple.x = 0.0f;
  7435. dimple.y = 0.02f;
  7436. }
  7437. }
  7438. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  7439. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  7440. part.Shape.SculptEntry = false;
  7441. part.UpdateShape(shapeBlock);
  7442. }
  7443. // Prim type torus, tube and ring.
  7444. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte profileshape, byte pathcurve)
  7445. {
  7446. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7447. return;
  7448. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7449. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7450. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7451. // profile/path swapped for a torrus, tube, ring
  7452. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7453. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7454. if (holesize.x < 0.01f)
  7455. {
  7456. holesize.x = 0.01f;
  7457. }
  7458. else if (holesize.x > 1f)
  7459. {
  7460. holesize.x = 1f;
  7461. }
  7462. tempFloat = 100.0f * (2.0f - (float)holesize.x) + 0.5f;
  7463. shapeBlock.PathScaleX = (byte)tempFloat;
  7464. if (holesize.y < 0.01f)
  7465. {
  7466. holesize.y = 0.01f;
  7467. }
  7468. else if (holesize.y > 0.5f)
  7469. {
  7470. holesize.y = 0.5f;
  7471. }
  7472. tempFloat = 100.0f * (2.0f - (float)holesize.y) + 0.5f;
  7473. shapeBlock.PathScaleY = (byte)tempFloat;
  7474. if (topshear.x < -0.5f)
  7475. {
  7476. topshear.x = -0.5f;
  7477. }
  7478. else if (topshear.x > 0.5f)
  7479. {
  7480. topshear.x = 0.5f;
  7481. }
  7482. tempFloat = (float)(100.0d * topshear.x);
  7483. if (tempFloat >= 0)
  7484. tempFloat += 0.5f;
  7485. else
  7486. tempFloat -= 0.5f;
  7487. shapeBlock.PathShearX = (byte)tempFloat;
  7488. if (topshear.y < -0.5f)
  7489. {
  7490. topshear.y = -0.5f;
  7491. }
  7492. else if (topshear.y > 0.5f)
  7493. {
  7494. topshear.y = 0.5f;
  7495. }
  7496. tempFloat = (float)(100.0d * topshear.y);
  7497. if (tempFloat >= 0)
  7498. tempFloat += 0.5f;
  7499. else
  7500. tempFloat -= 0.5f;
  7501. shapeBlock.PathShearY = (byte)tempFloat;
  7502. if (profilecut.x < 0f)
  7503. {
  7504. profilecut.x = 0f;
  7505. }
  7506. else if (profilecut.x > 1f)
  7507. {
  7508. profilecut.x = 1f;
  7509. }
  7510. if (profilecut.y < 0f)
  7511. {
  7512. profilecut.y = 0f;
  7513. }
  7514. else if (profilecut.y > 1f)
  7515. {
  7516. profilecut.y = 1f;
  7517. }
  7518. if (profilecut.y - profilecut.x < 0.02f)
  7519. {
  7520. profilecut.x = profilecut.y - 0.02f;
  7521. if (profilecut.x < 0.0f)
  7522. {
  7523. profilecut.x = 0.0f;
  7524. profilecut.y = 0.02f;
  7525. }
  7526. }
  7527. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  7528. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  7529. if (taper_a.x < -1f)
  7530. {
  7531. taper_a.x = -1f;
  7532. }
  7533. if (taper_a.x > 1f)
  7534. {
  7535. taper_a.x = 1f;
  7536. }
  7537. tempFloat = 100.0f * (float)taper_a.x;
  7538. if (tempFloat >= 0)
  7539. tempFloat += 0.5f;
  7540. else
  7541. tempFloat -= 0.5f;
  7542. shapeBlock.PathTaperX = (sbyte)tempFloat;
  7543. if (taper_a.y < -1f)
  7544. {
  7545. taper_a.y = -1f;
  7546. }
  7547. else if (taper_a.y > 1f)
  7548. {
  7549. taper_a.y = 1f;
  7550. }
  7551. tempFloat = 100.0f * (float)taper_a.y;
  7552. if (tempFloat >= 0)
  7553. tempFloat += 0.5f;
  7554. else
  7555. tempFloat -= 0.5f;
  7556. shapeBlock.PathTaperY = (sbyte)tempFloat;
  7557. if (revolutions < 1f)
  7558. {
  7559. revolutions = 1f;
  7560. }
  7561. if (revolutions > 4f)
  7562. {
  7563. revolutions = 4f;
  7564. }
  7565. tempFloat = 66.66667f * (revolutions - 1.0f) + 0.5f;
  7566. shapeBlock.PathRevolutions = (byte)tempFloat;
  7567. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  7568. if (radiusoffset < 0f)
  7569. {
  7570. radiusoffset = 0f;
  7571. }
  7572. if (radiusoffset > 1f)
  7573. {
  7574. radiusoffset = 1f;
  7575. }
  7576. tempFloat = 100.0f * radiusoffset + 0.5f;
  7577. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  7578. if (skew < -0.95f)
  7579. {
  7580. skew = -0.95f;
  7581. }
  7582. if (skew > 0.95f)
  7583. {
  7584. skew = 0.95f;
  7585. }
  7586. tempFloat = 100.0f * skew;
  7587. if (tempFloat >= 0)
  7588. tempFloat += 0.5f;
  7589. else
  7590. tempFloat -= 0.5f;
  7591. shapeBlock.PathSkew = (sbyte)tempFloat;
  7592. part.Shape.SculptEntry = false;
  7593. part.UpdateShape(shapeBlock);
  7594. }
  7595. // Prim type sculpt.
  7596. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  7597. {
  7598. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7599. return;
  7600. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7601. if (!UUID.TryParse(map, out UUID sculptId))
  7602. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  7603. if (sculptId == UUID.Zero)
  7604. return;
  7605. shapeBlock.PathCurve = pathcurve;
  7606. shapeBlock.ObjectLocalID = part.LocalId;
  7607. shapeBlock.PathScaleX = 100;
  7608. shapeBlock.PathScaleY = 150;
  7609. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  7610. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  7611. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  7612. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  7613. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  7614. {
  7615. // default
  7616. type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  7617. }
  7618. part.Shape.SetSculptProperties((byte)type, sculptId);
  7619. part.Shape.SculptEntry = true;
  7620. part.UpdateShape(shapeBlock);
  7621. }
  7622. public void llSetPrimitiveParams(LSL_List rules)
  7623. {
  7624. m_host.AddScriptLPS(1);
  7625. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  7626. ScriptSleep(m_sleepMsOnSetPrimitiveParams);
  7627. }
  7628. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7629. {
  7630. m_host.AddScriptLPS(1);
  7631. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  7632. ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
  7633. }
  7634. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  7635. {
  7636. m_host.AddScriptLPS(1);
  7637. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  7638. }
  7639. private void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  7640. {
  7641. List<object> parts = new List<object>();
  7642. List<SceneObjectPart> prims = GetLinkParts(linknumber);
  7643. List<ScenePresence> avatars = GetLinkAvatars(linknumber);
  7644. foreach (SceneObjectPart p in prims)
  7645. parts.Add(p);
  7646. foreach (ScenePresence p in avatars)
  7647. parts.Add(p);
  7648. LSL_List remaining = new LSL_List();
  7649. uint rulesParsed = 0;
  7650. if (parts.Count > 0)
  7651. {
  7652. foreach (object part in parts)
  7653. {
  7654. if (part is SceneObjectPart)
  7655. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7656. else
  7657. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7658. }
  7659. while (remaining.Length > 2)
  7660. {
  7661. linknumber = remaining.GetLSLIntegerItem(0);
  7662. rules = remaining.GetSublist(1, -1);
  7663. parts.Clear();
  7664. prims = GetLinkParts(linknumber);
  7665. avatars = GetLinkAvatars(linknumber);
  7666. foreach (SceneObjectPart p in prims)
  7667. parts.Add(p);
  7668. foreach (ScenePresence p in avatars)
  7669. parts.Add(p);
  7670. remaining = new LSL_List();
  7671. foreach (object part in parts)
  7672. {
  7673. if (part is SceneObjectPart)
  7674. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7675. else
  7676. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7677. }
  7678. }
  7679. }
  7680. }
  7681. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  7682. {
  7683. SceneObjectGroup group = m_host.ParentGroup;
  7684. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  7685. return;
  7686. if (group.IsAttachment)
  7687. return;
  7688. if (frames.Data.Length > 0) // We are getting a new motion
  7689. {
  7690. if (group.RootPart.KeyframeMotion != null)
  7691. group.RootPart.KeyframeMotion.Delete();
  7692. group.RootPart.KeyframeMotion = null;
  7693. int idx = 0;
  7694. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  7695. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  7696. while (idx < options.Data.Length)
  7697. {
  7698. int option = (int)options.GetLSLIntegerItem(idx++);
  7699. int remain = options.Data.Length - idx;
  7700. switch (option)
  7701. {
  7702. case ScriptBaseClass.KFM_MODE:
  7703. if (remain < 1)
  7704. break;
  7705. int modeval = (int)options.GetLSLIntegerItem(idx++);
  7706. switch(modeval)
  7707. {
  7708. case ScriptBaseClass.KFM_FORWARD:
  7709. mode = KeyframeMotion.PlayMode.Forward;
  7710. break;
  7711. case ScriptBaseClass.KFM_REVERSE:
  7712. mode = KeyframeMotion.PlayMode.Reverse;
  7713. break;
  7714. case ScriptBaseClass.KFM_LOOP:
  7715. mode = KeyframeMotion.PlayMode.Loop;
  7716. break;
  7717. case ScriptBaseClass.KFM_PING_PONG:
  7718. mode = KeyframeMotion.PlayMode.PingPong;
  7719. break;
  7720. }
  7721. break;
  7722. case ScriptBaseClass.KFM_DATA:
  7723. if (remain < 1)
  7724. break;
  7725. int dataval = (int)options.GetLSLIntegerItem(idx++);
  7726. data = (KeyframeMotion.DataFormat)dataval;
  7727. break;
  7728. }
  7729. }
  7730. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  7731. idx = 0;
  7732. int elemLength = 2;
  7733. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  7734. elemLength = 3;
  7735. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  7736. bool hasTranslation = (data & KeyframeMotion.DataFormat.Translation) != 0;
  7737. bool hasRotation = (data & KeyframeMotion.DataFormat.Rotation) != 0;
  7738. while (idx < frames.Data.Length)
  7739. {
  7740. int remain = frames.Data.Length - idx;
  7741. if (remain < elemLength)
  7742. break;
  7743. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe
  7744. {
  7745. Position = null,
  7746. Rotation = null
  7747. };
  7748. if (hasTranslation)
  7749. {
  7750. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  7751. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  7752. }
  7753. if (hasRotation)
  7754. {
  7755. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  7756. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  7757. frame.Rotation = q;
  7758. }
  7759. float tempf = (float)frames.GetLSLFloatItem(idx++);
  7760. frame.TimeMS = (int)(tempf * 1000.0f);
  7761. keyframes.Add(frame);
  7762. }
  7763. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  7764. group.RootPart.KeyframeMotion.Start();
  7765. }
  7766. else
  7767. {
  7768. if (group.RootPart.KeyframeMotion == null)
  7769. return;
  7770. if (options.Data.Length == 0)
  7771. {
  7772. group.RootPart.KeyframeMotion.Stop();
  7773. return;
  7774. }
  7775. int idx = 0;
  7776. while (idx < options.Data.Length)
  7777. {
  7778. int option = (int)options.GetLSLIntegerItem(idx++);
  7779. switch (option)
  7780. {
  7781. case ScriptBaseClass.KFM_COMMAND:
  7782. int cmd = (int)options.GetLSLIntegerItem(idx++);
  7783. switch (cmd)
  7784. {
  7785. case ScriptBaseClass.KFM_CMD_PLAY:
  7786. group.RootPart.KeyframeMotion.Start();
  7787. break;
  7788. case ScriptBaseClass.KFM_CMD_STOP:
  7789. group.RootPart.KeyframeMotion.Stop();
  7790. break;
  7791. case ScriptBaseClass.KFM_CMD_PAUSE:
  7792. group.RootPart.KeyframeMotion.Pause();
  7793. break;
  7794. }
  7795. break;
  7796. }
  7797. }
  7798. }
  7799. }
  7800. public LSL_List llGetPhysicsMaterial()
  7801. {
  7802. LSL_List result = new LSL_List();
  7803. result.Add(new LSL_Float(m_host.GravityModifier));
  7804. result.Add(new LSL_Float(m_host.Restitution));
  7805. result.Add(new LSL_Float(m_host.Friction));
  7806. result.Add(new LSL_Float(m_host.Density));
  7807. return result;
  7808. }
  7809. private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
  7810. float material_density, float material_friction,
  7811. float material_restitution, float material_gravity_modifier)
  7812. {
  7813. ExtraPhysicsData physdata = new ExtraPhysicsData
  7814. {
  7815. PhysShapeType = (PhysShapeType)part.PhysicsShapeType,
  7816. Density = part.Density,
  7817. Friction = part.Friction,
  7818. Bounce = part.Restitution,
  7819. GravitationModifier = part.GravityModifier
  7820. };
  7821. if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
  7822. physdata.Density = material_density;
  7823. if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
  7824. physdata.Friction = material_friction;
  7825. if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
  7826. physdata.Bounce = material_restitution;
  7827. if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
  7828. physdata.GravitationModifier = material_gravity_modifier;
  7829. part.UpdateExtraPhysics(physdata);
  7830. }
  7831. public void llSetPhysicsMaterial(int material_bits,
  7832. LSL_Float material_gravity_modifier, LSL_Float material_restitution,
  7833. LSL_Float material_friction, LSL_Float material_density)
  7834. {
  7835. SetPhysicsMaterial(m_host, material_bits, (float)material_density, (float)material_friction, (float)material_restitution, (float)material_gravity_modifier);
  7836. }
  7837. // vector up using libomv (c&p from sop )
  7838. // vector up rotated by r
  7839. private Vector3 Zrot(Quaternion r)
  7840. {
  7841. double x, y, z, m;
  7842. m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7843. if (Math.Abs(1.0 - m) > 0.000001)
  7844. {
  7845. m = 1.0 / Math.Sqrt(m);
  7846. r.X *= (float)m;
  7847. r.Y *= (float)m;
  7848. r.Z *= (float)m;
  7849. r.W *= (float)m;
  7850. }
  7851. x = 2 * (r.X * r.Z + r.Y * r.W);
  7852. y = 2 * (-r.X * r.W + r.Y * r.Z);
  7853. z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7854. return new Vector3((float)x, (float)y, (float)z);
  7855. }
  7856. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  7857. {
  7858. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7859. return new LSL_List();
  7860. int idx = 0;
  7861. int idxStart = 0;
  7862. SceneObjectGroup parentgrp = part.ParentGroup;
  7863. bool positionChanged = false;
  7864. bool materialChanged = false;
  7865. LSL_Vector currentPosition = GetPartLocalPos(part);
  7866. try
  7867. {
  7868. while (idx < rules.Length)
  7869. {
  7870. ++rulesParsed;
  7871. int code = rules.GetLSLIntegerItem(idx++);
  7872. int remain = rules.Length - idx;
  7873. idxStart = idx;
  7874. int face;
  7875. LSL_Vector v;
  7876. switch (code)
  7877. {
  7878. case ScriptBaseClass.PRIM_POSITION:
  7879. case ScriptBaseClass.PRIM_POS_LOCAL:
  7880. if (remain < 1)
  7881. return new LSL_List();
  7882. try
  7883. {
  7884. v = rules.GetVector3Item(idx++);
  7885. }
  7886. catch(InvalidCastException)
  7887. {
  7888. if(code == ScriptBaseClass.PRIM_POSITION)
  7889. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7890. else
  7891. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7892. return new LSL_List();
  7893. }
  7894. if (part.IsRoot && !part.ParentGroup.IsAttachment)
  7895. currentPosition = GetSetPosTarget(part, v, currentPosition, true);
  7896. else
  7897. currentPosition = GetSetPosTarget(part, v, currentPosition, false);
  7898. positionChanged = true;
  7899. break;
  7900. case ScriptBaseClass.PRIM_SIZE:
  7901. if (remain < 1)
  7902. return new LSL_List();
  7903. v=rules.GetVector3Item(idx++);
  7904. SetScale(part, v);
  7905. break;
  7906. case ScriptBaseClass.PRIM_ROTATION:
  7907. if (remain < 1)
  7908. return new LSL_List();
  7909. LSL_Rotation q;
  7910. try
  7911. {
  7912. q = rules.GetQuaternionItem(idx++);
  7913. }
  7914. catch(InvalidCastException)
  7915. {
  7916. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
  7917. return new LSL_List();
  7918. }
  7919. // try to let this work as in SL...
  7920. if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
  7921. {
  7922. // special case: If we are root, rotate complete SOG to new rotation
  7923. SetRot(part, q);
  7924. }
  7925. else
  7926. {
  7927. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  7928. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  7929. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  7930. }
  7931. break;
  7932. case ScriptBaseClass.PRIM_TYPE:
  7933. if (remain < 3)
  7934. return new LSL_List();
  7935. try
  7936. {
  7937. code = (int)rules.GetLSLIntegerItem(idx++);
  7938. }
  7939. catch(InvalidCastException)
  7940. {
  7941. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  7942. return new LSL_List();
  7943. }
  7944. remain = rules.Length - idx;
  7945. float hollow;
  7946. LSL_Vector twist;
  7947. LSL_Vector taper_b;
  7948. LSL_Vector topshear;
  7949. float revolutions;
  7950. float radiusoffset;
  7951. float skew;
  7952. LSL_Vector holesize;
  7953. LSL_Vector profilecut;
  7954. switch (code)
  7955. {
  7956. case ScriptBaseClass.PRIM_TYPE_BOX:
  7957. if (remain < 6)
  7958. return new LSL_List();
  7959. try
  7960. {
  7961. face = (int)rules.GetLSLIntegerItem(idx++);
  7962. }
  7963. catch(InvalidCastException)
  7964. {
  7965. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7966. return new LSL_List();
  7967. }
  7968. try
  7969. {
  7970. v = rules.GetVector3Item(idx++); // cut
  7971. }
  7972. catch(InvalidCastException)
  7973. {
  7974. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7975. return new LSL_List();
  7976. }
  7977. try
  7978. {
  7979. hollow = (float)rules.GetLSLFloatItem(idx++);
  7980. }
  7981. catch(InvalidCastException)
  7982. {
  7983. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7984. return new LSL_List();
  7985. }
  7986. try
  7987. {
  7988. twist = rules.GetVector3Item(idx++);
  7989. }
  7990. catch(InvalidCastException)
  7991. {
  7992. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
  7993. return new LSL_List();
  7994. }
  7995. try
  7996. {
  7997. taper_b = rules.GetVector3Item(idx++);
  7998. }
  7999. catch(InvalidCastException)
  8000. {
  8001. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8002. return new LSL_List();
  8003. }
  8004. try
  8005. {
  8006. topshear = rules.GetVector3Item(idx++);
  8007. }
  8008. catch(InvalidCastException)
  8009. {
  8010. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8011. return new LSL_List();
  8012. }
  8013. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8014. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  8015. break;
  8016. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  8017. if (remain < 6)
  8018. return new LSL_List();
  8019. try
  8020. {
  8021. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8022. }
  8023. catch(InvalidCastException)
  8024. {
  8025. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8026. return new LSL_List();
  8027. }
  8028. try
  8029. {
  8030. v = rules.GetVector3Item(idx++); // cut
  8031. }
  8032. catch(InvalidCastException)
  8033. {
  8034. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8035. return new LSL_List();
  8036. }
  8037. try
  8038. {
  8039. hollow = (float)rules.GetLSLFloatItem(idx++);
  8040. }
  8041. catch(InvalidCastException)
  8042. {
  8043. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8044. return new LSL_List();
  8045. }
  8046. try
  8047. {
  8048. twist = rules.GetVector3Item(idx++);
  8049. }
  8050. catch(InvalidCastException)
  8051. {
  8052. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8053. return new LSL_List();
  8054. }
  8055. try
  8056. {
  8057. taper_b = rules.GetVector3Item(idx++);
  8058. }
  8059. catch(InvalidCastException)
  8060. {
  8061. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8062. return new LSL_List();
  8063. }
  8064. try
  8065. {
  8066. topshear = rules.GetVector3Item(idx++);
  8067. }
  8068. catch(InvalidCastException)
  8069. {
  8070. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8071. return new LSL_List();
  8072. }
  8073. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8074. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  8075. break;
  8076. case ScriptBaseClass.PRIM_TYPE_PRISM:
  8077. if (remain < 6)
  8078. return new LSL_List();
  8079. try
  8080. {
  8081. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8082. }
  8083. catch(InvalidCastException)
  8084. {
  8085. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8086. return new LSL_List();
  8087. }
  8088. try
  8089. {
  8090. v = rules.GetVector3Item(idx++); //cut
  8091. }
  8092. catch(InvalidCastException)
  8093. {
  8094. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8095. return new LSL_List();
  8096. }
  8097. try
  8098. {
  8099. hollow = (float)rules.GetLSLFloatItem(idx++);
  8100. }
  8101. catch(InvalidCastException)
  8102. {
  8103. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8104. return new LSL_List();
  8105. }
  8106. try
  8107. {
  8108. twist = rules.GetVector3Item(idx++);
  8109. }
  8110. catch(InvalidCastException)
  8111. {
  8112. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8113. return new LSL_List();
  8114. }
  8115. try
  8116. {
  8117. taper_b = rules.GetVector3Item(idx++);
  8118. }
  8119. catch(InvalidCastException)
  8120. {
  8121. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8122. return new LSL_List();
  8123. }
  8124. try
  8125. {
  8126. topshear = rules.GetVector3Item(idx++);
  8127. }
  8128. catch(InvalidCastException)
  8129. {
  8130. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8131. return new LSL_List();
  8132. }
  8133. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8134. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  8135. break;
  8136. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  8137. if (remain < 5)
  8138. return new LSL_List();
  8139. try
  8140. {
  8141. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8142. }
  8143. catch(InvalidCastException)
  8144. {
  8145. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8146. return new LSL_List();
  8147. }
  8148. try
  8149. {
  8150. v = rules.GetVector3Item(idx++); // cut
  8151. }
  8152. catch(InvalidCastException)
  8153. {
  8154. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8155. return new LSL_List();
  8156. }
  8157. try
  8158. {
  8159. hollow = (float)rules.GetLSLFloatItem(idx++);
  8160. }
  8161. catch(InvalidCastException)
  8162. {
  8163. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8164. return new LSL_List();
  8165. }
  8166. try
  8167. {
  8168. twist = rules.GetVector3Item(idx++);
  8169. }
  8170. catch(InvalidCastException)
  8171. {
  8172. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8173. return new LSL_List();
  8174. }
  8175. try
  8176. {
  8177. taper_b = rules.GetVector3Item(idx++); // dimple
  8178. }
  8179. catch(InvalidCastException)
  8180. {
  8181. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8182. return new LSL_List();
  8183. }
  8184. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  8185. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  8186. break;
  8187. case ScriptBaseClass.PRIM_TYPE_TORUS:
  8188. if (remain < 11)
  8189. return new LSL_List();
  8190. try
  8191. {
  8192. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8193. }
  8194. catch(InvalidCastException)
  8195. {
  8196. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8197. return new LSL_List();
  8198. }
  8199. try
  8200. {
  8201. v = rules.GetVector3Item(idx++); //cut
  8202. }
  8203. catch(InvalidCastException)
  8204. {
  8205. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8206. return new LSL_List();
  8207. }
  8208. try
  8209. {
  8210. hollow = (float)rules.GetLSLFloatItem(idx++);
  8211. }
  8212. catch(InvalidCastException)
  8213. {
  8214. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8215. return new LSL_List();
  8216. }
  8217. try
  8218. {
  8219. twist = rules.GetVector3Item(idx++);
  8220. }
  8221. catch(InvalidCastException)
  8222. {
  8223. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8224. return new LSL_List();
  8225. }
  8226. try
  8227. {
  8228. holesize = rules.GetVector3Item(idx++);
  8229. }
  8230. catch(InvalidCastException)
  8231. {
  8232. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8233. return new LSL_List();
  8234. }
  8235. try
  8236. {
  8237. topshear = rules.GetVector3Item(idx++);
  8238. }
  8239. catch(InvalidCastException)
  8240. {
  8241. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8242. return new LSL_List();
  8243. }
  8244. try
  8245. {
  8246. profilecut = rules.GetVector3Item(idx++);
  8247. }
  8248. catch(InvalidCastException)
  8249. {
  8250. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8251. return new LSL_List();
  8252. }
  8253. try
  8254. {
  8255. taper_b = rules.GetVector3Item(idx++); // taper_a
  8256. }
  8257. catch(InvalidCastException)
  8258. {
  8259. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8260. return new LSL_List();
  8261. }
  8262. try
  8263. {
  8264. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8265. }
  8266. catch(InvalidCastException)
  8267. {
  8268. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8269. return new LSL_List();
  8270. }
  8271. try
  8272. {
  8273. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8274. }
  8275. catch(InvalidCastException)
  8276. {
  8277. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8278. return new LSL_List();
  8279. }
  8280. try
  8281. {
  8282. skew = (float)rules.GetLSLFloatItem(idx++);
  8283. }
  8284. catch(InvalidCastException)
  8285. {
  8286. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
  8287. return new LSL_List();
  8288. }
  8289. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8290. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  8291. break;
  8292. case ScriptBaseClass.PRIM_TYPE_TUBE:
  8293. if (remain < 11)
  8294. return new LSL_List();
  8295. try
  8296. {
  8297. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8298. }
  8299. catch(InvalidCastException)
  8300. {
  8301. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8302. return new LSL_List();
  8303. }
  8304. try
  8305. {
  8306. v = rules.GetVector3Item(idx++); //cut
  8307. }
  8308. catch(InvalidCastException)
  8309. {
  8310. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8311. return new LSL_List();
  8312. }
  8313. try
  8314. {
  8315. hollow = (float)rules.GetLSLFloatItem(idx++);
  8316. }
  8317. catch(InvalidCastException)
  8318. {
  8319. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8320. return new LSL_List();
  8321. }
  8322. try
  8323. {
  8324. twist = rules.GetVector3Item(idx++);
  8325. }
  8326. catch(InvalidCastException)
  8327. {
  8328. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8329. return new LSL_List();
  8330. }
  8331. try
  8332. {
  8333. holesize = rules.GetVector3Item(idx++);
  8334. }
  8335. catch(InvalidCastException)
  8336. {
  8337. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8338. return new LSL_List();
  8339. }
  8340. try
  8341. {
  8342. topshear = rules.GetVector3Item(idx++);
  8343. }
  8344. catch(InvalidCastException)
  8345. {
  8346. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8347. return new LSL_List();
  8348. }
  8349. try
  8350. {
  8351. profilecut = rules.GetVector3Item(idx++);
  8352. }
  8353. catch(InvalidCastException)
  8354. {
  8355. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8356. return new LSL_List();
  8357. }
  8358. try
  8359. {
  8360. taper_b = rules.GetVector3Item(idx++); // taper_a
  8361. }
  8362. catch(InvalidCastException)
  8363. {
  8364. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8365. return new LSL_List();
  8366. }
  8367. try
  8368. {
  8369. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8370. }
  8371. catch(InvalidCastException)
  8372. {
  8373. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8374. return new LSL_List();
  8375. }
  8376. try
  8377. {
  8378. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8379. }
  8380. catch(InvalidCastException)
  8381. {
  8382. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8383. return new LSL_List();
  8384. }
  8385. try
  8386. {
  8387. skew = (float)rules.GetLSLFloatItem(idx++);
  8388. }
  8389. catch(InvalidCastException)
  8390. {
  8391. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8392. return new LSL_List();
  8393. }
  8394. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8395. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  8396. break;
  8397. case ScriptBaseClass.PRIM_TYPE_RING:
  8398. if (remain < 11)
  8399. return new LSL_List();
  8400. try
  8401. {
  8402. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8403. }
  8404. catch(InvalidCastException)
  8405. {
  8406. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8407. return new LSL_List();
  8408. }
  8409. try
  8410. {
  8411. v = rules.GetVector3Item(idx++); //cut
  8412. }
  8413. catch(InvalidCastException)
  8414. {
  8415. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8416. return new LSL_List();
  8417. }
  8418. try
  8419. {
  8420. hollow = (float)rules.GetLSLFloatItem(idx++);
  8421. }
  8422. catch(InvalidCastException)
  8423. {
  8424. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8425. return new LSL_List();
  8426. }
  8427. try
  8428. {
  8429. twist = rules.GetVector3Item(idx++);
  8430. }
  8431. catch(InvalidCastException)
  8432. {
  8433. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8434. return new LSL_List();
  8435. }
  8436. try
  8437. {
  8438. holesize = rules.GetVector3Item(idx++);
  8439. }
  8440. catch(InvalidCastException)
  8441. {
  8442. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8443. return new LSL_List();
  8444. }
  8445. try
  8446. {
  8447. topshear = rules.GetVector3Item(idx++);
  8448. }
  8449. catch(InvalidCastException)
  8450. {
  8451. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8452. return new LSL_List();
  8453. }
  8454. try
  8455. {
  8456. profilecut = rules.GetVector3Item(idx++);
  8457. }
  8458. catch(InvalidCastException)
  8459. {
  8460. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8461. return new LSL_List();
  8462. }
  8463. try
  8464. {
  8465. taper_b = rules.GetVector3Item(idx++); // taper_a
  8466. }
  8467. catch(InvalidCastException)
  8468. {
  8469. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8470. return new LSL_List();
  8471. }
  8472. try
  8473. {
  8474. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8475. }
  8476. catch(InvalidCastException)
  8477. {
  8478. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8479. return new LSL_List();
  8480. }
  8481. try
  8482. {
  8483. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8484. }
  8485. catch(InvalidCastException)
  8486. {
  8487. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8488. return new LSL_List();
  8489. }
  8490. try
  8491. {
  8492. skew = (float)rules.GetLSLFloatItem(idx++);
  8493. }
  8494. catch(InvalidCastException)
  8495. {
  8496. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8497. return new LSL_List();
  8498. }
  8499. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8500. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  8501. break;
  8502. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  8503. if (remain < 2)
  8504. return new LSL_List();
  8505. string map = rules.Data[idx++].ToString();
  8506. try
  8507. {
  8508. face = (int)rules.GetLSLIntegerItem(idx++); // type
  8509. }
  8510. catch(InvalidCastException)
  8511. {
  8512. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8513. return new LSL_List();
  8514. }
  8515. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  8516. break;
  8517. }
  8518. break;
  8519. case ScriptBaseClass.PRIM_TEXTURE:
  8520. if (remain < 5)
  8521. return new LSL_List();
  8522. face=(int)rules.GetLSLIntegerItem(idx++);
  8523. string tex;
  8524. LSL_Vector repeats;
  8525. LSL_Vector offsets;
  8526. double rotation;
  8527. tex = rules.Data[idx++].ToString();
  8528. try
  8529. {
  8530. repeats = rules.GetVector3Item(idx++);
  8531. }
  8532. catch(InvalidCastException)
  8533. {
  8534. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8535. return new LSL_List();
  8536. }
  8537. try
  8538. {
  8539. offsets = rules.GetVector3Item(idx++);
  8540. }
  8541. catch(InvalidCastException)
  8542. {
  8543. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8544. return new LSL_List();
  8545. }
  8546. try
  8547. {
  8548. rotation = (double)rules.GetLSLFloatItem(idx++);
  8549. }
  8550. catch(InvalidCastException)
  8551. {
  8552. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8553. return new LSL_List();
  8554. }
  8555. SetTextureParams(part, tex, repeats.x, repeats.y, offsets.x, offsets.y, rotation, face);
  8556. break;
  8557. case ScriptBaseClass.PRIM_COLOR:
  8558. if (remain < 3)
  8559. return new LSL_List();
  8560. LSL_Vector color;
  8561. double alpha;
  8562. try
  8563. {
  8564. face = (int)rules.GetLSLIntegerItem(idx++);
  8565. }
  8566. catch(InvalidCastException)
  8567. {
  8568. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8569. return new LSL_List();
  8570. }
  8571. try
  8572. {
  8573. color = rules.GetVector3Item(idx++);
  8574. }
  8575. catch(InvalidCastException)
  8576. {
  8577. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8578. return new LSL_List();
  8579. }
  8580. try
  8581. {
  8582. alpha = (double)rules.GetLSLFloatItem(idx++);
  8583. }
  8584. catch(InvalidCastException)
  8585. {
  8586. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8587. return new LSL_List();
  8588. }
  8589. part.SetFaceColorAlpha(face, color, alpha);
  8590. break;
  8591. case ScriptBaseClass.PRIM_FLEXIBLE:
  8592. if (remain < 7)
  8593. return new LSL_List();
  8594. bool flexi;
  8595. int softness;
  8596. float gravity;
  8597. float friction;
  8598. float wind;
  8599. float tension;
  8600. LSL_Vector force;
  8601. try
  8602. {
  8603. flexi = rules.GetLSLIntegerItem(idx++);
  8604. }
  8605. catch(InvalidCastException)
  8606. {
  8607. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8608. return new LSL_List();
  8609. }
  8610. try
  8611. {
  8612. softness = rules.GetLSLIntegerItem(idx++);
  8613. }
  8614. catch(InvalidCastException)
  8615. {
  8616. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8617. return new LSL_List();
  8618. }
  8619. try
  8620. {
  8621. gravity = (float)rules.GetLSLFloatItem(idx++);
  8622. }
  8623. catch(InvalidCastException)
  8624. {
  8625. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8626. return new LSL_List();
  8627. }
  8628. try
  8629. {
  8630. friction = (float)rules.GetLSLFloatItem(idx++);
  8631. }
  8632. catch(InvalidCastException)
  8633. {
  8634. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8635. return new LSL_List();
  8636. }
  8637. try
  8638. {
  8639. wind = (float)rules.GetLSLFloatItem(idx++);
  8640. }
  8641. catch(InvalidCastException)
  8642. {
  8643. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8644. return new LSL_List();
  8645. }
  8646. try
  8647. {
  8648. tension = (float)rules.GetLSLFloatItem(idx++);
  8649. }
  8650. catch(InvalidCastException)
  8651. {
  8652. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
  8653. return new LSL_List();
  8654. }
  8655. try
  8656. {
  8657. force = rules.GetVector3Item(idx++);
  8658. }
  8659. catch(InvalidCastException)
  8660. {
  8661. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8662. return new LSL_List();
  8663. }
  8664. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  8665. break;
  8666. case ScriptBaseClass.PRIM_POINT_LIGHT:
  8667. if (remain < 5)
  8668. return new LSL_List();
  8669. bool light;
  8670. LSL_Vector lightcolor;
  8671. float intensity;
  8672. float radius;
  8673. float falloff;
  8674. try
  8675. {
  8676. light = rules.GetLSLIntegerItem(idx++);
  8677. }
  8678. catch(InvalidCastException)
  8679. {
  8680. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8681. return new LSL_List();
  8682. }
  8683. try
  8684. {
  8685. lightcolor = rules.GetVector3Item(idx++);
  8686. }
  8687. catch(InvalidCastException)
  8688. {
  8689. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8690. return new LSL_List();
  8691. }
  8692. try
  8693. {
  8694. intensity = (float)rules.GetLSLFloatItem(idx++);
  8695. }
  8696. catch(InvalidCastException)
  8697. {
  8698. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8699. return new LSL_List();
  8700. }
  8701. try
  8702. {
  8703. radius = (float)rules.GetLSLFloatItem(idx++);
  8704. }
  8705. catch(InvalidCastException)
  8706. {
  8707. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8708. return new LSL_List();
  8709. }
  8710. try
  8711. {
  8712. falloff = (float)rules.GetLSLFloatItem(idx++);
  8713. }
  8714. catch(InvalidCastException)
  8715. {
  8716. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8717. return new LSL_List();
  8718. }
  8719. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  8720. break;
  8721. case ScriptBaseClass.PRIM_GLOW:
  8722. if (remain < 2)
  8723. return new LSL_List();
  8724. float glow;
  8725. try
  8726. {
  8727. face = rules.GetLSLIntegerItem(idx++);
  8728. }
  8729. catch(InvalidCastException)
  8730. {
  8731. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8732. return new LSL_List();
  8733. }
  8734. try
  8735. {
  8736. glow = (float)rules.GetLSLFloatItem(idx++);
  8737. }
  8738. catch(InvalidCastException)
  8739. {
  8740. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8741. return new LSL_List();
  8742. }
  8743. SetGlow(part, face, glow);
  8744. break;
  8745. case ScriptBaseClass.PRIM_BUMP_SHINY:
  8746. if (remain < 3)
  8747. return new LSL_List();
  8748. int shiny;
  8749. Bumpiness bump;
  8750. try
  8751. {
  8752. face = (int)rules.GetLSLIntegerItem(idx++);
  8753. }
  8754. catch(InvalidCastException)
  8755. {
  8756. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8757. return new LSL_List();
  8758. }
  8759. try
  8760. {
  8761. shiny = (int)rules.GetLSLIntegerItem(idx++);
  8762. }
  8763. catch(InvalidCastException)
  8764. {
  8765. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8766. return new LSL_List();
  8767. }
  8768. try
  8769. {
  8770. bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  8771. }
  8772. catch(InvalidCastException)
  8773. {
  8774. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8775. return new LSL_List();
  8776. }
  8777. SetShiny(part, face, shiny, bump);
  8778. break;
  8779. case ScriptBaseClass.PRIM_FULLBRIGHT:
  8780. if (remain < 2)
  8781. return new LSL_List();
  8782. bool st;
  8783. try
  8784. {
  8785. face = rules.GetLSLIntegerItem(idx++);
  8786. }
  8787. catch(InvalidCastException)
  8788. {
  8789. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8790. return new LSL_List();
  8791. }
  8792. try
  8793. {
  8794. st = rules.GetLSLIntegerItem(idx++);
  8795. }
  8796. catch(InvalidCastException)
  8797. {
  8798. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8799. return new LSL_List();
  8800. }
  8801. SetFullBright(part, face , st);
  8802. break;
  8803. case ScriptBaseClass.PRIM_MATERIAL:
  8804. if (remain < 1)
  8805. return new LSL_List();
  8806. int mat;
  8807. try
  8808. {
  8809. mat = rules.GetLSLIntegerItem(idx++);
  8810. }
  8811. catch(InvalidCastException)
  8812. {
  8813. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8814. return new LSL_List();
  8815. }
  8816. if (mat < 0 || mat > 7)
  8817. return new LSL_List();
  8818. part.Material = Convert.ToByte(mat);
  8819. break;
  8820. case ScriptBaseClass.PRIM_PHANTOM:
  8821. if (remain < 1)
  8822. return new LSL_List();
  8823. string ph = rules.Data[idx++].ToString();
  8824. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  8825. break;
  8826. case ScriptBaseClass.PRIM_PHYSICS:
  8827. if (remain < 1)
  8828. return new LSL_List();
  8829. string phy = rules.Data[idx++].ToString();
  8830. part.ScriptSetPhysicsStatus(phy.Equals("1"));
  8831. break;
  8832. case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  8833. if (remain < 1)
  8834. return new LSL_List();
  8835. int shape_type;
  8836. try
  8837. {
  8838. shape_type = rules.GetLSLIntegerItem(idx++);
  8839. }
  8840. catch(InvalidCastException)
  8841. {
  8842. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8843. return new LSL_List();
  8844. }
  8845. ExtraPhysicsData physdata = new ExtraPhysicsData
  8846. {
  8847. Density = part.Density,
  8848. Bounce = part.Restitution,
  8849. GravitationModifier = part.GravityModifier,
  8850. PhysShapeType = (PhysShapeType)shape_type
  8851. };
  8852. part.UpdateExtraPhysics(physdata);
  8853. break;
  8854. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  8855. if (remain < 5)
  8856. return new LSL_List();
  8857. int material_bits = rules.GetLSLIntegerItem(idx++);
  8858. float material_density = (float)rules.GetLSLFloatItem(idx++);
  8859. float material_friction = (float)rules.GetLSLFloatItem(idx++);
  8860. float material_restitution = (float)rules.GetLSLFloatItem(idx++);
  8861. float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
  8862. SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
  8863. break;
  8864. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  8865. if (remain < 1)
  8866. return new LSL_List();
  8867. string temp = rules.Data[idx++].ToString();
  8868. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  8869. break;
  8870. case ScriptBaseClass.PRIM_TEXGEN:
  8871. if (remain < 2)
  8872. return new LSL_List();
  8873. //face,type
  8874. int style;
  8875. try
  8876. {
  8877. face = rules.GetLSLIntegerItem(idx++);
  8878. }
  8879. catch(InvalidCastException)
  8880. {
  8881. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8882. return new LSL_List();
  8883. }
  8884. try
  8885. {
  8886. style = rules.GetLSLIntegerItem(idx++);
  8887. }
  8888. catch(InvalidCastException)
  8889. {
  8890. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8891. return new LSL_List();
  8892. }
  8893. SetTexGen(part, face, style);
  8894. break;
  8895. case ScriptBaseClass.PRIM_TEXT:
  8896. if (remain < 3)
  8897. return new LSL_List();
  8898. string primText;
  8899. LSL_Vector primTextColor;
  8900. LSL_Float primTextAlpha;
  8901. try
  8902. {
  8903. primText = rules.GetLSLStringItem(idx++);
  8904. }
  8905. catch(InvalidCastException)
  8906. {
  8907. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8908. return new LSL_List();
  8909. }
  8910. try
  8911. {
  8912. primTextColor = rules.GetVector3Item(idx++);
  8913. }
  8914. catch(InvalidCastException)
  8915. {
  8916. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8917. return new LSL_List();
  8918. }
  8919. try
  8920. {
  8921. primTextAlpha = rules.GetLSLFloatItem(idx++);
  8922. }
  8923. catch(InvalidCastException)
  8924. {
  8925. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8926. return new LSL_List();
  8927. }
  8928. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  8929. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  8930. break;
  8931. case ScriptBaseClass.PRIM_NAME:
  8932. if (remain < 1)
  8933. return new LSL_List();
  8934. try
  8935. {
  8936. string primName = rules.GetLSLStringItem(idx++);
  8937. part.Name = primName;
  8938. }
  8939. catch(InvalidCastException)
  8940. {
  8941. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8942. return new LSL_List();
  8943. }
  8944. break;
  8945. case ScriptBaseClass.PRIM_DESC:
  8946. if (remain < 1)
  8947. return new LSL_List();
  8948. try
  8949. {
  8950. string primDesc = rules.GetLSLStringItem(idx++);
  8951. part.Description = primDesc;
  8952. }
  8953. catch(InvalidCastException)
  8954. {
  8955. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8956. return new LSL_List();
  8957. }
  8958. break;
  8959. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8960. if (remain < 1)
  8961. return new LSL_List();
  8962. LSL_Rotation rot;
  8963. try
  8964. {
  8965. rot = rules.GetQuaternionItem(idx++);
  8966. }
  8967. catch(InvalidCastException)
  8968. {
  8969. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8970. return new LSL_List();
  8971. }
  8972. SetRot(part, rot);
  8973. break;
  8974. case ScriptBaseClass.PRIM_OMEGA:
  8975. if (remain < 3)
  8976. return new LSL_List();
  8977. LSL_Vector axis;
  8978. LSL_Float spinrate;
  8979. LSL_Float gain;
  8980. try
  8981. {
  8982. axis = rules.GetVector3Item(idx++);
  8983. }
  8984. catch(InvalidCastException)
  8985. {
  8986. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8987. return new LSL_List();
  8988. }
  8989. try
  8990. {
  8991. spinrate = rules.GetLSLFloatItem(idx++);
  8992. }
  8993. catch(InvalidCastException)
  8994. {
  8995. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8996. return new LSL_List();
  8997. }
  8998. try
  8999. {
  9000. gain = rules.GetLSLFloatItem(idx++);
  9001. }
  9002. catch(InvalidCastException)
  9003. {
  9004. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  9005. return new LSL_List();
  9006. }
  9007. TargetOmega(part, axis, (double)spinrate, (double)gain);
  9008. break;
  9009. case ScriptBaseClass.PRIM_SLICE:
  9010. if (remain < 1)
  9011. return new LSL_List();
  9012. LSL_Vector slice;
  9013. try
  9014. {
  9015. slice = rules.GetVector3Item(idx++);
  9016. }
  9017. catch(InvalidCastException)
  9018. {
  9019. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9020. return new LSL_List();
  9021. }
  9022. part.UpdateSlice((float)slice.x, (float)slice.y);
  9023. break;
  9024. case ScriptBaseClass.PRIM_SIT_TARGET:
  9025. if (remain < 3)
  9026. return new LSL_List();
  9027. int active;
  9028. try
  9029. {
  9030. active = rules.GetLSLIntegerItem(idx++);
  9031. }
  9032. catch(InvalidCastException)
  9033. {
  9034. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  9035. return new LSL_List();
  9036. }
  9037. LSL_Vector offset;
  9038. try
  9039. {
  9040. offset = rules.GetVector3Item(idx++);
  9041. }
  9042. catch(InvalidCastException)
  9043. {
  9044. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9045. return new LSL_List();
  9046. }
  9047. LSL_Rotation sitrot;
  9048. try
  9049. {
  9050. sitrot = rules.GetQuaternionItem(idx++);
  9051. }
  9052. catch(InvalidCastException)
  9053. {
  9054. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 3 must be rotation", rulesParsed, idx - idxStart - 1));
  9055. return new LSL_List();
  9056. }
  9057. // not SL compatible since we don't have a independent flag to control active target but use the values of offset and rotation
  9058. if(active == 1)
  9059. {
  9060. if(offset.x == 0 && offset.y == 0 && offset.z == 0 && sitrot.s == 1.0)
  9061. offset.z = 1e-5f; // hack
  9062. SitTarget(part,offset,sitrot);
  9063. }
  9064. else if(active == 0)
  9065. SitTarget(part, Vector3.Zero , Quaternion.Identity);
  9066. break;
  9067. case ScriptBaseClass.PRIM_ALPHA_MODE:
  9068. if (remain < 3)
  9069. return new LSL_List();
  9070. try
  9071. {
  9072. face = rules.GetLSLIntegerItem(idx++);
  9073. }
  9074. catch(InvalidCastException)
  9075. {
  9076. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9077. return new LSL_List();
  9078. }
  9079. int materialAlphaMode;
  9080. try
  9081. {
  9082. materialAlphaMode = rules.GetLSLIntegerItem(idx++);
  9083. }
  9084. catch(InvalidCastException)
  9085. {
  9086. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9087. return new LSL_List();
  9088. }
  9089. if(materialAlphaMode < 0 || materialAlphaMode > 3)
  9090. {
  9091. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 3", rulesParsed, idx - idxStart - 1));
  9092. return new LSL_List();
  9093. }
  9094. int materialMaskCutoff;
  9095. try
  9096. {
  9097. materialMaskCutoff = rules.GetLSLIntegerItem(idx++);
  9098. }
  9099. catch(InvalidCastException)
  9100. {
  9101. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9102. return new LSL_List();
  9103. }
  9104. if(materialMaskCutoff < 0 || materialMaskCutoff > 255)
  9105. {
  9106. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 255", rulesParsed, idx - idxStart - 1));
  9107. return new LSL_List();
  9108. }
  9109. materialChanged |= SetMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9110. break;
  9111. case ScriptBaseClass.PRIM_NORMAL:
  9112. if (remain < 5)
  9113. return new LSL_List();
  9114. try
  9115. {
  9116. face = rules.GetLSLIntegerItem(idx++);
  9117. }
  9118. catch(InvalidCastException)
  9119. {
  9120. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9121. return new LSL_List();
  9122. }
  9123. string mapname = rules.Data[idx++].ToString();
  9124. UUID mapID = UUID.Zero;
  9125. if (!string.IsNullOrEmpty(mapname))
  9126. {
  9127. mapID = ScriptUtils.GetAssetIdFromItemName(m_host, mapname, (int)AssetType.Texture);
  9128. if (mapID == UUID.Zero)
  9129. {
  9130. if (!UUID.TryParse(mapname, out mapID))
  9131. {
  9132. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be a UUID or a texture name on object inventory", rulesParsed, idx - idxStart - 1));
  9133. return new LSL_List();
  9134. }
  9135. }
  9136. }
  9137. LSL_Vector mnrepeat;
  9138. try
  9139. {
  9140. mnrepeat = rules.GetVector3Item(idx++);
  9141. }
  9142. catch(InvalidCastException)
  9143. {
  9144. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9145. return new LSL_List();
  9146. }
  9147. LSL_Vector mnoffset;
  9148. try
  9149. {
  9150. mnoffset = rules.GetVector3Item(idx++);
  9151. }
  9152. catch(InvalidCastException)
  9153. {
  9154. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9155. return new LSL_List();
  9156. }
  9157. LSL_Float mnrot;
  9158. try
  9159. {
  9160. mnrot = rules.GetLSLFloatItem(idx++);
  9161. }
  9162. catch(InvalidCastException)
  9163. {
  9164. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9165. return new LSL_List();
  9166. }
  9167. float repeatX = (float)Util.Clamp(mnrepeat.x,-100.0, 100.0);
  9168. float repeatY = (float)Util.Clamp(mnrepeat.y,-100.0, 100.0);
  9169. float offsetX = (float)Util.Clamp(mnoffset.x, 0, 1.0);
  9170. float offsetY = (float)Util.Clamp(mnoffset.y, 0, 1.0);
  9171. materialChanged |= SetMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, (float)mnrot);
  9172. break;
  9173. case ScriptBaseClass.PRIM_SPECULAR:
  9174. if (remain < 8)
  9175. return new LSL_List();
  9176. try
  9177. {
  9178. face = rules.GetLSLIntegerItem(idx++);
  9179. }
  9180. catch(InvalidCastException)
  9181. {
  9182. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9183. return new LSL_List();
  9184. }
  9185. string smapname = rules.Data[idx++].ToString();
  9186. UUID smapID = UUID.Zero;
  9187. if(!string.IsNullOrEmpty(smapname))
  9188. {
  9189. smapID = ScriptUtils.GetAssetIdFromItemName(m_host, smapname, (int)AssetType.Texture);
  9190. if (smapID == UUID.Zero)
  9191. {
  9192. if (!UUID.TryParse(smapname, out smapID))
  9193. {
  9194. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be a UUID or a texture name on object inventory", rulesParsed, idx - idxStart - 1));
  9195. return new LSL_List();
  9196. }
  9197. }
  9198. }
  9199. LSL_Vector msrepeat;
  9200. try
  9201. {
  9202. msrepeat = rules.GetVector3Item(idx++);
  9203. }
  9204. catch(InvalidCastException)
  9205. {
  9206. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9207. return new LSL_List();
  9208. }
  9209. LSL_Vector msoffset;
  9210. try
  9211. {
  9212. msoffset = rules.GetVector3Item(idx++);
  9213. }
  9214. catch(InvalidCastException)
  9215. {
  9216. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9217. return new LSL_List();
  9218. }
  9219. LSL_Float msrot;
  9220. try
  9221. {
  9222. msrot = rules.GetLSLFloatItem(idx++);
  9223. }
  9224. catch(InvalidCastException)
  9225. {
  9226. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9227. return new LSL_List();
  9228. }
  9229. LSL_Vector mscolor;
  9230. try
  9231. {
  9232. mscolor = rules.GetVector3Item(idx++);
  9233. }
  9234. catch(InvalidCastException)
  9235. {
  9236. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9237. return new LSL_List();
  9238. }
  9239. LSL_Integer msgloss;
  9240. try
  9241. {
  9242. msgloss = rules.GetLSLIntegerItem(idx++);
  9243. }
  9244. catch(InvalidCastException)
  9245. {
  9246. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9247. return new LSL_List();
  9248. }
  9249. LSL_Integer msenv;
  9250. try
  9251. {
  9252. msenv = rules.GetLSLIntegerItem(idx++);
  9253. }
  9254. catch(InvalidCastException)
  9255. {
  9256. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9257. return new LSL_List();
  9258. }
  9259. float srepeatX = (float)Util.Clamp(msrepeat.x, -100.0, 100.0);
  9260. float srepeatY = (float)Util.Clamp(msrepeat.y, -100.0, 100.0);
  9261. float soffsetX = (float)Util.Clamp(msoffset.x, -1.0, 1.0);
  9262. float soffsetY = (float)Util.Clamp(msoffset.y, -1.0, 1.0);
  9263. byte colorR = (byte)(255.0 * Util.Clamp(mscolor.x, 0, 1.0) + 0.5);
  9264. byte colorG = (byte)(255.0 * Util.Clamp(mscolor.y, 0, 1.0) + 0.5);
  9265. byte colorB = (byte)(255.0 * Util.Clamp(mscolor.z, 0, 1.0) + 0.5);
  9266. byte gloss = (byte)Util.Clamp((int)msgloss, 0, 255);
  9267. byte env = (byte)Util.Clamp((int)msenv, 0, 255);
  9268. materialChanged |= SetMaterialSpecMap(part, face, smapID, srepeatX, srepeatY, soffsetX, soffsetY,
  9269. (float)msrot, colorR, colorG, colorB, gloss, env);
  9270. break;
  9271. case ScriptBaseClass.PRIM_LINK_TARGET:
  9272. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9273. return new LSL_List();
  9274. return rules.GetSublist(idx, -1);
  9275. default:
  9276. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
  9277. return new LSL_List();
  9278. }
  9279. }
  9280. }
  9281. catch (InvalidCastException e)
  9282. {
  9283. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9284. }
  9285. finally
  9286. {
  9287. if (positionChanged)
  9288. {
  9289. if (part.ParentGroup.RootPart == part)
  9290. {
  9291. SceneObjectGroup parent = part.ParentGroup;
  9292. // Util.FireAndForget(delegate(object x) {
  9293. parent.UpdateGroupPosition(currentPosition);
  9294. // });
  9295. }
  9296. else
  9297. {
  9298. part.OffsetPosition = currentPosition;
  9299. // SceneObjectGroup parent = part.ParentGroup;
  9300. // parent.HasGroupChanged = true;
  9301. // parent.ScheduleGroupForTerseUpdate();
  9302. part.ScheduleTerseUpdate();
  9303. }
  9304. }
  9305. if(materialChanged)
  9306. {
  9307. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  9308. {
  9309. part.TriggerScriptChangedEvent(Changed.TEXTURE);
  9310. part.ScheduleFullUpdate();
  9311. part.ParentGroup.HasGroupChanged = true;
  9312. }
  9313. }
  9314. }
  9315. return new LSL_List();
  9316. }
  9317. protected bool SetMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9318. {
  9319. if(m_materialsModule == null)
  9320. return false;
  9321. int nsides = part.GetNumberOfSides();
  9322. if(face == ScriptBaseClass.ALL_SIDES)
  9323. {
  9324. bool changed = false;
  9325. for(int i = 0; i < nsides; i++)
  9326. changed |= SetFaceMaterialAlphaMode(part, i, materialAlphaMode, materialMaskCutoff);
  9327. return changed;
  9328. }
  9329. if( face >= 0 && face < nsides)
  9330. return SetFaceMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9331. return false;
  9332. }
  9333. protected bool SetFaceMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9334. {
  9335. Primitive.TextureEntry tex = part.Shape.Textures;
  9336. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9337. if(texface == null)
  9338. return false;
  9339. FaceMaterial mat = null;
  9340. UUID oldid = texface.MaterialID;
  9341. if (oldid == UUID.Zero)
  9342. {
  9343. if (materialAlphaMode == 1)
  9344. return false;
  9345. }
  9346. else
  9347. mat = m_materialsModule.GetMaterialCopy(oldid);
  9348. if(mat == null)
  9349. mat = new FaceMaterial();
  9350. mat.DiffuseAlphaMode = (byte)materialAlphaMode;
  9351. mat.AlphaMaskCutoff = (byte)materialMaskCutoff;
  9352. UUID id = m_materialsModule.AddNewMaterial(mat); // id is a hash of entire material hash, so this means no change
  9353. if(oldid == id)
  9354. return false;
  9355. texface.MaterialID = id;
  9356. part.Shape.TextureEntry = tex.GetBytes(9);
  9357. m_materialsModule.RemoveMaterial(oldid);
  9358. return true;
  9359. }
  9360. protected bool SetMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9361. float offsetX, float offsetY, float rot)
  9362. {
  9363. if(m_materialsModule == null)
  9364. return false;
  9365. int nsides = part.GetNumberOfSides();
  9366. if(face == ScriptBaseClass.ALL_SIDES)
  9367. {
  9368. bool changed = false;
  9369. for(int i = 0; i < nsides; i++)
  9370. changed |= SetFaceMaterialNormalMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9371. return changed;
  9372. }
  9373. if( face >= 0 && face < nsides)
  9374. return SetFaceMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9375. return false;
  9376. }
  9377. protected bool SetFaceMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9378. float offsetX, float offsetY, float rot)
  9379. {
  9380. Primitive.TextureEntry tex = part.Shape.Textures;
  9381. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9382. if(texface == null)
  9383. return false;
  9384. FaceMaterial mat = null;
  9385. UUID oldid = texface.MaterialID;
  9386. if (oldid == UUID.Zero)
  9387. {
  9388. if (mapID == UUID.Zero)
  9389. return false;
  9390. }
  9391. else
  9392. mat = m_materialsModule.GetMaterialCopy(oldid);
  9393. if(mat == null)
  9394. mat = new FaceMaterial();
  9395. mat.NormalMapID = mapID;
  9396. mat.NormalOffsetX = offsetX;
  9397. mat.NormalOffsetY = offsetY;
  9398. mat.NormalRepeatX = repeatX;
  9399. mat.NormalRepeatY = repeatY;
  9400. mat.NormalRotation = rot;
  9401. mapID = m_materialsModule.AddNewMaterial(mat);
  9402. if(oldid == mapID)
  9403. return false;
  9404. texface.MaterialID = mapID;
  9405. part.Shape.TextureEntry = tex.GetBytes(9);
  9406. m_materialsModule.RemoveMaterial(oldid);
  9407. return true;
  9408. }
  9409. protected bool SetMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9410. float offsetX, float offsetY, float rot,
  9411. byte colorR, byte colorG, byte colorB,
  9412. byte gloss, byte env)
  9413. {
  9414. if(m_materialsModule == null)
  9415. return false;
  9416. int nsides = part.GetNumberOfSides();
  9417. if(face == ScriptBaseClass.ALL_SIDES)
  9418. {
  9419. bool changed = false;
  9420. for(int i = 0; i < nsides; i++)
  9421. changed |= SetFaceMaterialSpecMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9422. colorR, colorG, colorB, gloss, env);
  9423. return changed;
  9424. }
  9425. if( face >= 0 && face < nsides)
  9426. return SetFaceMaterialSpecMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9427. colorR, colorG, colorB, gloss, env);
  9428. return false;
  9429. }
  9430. protected bool SetFaceMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9431. float offsetX, float offsetY, float rot,
  9432. byte colorR, byte colorG, byte colorB,
  9433. byte gloss, byte env)
  9434. {
  9435. Primitive.TextureEntry tex = part.Shape.Textures;
  9436. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9437. if(texface == null)
  9438. return false;
  9439. FaceMaterial mat = null;
  9440. UUID oldid = texface.MaterialID;
  9441. if(oldid == UUID.Zero)
  9442. {
  9443. if(mapID == UUID.Zero)
  9444. return false;
  9445. }
  9446. else
  9447. mat = m_materialsModule.GetMaterialCopy(oldid);
  9448. if (mat == null)
  9449. mat = new FaceMaterial();
  9450. mat.SpecularMapID = mapID;
  9451. mat.SpecularOffsetX = offsetX;
  9452. mat.SpecularOffsetY = offsetY;
  9453. mat.SpecularRepeatX = repeatX;
  9454. mat.SpecularRepeatY = repeatY;
  9455. mat.SpecularRotation = rot;
  9456. mat.SpecularLightColorR = colorR;
  9457. mat.SpecularLightColorG = colorG;
  9458. mat.SpecularLightColorB = colorB;
  9459. mat.SpecularLightExponent = gloss;
  9460. mat.EnvironmentIntensity = env;
  9461. mapID = m_materialsModule.AddNewMaterial(mat);
  9462. if(oldid == mapID)
  9463. return false;
  9464. texface.MaterialID = mapID;
  9465. part.Shape.TextureEntry = tex.GetBytes(9);
  9466. m_materialsModule.RemoveMaterial(oldid);
  9467. return true;
  9468. }
  9469. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  9470. {
  9471. int idx = 0;
  9472. int idxStart = 0;
  9473. try
  9474. {
  9475. while (idx < rules.Length)
  9476. {
  9477. ++rulesParsed;
  9478. int code = rules.GetLSLIntegerItem(idx++);
  9479. int remain = rules.Length - idx;
  9480. idxStart = idx;
  9481. switch (code)
  9482. {
  9483. case ScriptBaseClass.PRIM_POSITION:
  9484. case ScriptBaseClass.PRIM_POS_LOCAL:
  9485. if (remain < 1)
  9486. return new LSL_List();
  9487. try
  9488. {
  9489. sp.OffsetPosition = rules.GetVector3Item(idx++);
  9490. }
  9491. catch(InvalidCastException)
  9492. {
  9493. if (code == ScriptBaseClass.PRIM_POSITION)
  9494. {
  9495. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9496. }
  9497. else
  9498. {
  9499. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9500. }
  9501. return new LSL_List();
  9502. }
  9503. break;
  9504. case ScriptBaseClass.PRIM_ROTATION:
  9505. if (remain < 1)
  9506. return new LSL_List();
  9507. Quaternion inRot;
  9508. try
  9509. {
  9510. inRot = rules.GetQuaternionItem(idx++);
  9511. }
  9512. catch(InvalidCastException)
  9513. {
  9514. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9515. return new LSL_List();
  9516. }
  9517. SceneObjectPart parentPart = sp.ParentPart;
  9518. if (parentPart != null)
  9519. sp.Rotation = m_host.GetWorldRotation() * inRot;
  9520. break;
  9521. case ScriptBaseClass.PRIM_ROT_LOCAL:
  9522. if (remain < 1)
  9523. return new LSL_List();
  9524. try
  9525. {
  9526. sp.Rotation = rules.GetQuaternionItem(idx++);
  9527. }
  9528. catch(InvalidCastException)
  9529. {
  9530. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9531. return new LSL_List();
  9532. }
  9533. break;
  9534. case ScriptBaseClass.PRIM_TYPE:
  9535. Error(originFunc, "PRIM_TYPE disallowed on agent");
  9536. return new LSL_List();
  9537. case ScriptBaseClass.PRIM_OMEGA:
  9538. Error(originFunc, "PRIM_OMEGA disallowed on agent");
  9539. return new LSL_List();
  9540. case ScriptBaseClass.PRIM_LINK_TARGET:
  9541. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9542. return new LSL_List();
  9543. return rules.GetSublist(idx, -1);
  9544. default:
  9545. Error(originFunc,
  9546. string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
  9547. return new LSL_List();
  9548. }
  9549. }
  9550. }
  9551. catch (InvalidCastException e)
  9552. {
  9553. Error(
  9554. originFunc,
  9555. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9556. }
  9557. return new LSL_List();
  9558. }
  9559. public LSL_String llStringToBase64(string str)
  9560. {
  9561. m_host.AddScriptLPS(1);
  9562. try
  9563. {
  9564. byte[] encData_byte;
  9565. encData_byte = Util.UTF8.GetBytes(str);
  9566. string encodedData = Convert.ToBase64String(encData_byte);
  9567. return encodedData;
  9568. }
  9569. catch
  9570. {
  9571. Error("llBase64ToString", "Error encoding string");
  9572. return string.Empty;
  9573. }
  9574. }
  9575. public LSL_String llBase64ToString(string str)
  9576. {
  9577. m_host.AddScriptLPS(1);
  9578. try
  9579. {
  9580. byte[] b = Convert.FromBase64String(str);
  9581. return Encoding.UTF8.GetString(b);
  9582. }
  9583. catch
  9584. {
  9585. Error("llBase64ToString", "Error decoding string");
  9586. return string.Empty;
  9587. }
  9588. }
  9589. public void llRemoteDataSetRegion()
  9590. {
  9591. m_host.AddScriptLPS(1);
  9592. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  9593. }
  9594. public LSL_Float llLog10(double val)
  9595. {
  9596. m_host.AddScriptLPS(1);
  9597. return (double)Math.Log10(val);
  9598. }
  9599. public LSL_Float llLog(double val)
  9600. {
  9601. m_host.AddScriptLPS(1);
  9602. return (double)Math.Log(val);
  9603. }
  9604. public LSL_List llGetAnimationList(LSL_Key id)
  9605. {
  9606. m_host.AddScriptLPS(1);
  9607. if(!UUID.TryParse(id, out UUID avID))
  9608. return new LSL_List();
  9609. ScenePresence av = World.GetScenePresence(avID);
  9610. if (av == null || av.IsChildAgent) // only if in the region
  9611. return new LSL_List();
  9612. UUID[] anims;
  9613. anims = av.Animator.GetAnimationArray();
  9614. LSL_List l = new LSL_List();
  9615. foreach (UUID foo in anims)
  9616. l.Add(new LSL_Key(foo.ToString()));
  9617. return l;
  9618. }
  9619. public void llSetParcelMusicURL(string url)
  9620. {
  9621. m_host.AddScriptLPS(1);
  9622. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9623. if (land.LandData.OwnerID != m_host.OwnerID)
  9624. return;
  9625. land.SetMusicUrl(url);
  9626. ScriptSleep(m_sleepMsOnSetParcelMusicURL);
  9627. }
  9628. public LSL_String llGetParcelMusicURL()
  9629. {
  9630. m_host.AddScriptLPS(1);
  9631. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9632. if (land.LandData.OwnerID != m_host.OwnerID)
  9633. return String.Empty;
  9634. return land.GetMusicUrl();
  9635. }
  9636. public LSL_Vector llGetRootPosition()
  9637. {
  9638. m_host.AddScriptLPS(1);
  9639. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  9640. }
  9641. /// <summary>
  9642. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  9643. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  9644. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  9645. /// In the root prim:-
  9646. /// Returns the object rotation if not attached
  9647. /// Returns the avatars rotation if attached
  9648. /// Returns the camera rotation if attached and the avatar is in mouselook
  9649. /// </summary>
  9650. public LSL_Rotation llGetRootRotation()
  9651. {
  9652. m_host.AddScriptLPS(1);
  9653. Quaternion q;
  9654. if (m_host.ParentGroup.AttachmentPoint != 0)
  9655. {
  9656. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  9657. if (avatar != null)
  9658. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  9659. q = avatar.CameraRotation; // Mouselook
  9660. else
  9661. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  9662. else
  9663. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  9664. }
  9665. else
  9666. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  9667. return new LSL_Rotation(q);
  9668. }
  9669. public LSL_String llGetObjectDesc()
  9670. {
  9671. return m_host.Description ?? String.Empty;
  9672. }
  9673. public void llSetObjectDesc(string desc)
  9674. {
  9675. m_host.AddScriptLPS(1);
  9676. m_host.Description = desc ?? String.Empty;
  9677. }
  9678. public LSL_Key llGetCreator()
  9679. {
  9680. m_host.AddScriptLPS(1);
  9681. return m_host.CreatorID.ToString();
  9682. }
  9683. public LSL_String llGetTimestamp()
  9684. {
  9685. m_host.AddScriptLPS(1);
  9686. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  9687. }
  9688. public LSL_Integer llGetNumberOfPrims()
  9689. {
  9690. m_host.AddScriptLPS(1);
  9691. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  9692. }
  9693. /// <summary>
  9694. /// Full implementation of llGetBoundingBox according to SL 2015-04-15.
  9695. /// http://wiki.secondlife.com/wiki/LlGetBoundingBox
  9696. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  9697. /// Returns local bounding box of avatar without attachments
  9698. /// if target is non-seated avatar or prim/mesh in avatar attachment.
  9699. /// Returns local bounding box of object
  9700. /// if target is seated avatar or prim/mesh in object.
  9701. /// Uses less accurate box models for speed.
  9702. /// </summary>
  9703. public LSL_List llGetBoundingBox(string obj)
  9704. {
  9705. m_host.AddScriptLPS(1);
  9706. UUID objID = UUID.Zero;
  9707. LSL_List result = new LSL_List();
  9708. // If the ID is not valid, return null result
  9709. if (!UUID.TryParse(obj, out objID))
  9710. {
  9711. result.Add(new LSL_Vector());
  9712. result.Add(new LSL_Vector());
  9713. return result;
  9714. }
  9715. // Check if this is an attached prim. If so, replace
  9716. // the UUID with the avatar UUID and report it's bounding box
  9717. SceneObjectPart part = World.GetSceneObjectPart(objID);
  9718. if (part != null && part.ParentGroup.IsAttachment)
  9719. objID = part.ParentGroup.AttachedAvatar;
  9720. // Find out if this is an avatar ID. If so, return it's box
  9721. ScenePresence presence = World.GetScenePresence(objID);
  9722. if (presence != null)
  9723. {
  9724. LSL_Vector lower;
  9725. LSL_Vector upper;
  9726. Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
  9727. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  9728. == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  9729. {
  9730. // This is for ground sitting avatars TODO!
  9731. lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
  9732. upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
  9733. }
  9734. else
  9735. {
  9736. // This is for standing/flying avatars
  9737. lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
  9738. upper = new LSL_Vector(box.X, box.Y, box.Z);
  9739. }
  9740. if (lower.x > upper.x)
  9741. lower.x = upper.x;
  9742. if (lower.y > upper.y)
  9743. lower.y = upper.y;
  9744. if (lower.z > upper.z)
  9745. lower.z = upper.z;
  9746. result.Add(lower);
  9747. result.Add(upper);
  9748. return result;
  9749. }
  9750. part = World.GetSceneObjectPart(objID);
  9751. // Currently only works for single prims without a sitting avatar
  9752. if (part == null)
  9753. {
  9754. result.Add(new LSL_Vector());
  9755. result.Add(new LSL_Vector());
  9756. return result;
  9757. }
  9758. SceneObjectGroup sog = part.ParentGroup;
  9759. if(sog.IsDeleted)
  9760. {
  9761. result.Add(new LSL_Vector());
  9762. result.Add(new LSL_Vector());
  9763. return result;
  9764. }
  9765. sog.GetBoundingBox(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ);
  9766. result.Add(new LSL_Vector(minX, minY, minZ));
  9767. result.Add(new LSL_Vector(maxX, maxY, maxZ));
  9768. return result;
  9769. }
  9770. /// <summary>
  9771. /// Helper to calculate bounding box of an avatar.
  9772. /// </summary>
  9773. private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper)
  9774. {
  9775. // Adjust from OS model
  9776. // avatar height = visual height - 0.2, bounding box height = visual height
  9777. // to SL model
  9778. // avatar height = visual height, bounding box height = visual height + 0.2
  9779. float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection;
  9780. // According to avatar bounding box in SL 2015-04-18:
  9781. // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h>
  9782. // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5>
  9783. // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h>
  9784. // When avatar is sitting
  9785. if (sp.ParentPart != null)
  9786. {
  9787. lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height);
  9788. upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height);
  9789. }
  9790. // When avatar is groundsitting
  9791. else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  9792. {
  9793. lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height);
  9794. upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height);
  9795. }
  9796. // When avatar is standing or flying
  9797. else
  9798. {
  9799. lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
  9800. upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
  9801. }
  9802. }
  9803. public LSL_Vector llGetGeometricCenter()
  9804. {
  9805. return new LSL_Vector(m_host.GetGeometricCenter());
  9806. }
  9807. public LSL_List llGetPrimitiveParams(LSL_List rules)
  9808. {
  9809. m_host.AddScriptLPS(1);
  9810. LSL_List result = new LSL_List();
  9811. LSL_List remaining = GetPrimParams(m_host, rules, ref result);
  9812. while (!(remaining is null) && remaining.Length > 1)
  9813. {
  9814. int linknumber = remaining.GetLSLIntegerItem(0);
  9815. rules = remaining.GetSublist(1, -1);
  9816. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  9817. if(parts.Count == 0)
  9818. break;
  9819. foreach (SceneObjectPart part in parts)
  9820. remaining = GetPrimParams(part, rules, ref result);
  9821. }
  9822. return result;
  9823. }
  9824. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  9825. {
  9826. m_host.AddScriptLPS(1);
  9827. // acording to SL wiki this must indicate a single link number or link_root or link_this.
  9828. // keep other options as before
  9829. List<SceneObjectPart> parts;
  9830. List<ScenePresence> avatars;
  9831. LSL_List res = new LSL_List();
  9832. LSL_List remaining = new LSL_List();
  9833. while (rules.Length > 0)
  9834. {
  9835. parts = GetLinkParts(linknumber);
  9836. avatars = GetLinkAvatars(linknumber);
  9837. remaining = new LSL_List();
  9838. foreach (SceneObjectPart part in parts)
  9839. {
  9840. remaining = GetPrimParams(part, rules, ref res);
  9841. }
  9842. foreach (ScenePresence avatar in avatars)
  9843. {
  9844. remaining = GetPrimParams(avatar, rules, ref res);
  9845. }
  9846. if (remaining.Length > 0)
  9847. {
  9848. linknumber = remaining.GetLSLIntegerItem(0);
  9849. rules = remaining.GetSublist(1, -1);
  9850. }
  9851. else
  9852. break;
  9853. }
  9854. return res;
  9855. }
  9856. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  9857. {
  9858. int idx = 0;
  9859. int face;
  9860. Primitive.TextureEntry tex;
  9861. int nsides = GetNumberOfSides(part);
  9862. while (idx < rules.Length)
  9863. {
  9864. int code = (int)rules.GetLSLIntegerItem(idx++);
  9865. int remain = rules.Length - idx;
  9866. switch (code)
  9867. {
  9868. case (int)ScriptBaseClass.PRIM_MATERIAL:
  9869. res.Add(new LSL_Integer(part.Material));
  9870. break;
  9871. case (int)ScriptBaseClass.PRIM_PHYSICS:
  9872. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  9873. res.Add(new LSL_Integer(1));
  9874. else
  9875. res.Add(new LSL_Integer(0));
  9876. break;
  9877. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  9878. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  9879. res.Add(new LSL_Integer(1));
  9880. else
  9881. res.Add(new LSL_Integer(0));
  9882. break;
  9883. case (int)ScriptBaseClass.PRIM_PHANTOM:
  9884. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  9885. res.Add(new LSL_Integer(1));
  9886. else
  9887. res.Add(new LSL_Integer(0));
  9888. break;
  9889. case (int)ScriptBaseClass.PRIM_POSITION:
  9890. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  9891. part.AbsolutePosition.Y,
  9892. part.AbsolutePosition.Z);
  9893. res.Add(v);
  9894. break;
  9895. case (int)ScriptBaseClass.PRIM_SIZE:
  9896. res.Add(new LSL_Vector(part.Scale));
  9897. break;
  9898. case (int)ScriptBaseClass.PRIM_ROTATION:
  9899. res.Add(GetPartRot(part));
  9900. break;
  9901. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  9902. res.Add(new LSL_Integer((int)part.PhysicsShapeType));
  9903. break;
  9904. case (int)ScriptBaseClass.PRIM_TYPE:
  9905. // implementing box
  9906. PrimitiveBaseShape Shape = part.Shape;
  9907. int primType = (int)part.GetPrimType();
  9908. res.Add(new LSL_Integer(primType));
  9909. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  9910. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  9911. switch (primType)
  9912. {
  9913. case ScriptBaseClass.PRIM_TYPE_BOX:
  9914. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  9915. case ScriptBaseClass.PRIM_TYPE_PRISM:
  9916. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9917. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9918. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9919. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9920. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9921. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9922. break;
  9923. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  9924. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9925. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9926. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9927. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9928. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9929. break;
  9930. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  9931. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  9932. res.Add(new LSL_Integer(Shape.SculptType));
  9933. break;
  9934. case ScriptBaseClass.PRIM_TYPE_RING:
  9935. case ScriptBaseClass.PRIM_TYPE_TUBE:
  9936. case ScriptBaseClass.PRIM_TYPE_TORUS:
  9937. // holeshape
  9938. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9939. // cut
  9940. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9941. // hollow
  9942. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9943. // twist
  9944. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9945. // vector holesize
  9946. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9947. // vector topshear
  9948. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9949. // vector profilecut
  9950. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9951. // vector tapera
  9952. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  9953. // float revolutions
  9954. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  9955. // Slightly inaccurate, because an unsigned byte is being used to represent
  9956. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  9957. // SL does it).
  9958. //
  9959. // Using these formulas to store and retrieve PathRevolutions, it is not
  9960. // possible to use all values between 1.00 and 4.00. For instance, you can't
  9961. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  9962. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  9963. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  9964. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  9965. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  9966. // such as 1.10. So, SL must store and retreive the actual user input rather
  9967. // than only storing the encoded value.
  9968. // float radiusoffset
  9969. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  9970. // float skew
  9971. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  9972. break;
  9973. }
  9974. break;
  9975. case (int)ScriptBaseClass.PRIM_TEXTURE:
  9976. if (remain < 1)
  9977. return new LSL_List();
  9978. face = (int)rules.GetLSLIntegerItem(idx++);
  9979. tex = part.Shape.Textures;
  9980. if (face == ScriptBaseClass.ALL_SIDES)
  9981. {
  9982. for (face = 0; face < nsides; face++)
  9983. {
  9984. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9985. res.Add(new LSL_String(texface.TextureID.ToString()));
  9986. res.Add(new LSL_Vector(texface.RepeatU,
  9987. texface.RepeatV,
  9988. 0));
  9989. res.Add(new LSL_Vector(texface.OffsetU,
  9990. texface.OffsetV,
  9991. 0));
  9992. res.Add(new LSL_Float(texface.Rotation));
  9993. }
  9994. }
  9995. else
  9996. {
  9997. if (face >= 0 && face < nsides)
  9998. {
  9999. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10000. res.Add(new LSL_String(texface.TextureID.ToString()));
  10001. res.Add(new LSL_Vector(texface.RepeatU,
  10002. texface.RepeatV,
  10003. 0));
  10004. res.Add(new LSL_Vector(texface.OffsetU,
  10005. texface.OffsetV,
  10006. 0));
  10007. res.Add(new LSL_Float(texface.Rotation));
  10008. }
  10009. }
  10010. break;
  10011. case (int)ScriptBaseClass.PRIM_COLOR:
  10012. if (remain < 1)
  10013. return new LSL_List();
  10014. face = (int)rules.GetLSLIntegerItem(idx++);
  10015. tex = part.Shape.Textures;
  10016. Color4 texcolor;
  10017. if (face == ScriptBaseClass.ALL_SIDES)
  10018. {
  10019. for (face = 0; face < nsides; face++)
  10020. {
  10021. texcolor = tex.GetFace((uint)face).RGBA;
  10022. res.Add(new LSL_Vector(texcolor.R,
  10023. texcolor.G,
  10024. texcolor.B));
  10025. res.Add(new LSL_Float(texcolor.A));
  10026. }
  10027. }
  10028. else
  10029. {
  10030. texcolor = tex.GetFace((uint)face).RGBA;
  10031. res.Add(new LSL_Vector(texcolor.R,
  10032. texcolor.G,
  10033. texcolor.B));
  10034. res.Add(new LSL_Float(texcolor.A));
  10035. }
  10036. break;
  10037. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  10038. {
  10039. if (remain < 1)
  10040. return new LSL_List();
  10041. face = (int)rules.GetLSLIntegerItem(idx++);
  10042. tex = part.Shape.Textures;
  10043. int shiny;
  10044. if (face == ScriptBaseClass.ALL_SIDES)
  10045. {
  10046. for (face = 0; face < nsides; face++)
  10047. {
  10048. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10049. if (shinyness == Shininess.High)
  10050. {
  10051. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10052. }
  10053. else if (shinyness == Shininess.Medium)
  10054. {
  10055. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10056. }
  10057. else if (shinyness == Shininess.Low)
  10058. {
  10059. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10060. }
  10061. else
  10062. {
  10063. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10064. }
  10065. res.Add(new LSL_Integer(shiny));
  10066. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10067. }
  10068. }
  10069. else
  10070. {
  10071. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10072. if (shinyness == Shininess.High)
  10073. {
  10074. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10075. }
  10076. else if (shinyness == Shininess.Medium)
  10077. {
  10078. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10079. }
  10080. else if (shinyness == Shininess.Low)
  10081. {
  10082. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10083. }
  10084. else
  10085. {
  10086. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10087. }
  10088. res.Add(new LSL_Integer(shiny));
  10089. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10090. }
  10091. break;
  10092. }
  10093. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  10094. {
  10095. if (remain < 1)
  10096. return new LSL_List();
  10097. face = (int)rules.GetLSLIntegerItem(idx++);
  10098. tex = part.Shape.Textures;
  10099. int fullbright;
  10100. if (face == ScriptBaseClass.ALL_SIDES)
  10101. {
  10102. for (face = 0; face < nsides; face++)
  10103. {
  10104. if (tex.GetFace((uint)face).Fullbright == true)
  10105. {
  10106. fullbright = ScriptBaseClass.TRUE;
  10107. }
  10108. else
  10109. {
  10110. fullbright = ScriptBaseClass.FALSE;
  10111. }
  10112. res.Add(new LSL_Integer(fullbright));
  10113. }
  10114. }
  10115. else
  10116. {
  10117. if (tex.GetFace((uint)face).Fullbright == true)
  10118. {
  10119. fullbright = ScriptBaseClass.TRUE;
  10120. }
  10121. else
  10122. {
  10123. fullbright = ScriptBaseClass.FALSE;
  10124. }
  10125. res.Add(new LSL_Integer(fullbright));
  10126. }
  10127. break;
  10128. }
  10129. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  10130. PrimitiveBaseShape shape = part.Shape;
  10131. if (shape.FlexiEntry)
  10132. res.Add(new LSL_Integer(1)); // active
  10133. else
  10134. res.Add(new LSL_Integer(0));
  10135. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  10136. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  10137. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  10138. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  10139. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  10140. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  10141. shape.FlexiForceY,
  10142. shape.FlexiForceZ));
  10143. break;
  10144. case (int)ScriptBaseClass.PRIM_TEXGEN:
  10145. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  10146. if (remain < 1)
  10147. return new LSL_List();
  10148. face = (int)rules.GetLSLIntegerItem(idx++);
  10149. tex = part.Shape.Textures;
  10150. if (face == ScriptBaseClass.ALL_SIDES)
  10151. {
  10152. for (face = 0; face < nsides; face++)
  10153. {
  10154. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10155. {
  10156. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10157. }
  10158. else
  10159. {
  10160. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10161. }
  10162. }
  10163. }
  10164. else
  10165. {
  10166. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10167. {
  10168. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10169. }
  10170. else
  10171. {
  10172. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10173. }
  10174. }
  10175. break;
  10176. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  10177. shape = part.Shape;
  10178. if (shape.LightEntry)
  10179. res.Add(new LSL_Integer(1)); // active
  10180. else
  10181. res.Add(new LSL_Integer(0));
  10182. res.Add(new LSL_Vector(shape.LightColorR, // color
  10183. shape.LightColorG,
  10184. shape.LightColorB));
  10185. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  10186. res.Add(new LSL_Float(shape.LightRadius)); // radius
  10187. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  10188. break;
  10189. case (int)ScriptBaseClass.PRIM_GLOW:
  10190. if (remain < 1)
  10191. return new LSL_List();
  10192. face = (int)rules.GetLSLIntegerItem(idx++);
  10193. tex = part.Shape.Textures;
  10194. float primglow;
  10195. if (face == ScriptBaseClass.ALL_SIDES)
  10196. {
  10197. for (face = 0; face < nsides; face++)
  10198. {
  10199. primglow = tex.GetFace((uint)face).Glow;
  10200. res.Add(new LSL_Float(primglow));
  10201. }
  10202. }
  10203. else
  10204. {
  10205. primglow = tex.GetFace((uint)face).Glow;
  10206. res.Add(new LSL_Float(primglow));
  10207. }
  10208. break;
  10209. case (int)ScriptBaseClass.PRIM_TEXT:
  10210. Color4 textColor = part.GetTextColor();
  10211. res.Add(new LSL_String(part.Text));
  10212. res.Add(new LSL_Vector(textColor.R,
  10213. textColor.G,
  10214. textColor.B));
  10215. res.Add(new LSL_Float(textColor.A));
  10216. break;
  10217. case (int)ScriptBaseClass.PRIM_NAME:
  10218. res.Add(new LSL_String(part.Name));
  10219. break;
  10220. case (int)ScriptBaseClass.PRIM_DESC:
  10221. res.Add(new LSL_String(part.Description));
  10222. break;
  10223. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  10224. res.Add(new LSL_Rotation(part.RotationOffset));
  10225. break;
  10226. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  10227. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  10228. break;
  10229. case (int)ScriptBaseClass.PRIM_SLICE:
  10230. PrimType prim_type = part.GetPrimType();
  10231. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  10232. res.Add(new LSL_Vector(
  10233. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  10234. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  10235. 0
  10236. ));
  10237. break;
  10238. case (int)ScriptBaseClass.PRIM_OMEGA:
  10239. // this may return values diferent from SL since we don't handle set the same way
  10240. float gain = 1.0f; // we don't use gain and don't store it
  10241. Vector3 axis = part.AngularVelocity;
  10242. float spin = axis.Length();
  10243. if(spin < 1.0e-6)
  10244. {
  10245. axis = Vector3.Zero;
  10246. gain = 0.0f;
  10247. spin = 0.0f;
  10248. }
  10249. else
  10250. {
  10251. axis = axis * (1.0f/spin);
  10252. }
  10253. res.Add(new LSL_Vector(axis.X,
  10254. axis.Y,
  10255. axis.Z));
  10256. res.Add(new LSL_Float(spin));
  10257. res.Add(new LSL_Float(gain));
  10258. break;
  10259. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  10260. if(part.IsSitTargetSet)
  10261. {
  10262. res.Add(new LSL_Integer(1));
  10263. res.Add(new LSL_Vector(part.SitTargetPosition));
  10264. res.Add(new LSL_Rotation(part.SitTargetOrientation));
  10265. }
  10266. else
  10267. {
  10268. res.Add(new LSL_Integer(0));
  10269. res.Add(new LSL_Vector(Vector3.Zero));
  10270. res.Add(new LSL_Rotation(Quaternion.Identity));
  10271. }
  10272. break;
  10273. case (int)ScriptBaseClass.PRIM_NORMAL:
  10274. case (int)ScriptBaseClass.PRIM_SPECULAR:
  10275. case (int)ScriptBaseClass.PRIM_ALPHA_MODE:
  10276. if (remain < 1)
  10277. return new LSL_List();
  10278. face = (int)rules.GetLSLIntegerItem(idx++);
  10279. tex = part.Shape.Textures;
  10280. if (face == ScriptBaseClass.ALL_SIDES)
  10281. {
  10282. for (face = 0; face < nsides; face++)
  10283. {
  10284. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10285. getLSLFaceMaterial(ref res, code, part, texface);
  10286. }
  10287. }
  10288. else
  10289. {
  10290. if (face >= 0 && face < nsides)
  10291. {
  10292. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10293. getLSLFaceMaterial(ref res, code, part, texface);
  10294. }
  10295. }
  10296. break;
  10297. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  10298. // TODO: Should be issuing a runtime script warning in this case.
  10299. if (remain < 2)
  10300. return new LSL_List();
  10301. return rules.GetSublist(idx, -1);
  10302. }
  10303. }
  10304. return new LSL_List();
  10305. }
  10306. private string GetMaterialTextureUUIDbyRights(UUID origID, SceneObjectPart part)
  10307. {
  10308. if(World.Permissions.CanEditObject(m_host.ParentGroup.UUID, m_host.ParentGroup.RootPart.OwnerID))
  10309. return origID.ToString();
  10310. lock(part.TaskInventory)
  10311. {
  10312. foreach(KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  10313. {
  10314. if(inv.Value.InvType == (int)InventoryType.Texture && inv.Value.AssetID == origID)
  10315. return origID.ToString();
  10316. }
  10317. }
  10318. return ScriptBaseClass.NULL_KEY;
  10319. }
  10320. private void getLSLFaceMaterial(ref LSL_List res, int code, SceneObjectPart part, Primitive.TextureEntryFace texface)
  10321. {
  10322. UUID matID = UUID.Zero;
  10323. if(m_materialsModule != null)
  10324. matID = texface.MaterialID;
  10325. if(matID != UUID.Zero)
  10326. {
  10327. FaceMaterial mat = m_materialsModule.GetMaterial(matID);
  10328. if(mat != null)
  10329. {
  10330. if(code == ScriptBaseClass.PRIM_NORMAL)
  10331. {
  10332. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.NormalMapID, part)));
  10333. res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0));
  10334. res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0));
  10335. res.Add(new LSL_Float(mat.NormalRotation));
  10336. }
  10337. else if(code == ScriptBaseClass.PRIM_SPECULAR)
  10338. {
  10339. const float colorScale = 1.0f / 255f;
  10340. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.SpecularMapID, part)));
  10341. res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0));
  10342. res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0));
  10343. res.Add(new LSL_Float(mat.SpecularRotation));
  10344. res.Add(new LSL_Vector(mat.SpecularLightColorR * colorScale,
  10345. mat.SpecularLightColorG * colorScale,
  10346. mat.SpecularLightColorB * colorScale));
  10347. res.Add(new LSL_Integer(mat.SpecularLightExponent));
  10348. res.Add(new LSL_Integer(mat.EnvironmentIntensity));
  10349. }
  10350. else if(code == ScriptBaseClass.PRIM_ALPHA_MODE)
  10351. {
  10352. res.Add(new LSL_Integer(mat.DiffuseAlphaMode));
  10353. res.Add(new LSL_Integer(mat.AlphaMaskCutoff));
  10354. }
  10355. return;
  10356. }
  10357. }
  10358. // material not found
  10359. if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10360. {
  10361. res.Add(new LSL_String(ScriptBaseClass.NULL_KEY));
  10362. res.Add(new LSL_Vector(1.0, 1.0, 0));
  10363. res.Add(new LSL_Vector(0, 0, 0));
  10364. res.Add(new LSL_Float(0));
  10365. if(code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10366. {
  10367. res.Add(new LSL_Vector(1.0, 1.0, 1.0));
  10368. res.Add(new LSL_Integer(51));
  10369. res.Add(new LSL_Integer(0));
  10370. }
  10371. }
  10372. else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE)
  10373. {
  10374. res.Add(new LSL_Integer(1));
  10375. res.Add(new LSL_Integer(0));
  10376. }
  10377. }
  10378. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  10379. {
  10380. m_host.AddScriptLPS(1);
  10381. ScriptSleep(m_sleepMsOnGetPrimMediaParams);
  10382. return GetPrimMediaParams(m_host, face, rules);
  10383. }
  10384. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10385. {
  10386. m_host.AddScriptLPS(1);
  10387. ScriptSleep(m_sleepMsOnGetLinkMedia);
  10388. if (link == ScriptBaseClass.LINK_ROOT)
  10389. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10390. else if (link == ScriptBaseClass.LINK_THIS)
  10391. return GetPrimMediaParams(m_host, face, rules);
  10392. else
  10393. {
  10394. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10395. if (null != part)
  10396. return GetPrimMediaParams(part, face, rules);
  10397. }
  10398. return new LSL_List();
  10399. }
  10400. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  10401. {
  10402. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  10403. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  10404. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  10405. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10406. return new LSL_List();
  10407. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10408. if (null == module)
  10409. return new LSL_List();
  10410. MediaEntry me = module.GetMediaEntry(part, face);
  10411. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  10412. if (null == me)
  10413. return new LSL_List();
  10414. LSL_List res = new LSL_List();
  10415. for (int i = 0; i < rules.Length; i++)
  10416. {
  10417. int code = (int)rules.GetLSLIntegerItem(i);
  10418. switch (code)
  10419. {
  10420. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10421. // Not implemented
  10422. res.Add(new LSL_Integer(0));
  10423. break;
  10424. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10425. if (me.Controls == MediaControls.Standard)
  10426. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  10427. else
  10428. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  10429. break;
  10430. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10431. res.Add(new LSL_String(me.CurrentURL));
  10432. break;
  10433. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10434. res.Add(new LSL_String(me.HomeURL));
  10435. break;
  10436. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10437. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10438. break;
  10439. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10440. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10441. break;
  10442. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10443. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10444. break;
  10445. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10446. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10447. break;
  10448. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10449. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10450. break;
  10451. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10452. res.Add(new LSL_Integer(me.Width));
  10453. break;
  10454. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10455. res.Add(new LSL_Integer(me.Height));
  10456. break;
  10457. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10458. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10459. break;
  10460. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10461. string[] urls = (string[])me.WhiteList.Clone();
  10462. for (int j = 0; j < urls.Length; j++)
  10463. urls[j] = Uri.EscapeDataString(urls[j]);
  10464. res.Add(new LSL_String(string.Join(", ", urls)));
  10465. break;
  10466. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10467. res.Add(new LSL_Integer((int)me.InteractPermissions));
  10468. break;
  10469. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10470. res.Add(new LSL_Integer((int)me.ControlPermissions));
  10471. break;
  10472. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10473. }
  10474. }
  10475. return res;
  10476. }
  10477. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  10478. {
  10479. m_host.AddScriptLPS(1);
  10480. ScriptSleep(m_sleepMsOnSetPrimMediaParams);
  10481. return SetPrimMediaParams(m_host, face, rules);
  10482. }
  10483. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10484. {
  10485. m_host.AddScriptLPS(1);
  10486. ScriptSleep(m_sleepMsOnSetLinkMedia);
  10487. if (link == ScriptBaseClass.LINK_ROOT)
  10488. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10489. else if (link == ScriptBaseClass.LINK_THIS)
  10490. return SetPrimMediaParams(m_host, face, rules);
  10491. else
  10492. {
  10493. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10494. if (null != part)
  10495. return SetPrimMediaParams(part, face, rules);
  10496. }
  10497. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10498. }
  10499. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  10500. {
  10501. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  10502. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10503. // Don't perform the media check directly
  10504. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10505. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10506. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10507. if (null == module)
  10508. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10509. MediaEntry me = module.GetMediaEntry(part, face);
  10510. if (null == me)
  10511. me = new MediaEntry();
  10512. int i = 0;
  10513. while (i < rules.Length - 1)
  10514. {
  10515. int code = rules.GetLSLIntegerItem(i++);
  10516. switch (code)
  10517. {
  10518. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10519. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  10520. break;
  10521. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10522. int v = rules.GetLSLIntegerItem(i++);
  10523. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  10524. me.Controls = MediaControls.Standard;
  10525. else
  10526. me.Controls = MediaControls.Mini;
  10527. break;
  10528. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10529. me.CurrentURL = rules.GetLSLStringItem(i++);
  10530. break;
  10531. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10532. me.HomeURL = rules.GetLSLStringItem(i++);
  10533. break;
  10534. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10535. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10536. break;
  10537. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10538. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10539. break;
  10540. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10541. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10542. break;
  10543. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10544. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10545. break;
  10546. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10547. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10548. break;
  10549. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10550. me.Width = (int)rules.GetLSLIntegerItem(i++);
  10551. break;
  10552. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10553. me.Height = (int)rules.GetLSLIntegerItem(i++);
  10554. break;
  10555. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10556. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10557. break;
  10558. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10559. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  10560. List<string> whiteListUrls = new List<string>();
  10561. Array.ForEach(
  10562. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  10563. me.WhiteList = whiteListUrls.ToArray();
  10564. break;
  10565. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10566. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10567. break;
  10568. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10569. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10570. break;
  10571. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10572. }
  10573. }
  10574. module.SetMediaEntry(part, face, me);
  10575. return ScriptBaseClass.LSL_STATUS_OK;
  10576. }
  10577. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  10578. {
  10579. m_host.AddScriptLPS(1);
  10580. ScriptSleep(m_sleepMsOnClearPrimMedia);
  10581. return ClearPrimMedia(m_host, face);
  10582. }
  10583. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  10584. {
  10585. m_host.AddScriptLPS(1);
  10586. ScriptSleep(m_sleepMsOnClearLinkMedia);
  10587. if (link == ScriptBaseClass.LINK_ROOT)
  10588. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  10589. else if (link == ScriptBaseClass.LINK_THIS)
  10590. return ClearPrimMedia(m_host, face);
  10591. else
  10592. {
  10593. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10594. if (null != part)
  10595. return ClearPrimMedia(part, face);
  10596. }
  10597. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10598. }
  10599. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  10600. {
  10601. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  10602. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10603. // FIXME: Don't perform the media check directly
  10604. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10605. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10606. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10607. if (null == module)
  10608. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10609. module.ClearMediaEntry(part, face);
  10610. return ScriptBaseClass.LSL_STATUS_OK;
  10611. }
  10612. // <remarks>
  10613. // <para>
  10614. // The .NET definition of base 64 is:
  10615. // <list>
  10616. // <item>
  10617. // Significant: A-Z a-z 0-9 + -
  10618. // </item>
  10619. // <item>
  10620. // Whitespace: \t \n \r ' '
  10621. // </item>
  10622. // <item>
  10623. // Valueless: =
  10624. // </item>
  10625. // <item>
  10626. // End-of-string: \0 or '=='
  10627. // </item>
  10628. // </list>
  10629. // </para>
  10630. // <para>
  10631. // Each point in a base-64 string represents
  10632. // a 6 bit value. A 32-bit integer can be
  10633. // represented using 6 characters (with some
  10634. // redundancy).
  10635. // </para>
  10636. // <para>
  10637. // LSL requires a base64 string to be 8
  10638. // characters in length. LSL also uses '/'
  10639. // rather than '-' (MIME compliant).
  10640. // </para>
  10641. // <para>
  10642. // RFC 1341 used as a reference (as specified
  10643. // by the SecondLife Wiki).
  10644. // </para>
  10645. // <para>
  10646. // SL do not record any kind of exception for
  10647. // these functions, so the string to integer
  10648. // conversion returns '0' if an invalid
  10649. // character is encountered during conversion.
  10650. // </para>
  10651. // <para>
  10652. // References
  10653. // <list>
  10654. // <item>
  10655. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  10656. // </item>
  10657. // <item>
  10658. // </item>
  10659. // </list>
  10660. // </para>
  10661. // </remarks>
  10662. // <summary>
  10663. // Table for converting 6-bit integers into
  10664. // base-64 characters
  10665. // </summary>
  10666. protected static readonly char[] i2ctable =
  10667. {
  10668. 'A','B','C','D','E','F','G','H',
  10669. 'I','J','K','L','M','N','O','P',
  10670. 'Q','R','S','T','U','V','W','X',
  10671. 'Y','Z',
  10672. 'a','b','c','d','e','f','g','h',
  10673. 'i','j','k','l','m','n','o','p',
  10674. 'q','r','s','t','u','v','w','x',
  10675. 'y','z',
  10676. '0','1','2','3','4','5','6','7',
  10677. '8','9',
  10678. '+','/'
  10679. };
  10680. // <summary>
  10681. // Table for converting base-64 characters
  10682. // into 6-bit integers.
  10683. // </summary>
  10684. protected static readonly int[] c2itable =
  10685. {
  10686. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  10687. -1,-1,-1,-1,-1,-1,-1,-1,
  10688. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  10689. -1,-1,-1,-1,-1,-1,-1,-1,
  10690. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  10691. -1,-1,-1,63,-1,-1,-1,64,
  10692. 53,54,55,56,57,58,59,60, // 3x
  10693. 61,62,-1,-1,-1,0,-1,-1,
  10694. -1,1,2,3,4,5,6,7, // 4x
  10695. 8,9,10,11,12,13,14,15,
  10696. 16,17,18,19,20,21,22,23, // 5x
  10697. 24,25,26,-1,-1,-1,-1,-1,
  10698. -1,27,28,29,30,31,32,33, // 6x
  10699. 34,35,36,37,38,39,40,41,
  10700. 42,43,44,45,46,47,48,49, // 7x
  10701. 50,51,52,-1,-1,-1,-1,-1,
  10702. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  10703. -1,-1,-1,-1,-1,-1,-1,-1,
  10704. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  10705. -1,-1,-1,-1,-1,-1,-1,-1,
  10706. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  10707. -1,-1,-1,-1,-1,-1,-1,-1,
  10708. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  10709. -1,-1,-1,-1,-1,-1,-1,-1,
  10710. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  10711. -1,-1,-1,-1,-1,-1,-1,-1,
  10712. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  10713. -1,-1,-1,-1,-1,-1,-1,-1,
  10714. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  10715. -1,-1,-1,-1,-1,-1,-1,-1,
  10716. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  10717. -1,-1,-1,-1,-1,-1,-1,-1
  10718. };
  10719. // <summary>
  10720. // Converts a 32-bit integer into a Base64
  10721. // character string. Base64 character strings
  10722. // are always 8 characters long. All iinteger
  10723. // values are acceptable.
  10724. // </summary>
  10725. // <param name="number">
  10726. // 32-bit integer to be converted.
  10727. // </param>
  10728. // <returns>
  10729. // 8 character string. The 1st six characters
  10730. // contain the encoded number, the last two
  10731. // characters are padded with "=".
  10732. // </returns>
  10733. public LSL_String llIntegerToBase64(int number)
  10734. {
  10735. // uninitialized string
  10736. char[] imdt = new char[8];
  10737. m_host.AddScriptLPS(1);
  10738. // Manually unroll the loop
  10739. imdt[7] = '=';
  10740. imdt[6] = '=';
  10741. imdt[5] = i2ctable[number<<4 & 0x3F];
  10742. imdt[4] = i2ctable[number>>2 & 0x3F];
  10743. imdt[3] = i2ctable[number>>8 & 0x3F];
  10744. imdt[2] = i2ctable[number>>14 & 0x3F];
  10745. imdt[1] = i2ctable[number>>20 & 0x3F];
  10746. imdt[0] = i2ctable[number>>26 & 0x3F];
  10747. return new string(imdt);
  10748. }
  10749. // <summary>
  10750. // Converts an eight character base-64 string
  10751. // into a 32-bit integer.
  10752. // </summary>
  10753. // <param name="str">
  10754. // 8 characters string to be converted. Other
  10755. // length strings return zero.
  10756. // </param>
  10757. // <returns>
  10758. // Returns an integer representing the
  10759. // encoded value providedint he 1st 6
  10760. // characters of the string.
  10761. // </returns>
  10762. // <remarks>
  10763. // This is coded to behave like LSL's
  10764. // implementation (I think), based upon the
  10765. // information available at the Wiki.
  10766. // If more than 8 characters are supplied,
  10767. // zero is returned.
  10768. // If a NULL string is supplied, zero will
  10769. // be returned.
  10770. // If fewer than 6 characters are supplied, then
  10771. // the answer will reflect a partial
  10772. // accumulation.
  10773. // <para>
  10774. // The 6-bit segments are
  10775. // extracted left-to-right in big-endian mode,
  10776. // which means that segment 6 only contains the
  10777. // two low-order bits of the 32 bit integer as
  10778. // its high order 2 bits. A short string therefore
  10779. // means loss of low-order information. E.g.
  10780. //
  10781. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  10782. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  10783. // |3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1| | | | | | | | | | |P|P|P|P|
  10784. // |1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|P|P|P|P|
  10785. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  10786. //
  10787. // </para>
  10788. // </remarks>
  10789. public LSL_Integer llBase64ToInteger(string str)
  10790. {
  10791. int number = 0;
  10792. int digit;
  10793. m_host.AddScriptLPS(1);
  10794. // Require a well-fromed base64 string
  10795. if (str.Length > 8)
  10796. return 0;
  10797. // The loop is unrolled in the interests
  10798. // of performance and simple necessity.
  10799. //
  10800. // MUST find 6 digits to be well formed
  10801. // -1 == invalid
  10802. // 0 == padding
  10803. if ((digit = c2itable[str[0]]) <= 0)
  10804. {
  10805. return digit < 0 ? (int)0 : number;
  10806. }
  10807. number += --digit<<26;
  10808. if ((digit = c2itable[str[1]]) <= 0)
  10809. {
  10810. return digit < 0 ? (int)0 : number;
  10811. }
  10812. number += --digit<<20;
  10813. if ((digit = c2itable[str[2]]) <= 0)
  10814. {
  10815. return digit < 0 ? (int)0 : number;
  10816. }
  10817. number += --digit<<14;
  10818. if ((digit = c2itable[str[3]]) <= 0)
  10819. {
  10820. return digit < 0 ? (int)0 : number;
  10821. }
  10822. number += --digit<<8;
  10823. if ((digit = c2itable[str[4]]) <= 0)
  10824. {
  10825. return digit < 0 ? (int)0 : number;
  10826. }
  10827. number += --digit<<2;
  10828. if ((digit = c2itable[str[5]]) <= 0)
  10829. {
  10830. return digit < 0 ? (int)0 : number;
  10831. }
  10832. number += --digit>>4;
  10833. // ignore trailing padding
  10834. return number;
  10835. }
  10836. public LSL_Float llGetGMTclock()
  10837. {
  10838. m_host.AddScriptLPS(1);
  10839. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  10840. }
  10841. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  10842. {
  10843. m_host.AddScriptLPS(1);
  10844. if (m_UrlModule != null)
  10845. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  10846. return String.Empty;
  10847. }
  10848. public LSL_String llGetSimulatorHostname()
  10849. {
  10850. m_host.AddScriptLPS(1);
  10851. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  10852. return UrlModule.ExternalHostNameForLSL;
  10853. }
  10854. // <summary>
  10855. // Scan the string supplied in 'src' and
  10856. // tokenize it based upon two sets of
  10857. // tokenizers provided in two lists,
  10858. // separators and spacers.
  10859. // </summary>
  10860. //
  10861. // <remarks>
  10862. // Separators demarcate tokens and are
  10863. // elided as they are encountered. Spacers
  10864. // also demarcate tokens, but are themselves
  10865. // retained as tokens.
  10866. //
  10867. // Both separators and spacers may be arbitrarily
  10868. // long strings. i.e. ":::".
  10869. //
  10870. // The function returns an ordered list
  10871. // representing the tokens found in the supplied
  10872. // sources string. If two successive tokenizers
  10873. // are encountered, then a null-string entry is
  10874. // added to the list.
  10875. //
  10876. // It is a precondition that the source and
  10877. // toekizer lisst are non-null. If they are null,
  10878. // then a null pointer exception will be thrown
  10879. // while their lengths are being determined.
  10880. //
  10881. // A small amount of working memoryis required
  10882. // of approximately 8*#tokenizers + 8*srcstrlen.
  10883. //
  10884. // There are many ways in which this function
  10885. // can be implemented, this implementation is
  10886. // fairly naive and assumes that when the
  10887. // function is invooked with a short source
  10888. // string and/or short lists of tokenizers, then
  10889. // performance will not be an issue.
  10890. //
  10891. // In order to minimize the perofrmance
  10892. // effects of long strings, or large numbers
  10893. // of tokeizers, the function skips as far as
  10894. // possible whenever a toekenizer is found,
  10895. // and eliminates redundant tokenizers as soon
  10896. // as is possible.
  10897. //
  10898. // The implementation tries to minimize temporary
  10899. // garbage generation.
  10900. // </remarks>
  10901. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  10902. {
  10903. return ParseString2List(src, separators, spacers, true);
  10904. }
  10905. private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  10906. {
  10907. int srclen = src.Length;
  10908. int seplen = separators.Length;
  10909. object[] separray = separators.Data;
  10910. int spclen = spacers.Length;
  10911. object[] spcarray = spacers.Data;
  10912. int dellen = 0;
  10913. string[] delarray = new string[seplen+spclen];
  10914. int outlen = 0;
  10915. string[] outarray = new string[srclen*2+1];
  10916. int i, j;
  10917. string d;
  10918. m_host.AddScriptLPS(1);
  10919. /*
  10920. * Convert separator and spacer lists to C# strings.
  10921. * Also filter out null strings so we don't hang.
  10922. */
  10923. for (i = 0; i < seplen; i ++)
  10924. {
  10925. d = separray[i].ToString();
  10926. if (d.Length > 0)
  10927. {
  10928. delarray[dellen++] = d;
  10929. }
  10930. }
  10931. seplen = dellen;
  10932. for (i = 0; i < spclen; i ++)
  10933. {
  10934. d = spcarray[i].ToString();
  10935. if (d.Length > 0)
  10936. {
  10937. delarray[dellen++] = d;
  10938. }
  10939. }
  10940. /*
  10941. * Scan through source string from beginning to end.
  10942. */
  10943. for (i = 0;;)
  10944. {
  10945. /*
  10946. * Find earliest delimeter in src starting at i (if any).
  10947. */
  10948. int earliestDel = -1;
  10949. int earliestSrc = srclen;
  10950. string earliestStr = null;
  10951. for (j = 0; j < dellen; j ++)
  10952. {
  10953. d = delarray[j];
  10954. if (d != null)
  10955. {
  10956. int index = src.IndexOf(d, i);
  10957. if (index < 0)
  10958. {
  10959. delarray[j] = null; // delim nowhere in src, don't check it anymore
  10960. }
  10961. else if (index < earliestSrc)
  10962. {
  10963. earliestSrc = index; // where delimeter starts in source string
  10964. earliestDel = j; // where delimeter is in delarray[]
  10965. earliestStr = d; // the delimeter string from delarray[]
  10966. if (index == i) break; // can't do any better than found at beg of string
  10967. }
  10968. }
  10969. }
  10970. /*
  10971. * Output source string starting at i through start of earliest delimeter.
  10972. */
  10973. if (keepNulls || (earliestSrc > i))
  10974. {
  10975. outarray[outlen++] = src.Substring(i, earliestSrc - i);
  10976. }
  10977. /*
  10978. * If no delimeter found at or after i, we're done scanning.
  10979. */
  10980. if (earliestDel < 0) break;
  10981. /*
  10982. * If delimeter was a spacer, output the spacer.
  10983. */
  10984. if (earliestDel >= seplen)
  10985. {
  10986. outarray[outlen++] = earliestStr;
  10987. }
  10988. /*
  10989. * Look at rest of src string following delimeter.
  10990. */
  10991. i = earliestSrc + earliestStr.Length;
  10992. }
  10993. /*
  10994. * Make up an exact-sized output array suitable for an LSL_List object.
  10995. */
  10996. object[] outlist = new object[outlen];
  10997. for (i = 0; i < outlen; i ++)
  10998. {
  10999. outlist[i] = new LSL_String(outarray[i]);
  11000. }
  11001. return new LSL_List(outlist);
  11002. }
  11003. private const uint fullperms = (uint)PermissionMask.All; // no export for now
  11004. private int PermissionMaskToLSLPerm(uint value)
  11005. {
  11006. value &= fullperms;
  11007. if (value == fullperms)
  11008. return ScriptBaseClass.PERM_ALL;
  11009. if( value == 0)
  11010. return 0;
  11011. int ret = 0;
  11012. if ((value & (uint)PermissionMask.Copy) != 0)
  11013. ret |= ScriptBaseClass.PERM_COPY;
  11014. if ((value & (uint)PermissionMask.Modify) != 0)
  11015. ret |= ScriptBaseClass.PERM_MODIFY;
  11016. if ((value & (uint)PermissionMask.Move) != 0)
  11017. ret |= ScriptBaseClass.PERM_MOVE;
  11018. if ((value & (uint)PermissionMask.Transfer) != 0)
  11019. ret |= ScriptBaseClass.PERM_TRANSFER;
  11020. return ret;
  11021. }
  11022. private uint LSLPermToPermissionMask(int lslperm, uint oldvalue)
  11023. {
  11024. lslperm &= ScriptBaseClass.PERM_ALL;
  11025. if (lslperm == ScriptBaseClass.PERM_ALL)
  11026. return oldvalue |= fullperms;
  11027. oldvalue &= ~fullperms;
  11028. if(lslperm != 0)
  11029. {
  11030. if ((lslperm & ScriptBaseClass.PERM_COPY) != 0)
  11031. oldvalue |= (uint)PermissionMask.Copy;
  11032. if ((lslperm & ScriptBaseClass.PERM_MODIFY) != 0)
  11033. oldvalue |= (uint)PermissionMask.Modify;
  11034. if ((lslperm & ScriptBaseClass.PERM_MOVE) != 0)
  11035. oldvalue |= (uint)PermissionMask.Move;
  11036. if ((lslperm & ScriptBaseClass.PERM_TRANSFER) != 0)
  11037. oldvalue |= (uint)PermissionMask.Transfer;
  11038. }
  11039. return oldvalue;
  11040. }
  11041. private int fixedCopyTransfer(int value)
  11042. {
  11043. if ((value & (ScriptBaseClass.PERM_COPY | ScriptBaseClass.PERM_TRANSFER)) == 0)
  11044. value |= ScriptBaseClass.PERM_TRANSFER;
  11045. return value;
  11046. }
  11047. public LSL_Integer llGetObjectPermMask(int mask)
  11048. {
  11049. m_host.AddScriptLPS(1);
  11050. switch(mask)
  11051. {
  11052. case ScriptBaseClass.MASK_BASE:
  11053. return PermissionMaskToLSLPerm(m_host.BaseMask);
  11054. case ScriptBaseClass.MASK_OWNER:
  11055. return PermissionMaskToLSLPerm(m_host.OwnerMask);
  11056. case ScriptBaseClass.MASK_GROUP:
  11057. return PermissionMaskToLSLPerm(m_host.GroupMask);
  11058. case ScriptBaseClass.MASK_EVERYONE:
  11059. return PermissionMaskToLSLPerm(m_host.EveryoneMask);
  11060. case ScriptBaseClass.MASK_NEXT:
  11061. return PermissionMaskToLSLPerm(m_host.NextOwnerMask);
  11062. }
  11063. return -1;
  11064. }
  11065. public void llSetObjectPermMask(int mask, int value)
  11066. {
  11067. m_host.AddScriptLPS(1);
  11068. if (!m_AllowGodFunctions || !World.Permissions.IsAdministrator(m_host.OwnerID))
  11069. return;
  11070. // not even admins have right to violate basic rules
  11071. if (mask != ScriptBaseClass.MASK_BASE)
  11072. {
  11073. mask &= PermissionMaskToLSLPerm(m_host.BaseMask);
  11074. if (mask != ScriptBaseClass.MASK_OWNER)
  11075. mask &= PermissionMaskToLSLPerm(m_host.OwnerMask);
  11076. }
  11077. switch (mask)
  11078. {
  11079. case ScriptBaseClass.MASK_BASE:
  11080. value = fixedCopyTransfer(value);
  11081. m_host.BaseMask = LSLPermToPermissionMask(value, m_host.BaseMask);
  11082. break;
  11083. case ScriptBaseClass.MASK_OWNER:
  11084. value = fixedCopyTransfer(value);
  11085. m_host.OwnerMask = LSLPermToPermissionMask(value, m_host.OwnerMask);
  11086. break;
  11087. case ScriptBaseClass.MASK_GROUP:
  11088. m_host.GroupMask = LSLPermToPermissionMask(value, m_host.GroupMask);
  11089. break;
  11090. case ScriptBaseClass.MASK_EVERYONE:
  11091. m_host.EveryoneMask = LSLPermToPermissionMask(value, m_host.EveryoneMask);
  11092. break;
  11093. case ScriptBaseClass.MASK_NEXT:
  11094. value = fixedCopyTransfer(value);
  11095. m_host.NextOwnerMask = LSLPermToPermissionMask(value, m_host.NextOwnerMask);
  11096. break;
  11097. default:
  11098. return;
  11099. }
  11100. m_host.ParentGroup.AggregatePerms();
  11101. }
  11102. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  11103. {
  11104. m_host.AddScriptLPS(1);
  11105. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11106. if (item == null)
  11107. return -1;
  11108. switch (mask)
  11109. {
  11110. case ScriptBaseClass.MASK_BASE:
  11111. return PermissionMaskToLSLPerm(item.BasePermissions);
  11112. case ScriptBaseClass.MASK_OWNER:
  11113. return PermissionMaskToLSLPerm(item.CurrentPermissions);
  11114. case ScriptBaseClass.MASK_GROUP:
  11115. return PermissionMaskToLSLPerm(item.GroupPermissions);
  11116. case ScriptBaseClass.MASK_EVERYONE:
  11117. return PermissionMaskToLSLPerm(item.EveryonePermissions);
  11118. case ScriptBaseClass.MASK_NEXT:
  11119. return PermissionMaskToLSLPerm(item.NextPermissions);
  11120. }
  11121. return -1;
  11122. }
  11123. public void llSetInventoryPermMask(string itemName, int mask, int value)
  11124. {
  11125. m_host.AddScriptLPS(1);
  11126. if(!m_AllowGodFunctions || !World.Permissions.IsAdministrator(m_host.OwnerID))
  11127. return;
  11128. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11129. if (item != null)
  11130. {
  11131. if (mask != ScriptBaseClass.MASK_BASE)
  11132. {
  11133. mask &= PermissionMaskToLSLPerm(item.BasePermissions);
  11134. if (mask != ScriptBaseClass.MASK_OWNER)
  11135. mask &= PermissionMaskToLSLPerm(item.CurrentPermissions);
  11136. }
  11137. /*
  11138. if(item.Type == (int)(AssetType.Settings))
  11139. value |= ScriptBaseClass.PERM_COPY;
  11140. */
  11141. switch (mask)
  11142. {
  11143. case ScriptBaseClass.MASK_BASE:
  11144. value = fixedCopyTransfer(value);
  11145. item.BasePermissions = LSLPermToPermissionMask(value, item.BasePermissions);
  11146. break;
  11147. case ScriptBaseClass.MASK_OWNER:
  11148. value = fixedCopyTransfer(value);
  11149. item.CurrentPermissions = LSLPermToPermissionMask(value, item.CurrentPermissions);
  11150. break;
  11151. case ScriptBaseClass.MASK_GROUP:
  11152. item.GroupPermissions = LSLPermToPermissionMask(value, item.GroupPermissions);
  11153. break;
  11154. case ScriptBaseClass.MASK_EVERYONE:
  11155. item.EveryonePermissions = LSLPermToPermissionMask(value, item.EveryonePermissions);
  11156. break;
  11157. case ScriptBaseClass.MASK_NEXT:
  11158. value = fixedCopyTransfer(value);
  11159. item.NextPermissions = LSLPermToPermissionMask(value, item.NextPermissions);
  11160. break;
  11161. default:
  11162. return;
  11163. }
  11164. m_host.ParentGroup.InvalidateDeepEffectivePerms();
  11165. m_host.ParentGroup.AggregatePerms();
  11166. }
  11167. }
  11168. public LSL_Key llGetInventoryCreator(string itemName)
  11169. {
  11170. m_host.AddScriptLPS(1);
  11171. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11172. if (item == null)
  11173. {
  11174. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  11175. return String.Empty;
  11176. }
  11177. return item.CreatorID.ToString();
  11178. }
  11179. public void llOwnerSay(string msg)
  11180. {
  11181. m_host.AddScriptLPS(1);
  11182. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  11183. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  11184. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  11185. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  11186. }
  11187. public LSL_Key llRequestSecureURL()
  11188. {
  11189. m_host.AddScriptLPS(1);
  11190. if (m_UrlModule != null)
  11191. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11192. return ScriptBaseClass.NULL_KEY;
  11193. }
  11194. public LSL_Key llRequestSimulatorData(string simulator, int data)
  11195. {
  11196. try
  11197. {
  11198. m_host.AddScriptLPS(1);
  11199. if (World.RegionInfo.RegionName == simulator)
  11200. {
  11201. string lreply = String.Empty;
  11202. GridRegion linfo = new GridRegion(World.RegionInfo);
  11203. switch (data)
  11204. {
  11205. case ScriptBaseClass.DATA_SIM_POS:
  11206. {
  11207. lreply = new LSL_Vector(
  11208. linfo.RegionLocX,
  11209. linfo.RegionLocY,
  11210. 0).ToString();
  11211. }
  11212. break;
  11213. case ScriptBaseClass.DATA_SIM_STATUS:
  11214. lreply = "up"; // Duh!
  11215. break;
  11216. case ScriptBaseClass.DATA_SIM_RATING:
  11217. int access = linfo.Maturity;
  11218. if (access == 0)
  11219. lreply = "PG";
  11220. else if (access == 1)
  11221. lreply = "MATURE";
  11222. else if (access == 2)
  11223. lreply = "ADULT";
  11224. else
  11225. lreply = "UNKNOWN";
  11226. break;
  11227. case ScriptBaseClass.DATA_SIM_RELEASE:
  11228. lreply = "OpenSim";
  11229. break;
  11230. default:
  11231. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11232. return ScriptBaseClass.NULL_KEY; // Raise no event
  11233. }
  11234. string ltid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  11235. m_item.ItemID, lreply);
  11236. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11237. return ltid;
  11238. }
  11239. Action<string> act = eventID =>
  11240. {
  11241. GridRegion info = World.GridService.GetRegionByName(RegionScopeID, simulator);
  11242. string reply = "unknown";
  11243. if (info != null)
  11244. {
  11245. switch (data)
  11246. {
  11247. case ScriptBaseClass.DATA_SIM_POS:
  11248. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  11249. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  11250. // anything is present we need to disambiguate.
  11251. //
  11252. // FIXME: Hypergrid should be storing this data in a different field.
  11253. RegionFlags regionFlags = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  11254. info.ScopeID, info.RegionID);
  11255. if ((regionFlags & RegionFlags.Hyperlink) != 0)
  11256. {
  11257. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out uint rx, out uint ry);
  11258. reply = new LSL_Vector(rx, ry, 0).ToString();
  11259. }
  11260. else
  11261. {
  11262. // Local grid co-oridnates
  11263. reply = new LSL_Vector(info.RegionLocX, info.RegionLocY, 0).ToString();
  11264. }
  11265. break;
  11266. case ScriptBaseClass.DATA_SIM_STATUS:
  11267. reply = "up"; // Duh!
  11268. break;
  11269. case ScriptBaseClass.DATA_SIM_RATING:
  11270. int access = info.Maturity;
  11271. if (access == 0)
  11272. reply = "PG";
  11273. else if (access == 1)
  11274. reply = "MATURE";
  11275. else if (access == 2)
  11276. reply = "ADULT";
  11277. else
  11278. reply = "UNKNOWN";
  11279. break;
  11280. case ScriptBaseClass.DATA_SIM_RELEASE:
  11281. reply = "OpenSim";
  11282. break;
  11283. default:
  11284. break;
  11285. }
  11286. }
  11287. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  11288. };
  11289. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(
  11290. m_host.LocalId, m_item.ItemID, act);
  11291. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11292. return tid.ToString();
  11293. }
  11294. catch(Exception)
  11295. {
  11296. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  11297. return ScriptBaseClass.NULL_KEY;
  11298. }
  11299. }
  11300. public LSL_Key llRequestURL()
  11301. {
  11302. m_host.AddScriptLPS(1);
  11303. if (m_UrlModule != null)
  11304. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11305. return ScriptBaseClass.NULL_KEY;
  11306. }
  11307. public void llForceMouselook(int mouselook)
  11308. {
  11309. m_host.AddScriptLPS(1);
  11310. m_host.SetForceMouselook(mouselook != 0);
  11311. }
  11312. public LSL_Float llGetObjectMass(LSL_Key id)
  11313. {
  11314. m_host.AddScriptLPS(1);
  11315. UUID key = new UUID();
  11316. if (!UUID.TryParse(id, out key))
  11317. return 0;
  11318. // return total object mass
  11319. SceneObjectPart part = World.GetSceneObjectPart(key);
  11320. if (part != null)
  11321. return part.ParentGroup.GetMass();
  11322. // the object is null so the key is for an avatar
  11323. ScenePresence avatar = World.GetScenePresence(key);
  11324. if (avatar != null)
  11325. {
  11326. if (avatar.IsChildAgent)
  11327. {
  11328. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  11329. // child agents have a mass of 1.0
  11330. return 1;
  11331. }
  11332. else
  11333. {
  11334. return avatar.GetMass();
  11335. }
  11336. }
  11337. return 0;
  11338. }
  11339. /// <summary>
  11340. /// llListReplaceList removes the sub-list defined by the inclusive indices
  11341. /// start and end and inserts the src list in its place. The inclusive
  11342. /// nature of the indices means that at least one element must be deleted
  11343. /// if the indices are within the bounds of the existing list. I.e. 2,2
  11344. /// will remove the element at index 2 and replace it with the source
  11345. /// list. Both indices may be negative, with the usual interpretation. An
  11346. /// interesting case is where end is lower than start. As these indices
  11347. /// bound the list to be removed, then 0->end, and start->lim are removed
  11348. /// and the source list is added as a suffix.
  11349. /// </summary>
  11350. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  11351. {
  11352. LSL_List pref;
  11353. m_host.AddScriptLPS(1);
  11354. // Note that although we have normalized, both
  11355. // indices could still be negative.
  11356. if (start < 0)
  11357. {
  11358. start = start+dest.Length;
  11359. }
  11360. if (end < 0)
  11361. {
  11362. end = end+dest.Length;
  11363. }
  11364. // The comventional case, remove a sequence starting with
  11365. // start and ending with end. And then insert the source
  11366. // list.
  11367. if (start <= end)
  11368. {
  11369. // If greater than zero, then there is going to be a
  11370. // surviving prefix. Otherwise the inclusive nature
  11371. // of the indices mean that we're going to add the
  11372. // source list as a prefix.
  11373. if (start > 0)
  11374. {
  11375. pref = dest.GetSublist(0,start-1);
  11376. // Only add a suffix if there is something
  11377. // beyond the end index (it's inclusive too).
  11378. if (end + 1 < dest.Length)
  11379. {
  11380. return pref + src + dest.GetSublist(end + 1, -1);
  11381. }
  11382. else
  11383. {
  11384. return pref + src;
  11385. }
  11386. }
  11387. // If start is less than or equal to zero, then
  11388. // the new list is simply a prefix. We still need to
  11389. // figure out any necessary surgery to the destination
  11390. // based upon end. Note that if end exceeds the upper
  11391. // bound in this case, the entire destination list
  11392. // is removed.
  11393. else if (start == 0)
  11394. {
  11395. if (end + 1 < dest.Length)
  11396. return src + dest.GetSublist(end + 1, -1);
  11397. else
  11398. return src;
  11399. }
  11400. else // Start < 0
  11401. {
  11402. if (end + 1 < dest.Length)
  11403. return dest.GetSublist(end + 1, -1);
  11404. else
  11405. return new LSL_List();
  11406. }
  11407. }
  11408. // Finally, if start > end, we strip away a prefix and
  11409. // a suffix, to leave the list that sits <between> ens
  11410. // and start, and then tag on the src list. AT least
  11411. // that's my interpretation. We can get sublist to do
  11412. // this for us. Note that one, or both of the indices
  11413. // might have been negative.
  11414. else
  11415. {
  11416. return dest.GetSublist(end + 1, start - 1) + src;
  11417. }
  11418. }
  11419. public void llLoadURL(string avatar_id, string message, string url)
  11420. {
  11421. m_host.AddScriptLPS(1);
  11422. if(m_host.OwnerID == m_host.GroupID)
  11423. return;
  11424. try
  11425. {
  11426. Uri m_checkuri = new Uri(url);
  11427. if (m_checkuri.Scheme != Uri.UriSchemeHttp && m_checkuri.Scheme != Uri.UriSchemeHttps)
  11428. {
  11429. Error("llLoadURL","Invalid url schema");
  11430. ScriptSleep(200);
  11431. return;
  11432. }
  11433. }
  11434. catch
  11435. {
  11436. Error("llLoadURL","Invalid url");
  11437. ScriptSleep(200);
  11438. return;
  11439. }
  11440. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  11441. if (null != dm)
  11442. dm.SendUrlToUser(
  11443. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  11444. ScriptSleep(m_sleepMsOnLoadURL);
  11445. }
  11446. public void llParcelMediaCommandList(LSL_List commandList)
  11447. {
  11448. // TODO: Not implemented yet (missing in libomv?):
  11449. // PARCEL_MEDIA_COMMAND_LOOP_SET float loop Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
  11450. m_host.AddScriptLPS(1);
  11451. // according to the docs, this command only works if script owner and land owner are the same
  11452. // lets add estate owners and gods, too, and use the generic permission check.
  11453. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11454. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false)) return;
  11455. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  11456. byte loop = 0;
  11457. LandData landData = landObject.LandData;
  11458. string url = landData.MediaURL;
  11459. string texture = landData.MediaID.ToString();
  11460. bool autoAlign = landData.MediaAutoScale != 0;
  11461. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  11462. string description = "";
  11463. int width = 0;
  11464. int height = 0;
  11465. ParcelMediaCommandEnum? commandToSend = null;
  11466. float time = 0.0f; // default is from start
  11467. uint cmndFlags = 0;
  11468. ScenePresence presence = null;
  11469. int cmd;
  11470. for (int i = 0; i < commandList.Data.Length; i++)
  11471. {
  11472. if(commandList.Data[i] is LSL_Integer)
  11473. cmd = (LSL_Integer)commandList.Data[i];
  11474. else
  11475. cmd = (int)commandList.Data[i];
  11476. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)cmd;
  11477. switch (command)
  11478. {
  11479. case ParcelMediaCommandEnum.Agent:
  11480. // we send only to one agent
  11481. if ((i + 1) < commandList.Length)
  11482. {
  11483. if (commandList.Data[i + 1] is LSL_String)
  11484. {
  11485. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out UUID agentID))
  11486. {
  11487. presence = World.GetScenePresence(agentID);
  11488. if(presence == null || presence.IsNPC)
  11489. return;
  11490. }
  11491. }
  11492. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  11493. ++i;
  11494. }
  11495. break;
  11496. case ParcelMediaCommandEnum.Loop:
  11497. loop = 1;
  11498. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_LOOP);
  11499. commandToSend = command;
  11500. update = true; //need to send the media update packet to set looping
  11501. break;
  11502. case ParcelMediaCommandEnum.Play:
  11503. loop = 0;
  11504. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PLAY);
  11505. commandToSend = command;
  11506. update = true; //need to send the media update packet to make sure it doesn't loop
  11507. break;
  11508. case ParcelMediaCommandEnum.Pause:
  11509. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PAUSE);
  11510. commandToSend = command;
  11511. break;
  11512. case ParcelMediaCommandEnum.Stop:
  11513. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_STOP);
  11514. commandToSend = command;
  11515. break;
  11516. case ParcelMediaCommandEnum.Unload:
  11517. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_UNLOAD);
  11518. commandToSend = command;
  11519. break;
  11520. case ParcelMediaCommandEnum.Url:
  11521. if ((i + 1) < commandList.Length)
  11522. {
  11523. if (commandList.Data[i + 1] is LSL_String)
  11524. {
  11525. url = (LSL_String)commandList.Data[i + 1];
  11526. if(string.IsNullOrWhiteSpace(url))
  11527. url = string.Empty;
  11528. else
  11529. {
  11530. try
  11531. {
  11532. Uri dummy = new Uri(url, UriKind.Absolute);
  11533. }
  11534. catch
  11535. {
  11536. Error("llParcelMediaCommandList", "invalid PARCEL_MEDIA_COMMAND_URL");
  11537. return;
  11538. }
  11539. }
  11540. update = true;
  11541. }
  11542. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  11543. ++i;
  11544. }
  11545. break;
  11546. case ParcelMediaCommandEnum.Texture:
  11547. if ((i + 1) < commandList.Length)
  11548. {
  11549. if (commandList.Data[i + 1] is LSL_String)
  11550. {
  11551. texture = (LSL_String)commandList.Data[i + 1];
  11552. update = true;
  11553. }
  11554. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  11555. ++i;
  11556. }
  11557. break;
  11558. case ParcelMediaCommandEnum.Time:
  11559. if ((i + 1) < commandList.Length)
  11560. {
  11561. if (commandList.Data[i + 1] is LSL_Float)
  11562. {
  11563. time = (float)(LSL_Float)commandList.Data[i + 1];
  11564. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_TIME);
  11565. }
  11566. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  11567. ++i;
  11568. }
  11569. break;
  11570. case ParcelMediaCommandEnum.AutoAlign:
  11571. if ((i + 1) < commandList.Length)
  11572. {
  11573. if (commandList.Data[i + 1] is LSL_Integer)
  11574. {
  11575. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  11576. update = true;
  11577. }
  11578. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  11579. ++i;
  11580. }
  11581. break;
  11582. case ParcelMediaCommandEnum.Type:
  11583. if ((i + 1) < commandList.Length)
  11584. {
  11585. if (commandList.Data[i + 1] is LSL_String)
  11586. {
  11587. mediaType = (LSL_String)commandList.Data[i + 1];
  11588. update = true;
  11589. }
  11590. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  11591. ++i;
  11592. }
  11593. break;
  11594. case ParcelMediaCommandEnum.Desc:
  11595. if ((i + 1) < commandList.Length)
  11596. {
  11597. if (commandList.Data[i + 1] is LSL_String)
  11598. {
  11599. description = (LSL_String)commandList.Data[i + 1];
  11600. update = true;
  11601. }
  11602. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  11603. ++i;
  11604. }
  11605. break;
  11606. case ParcelMediaCommandEnum.Size:
  11607. if ((i + 2) < commandList.Length)
  11608. {
  11609. if (commandList.Data[i + 1] is LSL_Integer)
  11610. {
  11611. if (commandList.Data[i + 2] is LSL_Integer)
  11612. {
  11613. width = (LSL_Integer)commandList.Data[i + 1];
  11614. height = (LSL_Integer)commandList.Data[i + 2];
  11615. update = true;
  11616. }
  11617. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11618. }
  11619. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11620. i += 2;
  11621. }
  11622. break;
  11623. default:
  11624. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  11625. break;
  11626. }//end switch
  11627. }//end for
  11628. // if we didn't get a presence, we send to all and change the url
  11629. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  11630. // did something important change or do we only start/stop/pause?
  11631. if (update)
  11632. {
  11633. if (presence == null)
  11634. {
  11635. // we send to all
  11636. landData.MediaID = new UUID(texture);
  11637. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  11638. landData.MediaWidth = width;
  11639. landData.MediaHeight = height;
  11640. landData.MediaType = mediaType;
  11641. // do that one last, it will cause a ParcelPropertiesUpdate
  11642. landObject.SetMediaUrl(url);
  11643. // now send to all (non-child) agents in the parcel
  11644. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11645. {
  11646. if (sp.currentParcelUUID == landData.GlobalID)
  11647. {
  11648. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  11649. landData.MediaID,
  11650. landData.MediaAutoScale,
  11651. mediaType,
  11652. description,
  11653. width, height,
  11654. loop);
  11655. }
  11656. });
  11657. }
  11658. else if (!presence.IsChildAgent)
  11659. {
  11660. // we only send to one (root) agent
  11661. presence.ControllingClient.SendParcelMediaUpdate(url,
  11662. new UUID(texture),
  11663. autoAlign ? (byte)1 : (byte)0,
  11664. mediaType,
  11665. description,
  11666. width, height,
  11667. loop);
  11668. }
  11669. }
  11670. if (commandToSend != null)
  11671. {
  11672. // the commandList contained a start/stop/... command, too
  11673. if (presence == null)
  11674. {
  11675. // send to all (non-child) agents in the parcel
  11676. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11677. {
  11678. if (sp.currentParcelUUID == landData.GlobalID)
  11679. {
  11680. sp.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11681. commandToSend.Value, time);
  11682. }
  11683. });
  11684. }
  11685. else if (!presence.IsChildAgent)
  11686. {
  11687. presence.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11688. commandToSend.Value, time);
  11689. }
  11690. }
  11691. ScriptSleep(m_sleepMsOnParcelMediaCommandList);
  11692. }
  11693. public LSL_List llParcelMediaQuery(LSL_List aList)
  11694. {
  11695. m_host.AddScriptLPS(1);
  11696. LSL_List list = new LSL_List();
  11697. Vector3 pos = m_host.AbsolutePosition;
  11698. ILandObject landObject = World.LandChannel.GetLandObject(pos);
  11699. if(landObject == null)
  11700. return list;
  11701. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false))
  11702. return list;
  11703. LandData land = landObject.LandData;
  11704. if(land == null)
  11705. return list;
  11706. //TO DO: make the implementation for the missing commands
  11707. //PARCEL_MEDIA_COMMAND_LOOP_SET float loop Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
  11708. for (int i = 0; i < aList.Data.Length; i++)
  11709. {
  11710. if (aList.Data[i] != null)
  11711. {
  11712. switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
  11713. {
  11714. case ParcelMediaCommandEnum.Url:
  11715. list.Add(new LSL_String(land.MediaURL));
  11716. break;
  11717. case ParcelMediaCommandEnum.Desc:
  11718. list.Add(new LSL_String(land.MediaDescription));
  11719. break;
  11720. case ParcelMediaCommandEnum.Texture:
  11721. list.Add(new LSL_String(land.MediaID.ToString()));
  11722. break;
  11723. case ParcelMediaCommandEnum.Type:
  11724. list.Add(new LSL_String(land.MediaType));
  11725. break;
  11726. case ParcelMediaCommandEnum.Size:
  11727. list.Add(new LSL_String(land.MediaWidth));
  11728. list.Add(new LSL_String(land.MediaHeight));
  11729. break;
  11730. default:
  11731. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  11732. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  11733. break;
  11734. }
  11735. }
  11736. }
  11737. ScriptSleep(m_sleepMsOnParcelMediaQuery);
  11738. return list;
  11739. }
  11740. public LSL_Integer llModPow(int a, int b, int c)
  11741. {
  11742. m_host.AddScriptLPS(1);
  11743. Math.DivRem((long)Math.Pow(a, b), c, out long tmp);
  11744. ScriptSleep(m_sleepMsOnModPow);
  11745. return (int)tmp;
  11746. }
  11747. public LSL_Integer llGetInventoryType(string name)
  11748. {
  11749. m_host.AddScriptLPS(1);
  11750. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11751. if (item == null)
  11752. return -1;
  11753. return item.Type;
  11754. }
  11755. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  11756. {
  11757. m_host.AddScriptLPS(1);
  11758. if(m_host.LocalId != m_host.ParentGroup.RootPart.LocalId)
  11759. return;
  11760. if (quick_pay_buttons.Data.Length < 4)
  11761. {
  11762. int x;
  11763. for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
  11764. {
  11765. quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
  11766. }
  11767. }
  11768. int[] nPrice = new int[5];
  11769. nPrice[0] = price;
  11770. nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
  11771. nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
  11772. nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
  11773. nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
  11774. m_host.ParentGroup.RootPart.PayPrice = nPrice;
  11775. m_host.ParentGroup.HasGroupChanged = true;
  11776. }
  11777. public LSL_Vector llGetCameraPos()
  11778. {
  11779. m_host.AddScriptLPS(1);
  11780. if (m_item.PermsGranter == UUID.Zero)
  11781. return Vector3.Zero;
  11782. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11783. {
  11784. Error("llGetCameraPos", "No permissions to track the camera");
  11785. return Vector3.Zero;
  11786. }
  11787. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11788. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11789. if (presence != null)
  11790. {
  11791. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  11792. return pos;
  11793. }
  11794. return Vector3.Zero;
  11795. }
  11796. public LSL_Rotation llGetCameraRot()
  11797. {
  11798. m_host.AddScriptLPS(1);
  11799. if (m_item.PermsGranter == UUID.Zero)
  11800. return Quaternion.Identity;
  11801. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11802. {
  11803. Error("llGetCameraRot", "No permissions to track the camera");
  11804. return Quaternion.Identity;
  11805. }
  11806. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11807. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11808. if (presence != null)
  11809. {
  11810. return new LSL_Rotation(presence.CameraRotation);
  11811. }
  11812. return Quaternion.Identity;
  11813. }
  11814. public void llSetPrimURL(string url)
  11815. {
  11816. m_host.AddScriptLPS(1);
  11817. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  11818. ScriptSleep(m_sleepMsOnSetPrimURL);
  11819. }
  11820. public void llRefreshPrimURL()
  11821. {
  11822. m_host.AddScriptLPS(1);
  11823. Deprecated("llRefreshPrimURL");
  11824. ScriptSleep(m_sleepMsOnRefreshPrimURL);
  11825. }
  11826. public LSL_String llEscapeURL(string url)
  11827. {
  11828. m_host.AddScriptLPS(1);
  11829. try
  11830. {
  11831. return Uri.EscapeDataString(url);
  11832. }
  11833. catch (Exception ex)
  11834. {
  11835. return "llEscapeURL: " + ex.ToString();
  11836. }
  11837. }
  11838. public LSL_String llUnescapeURL(string url)
  11839. {
  11840. m_host.AddScriptLPS(1);
  11841. try
  11842. {
  11843. return Uri.UnescapeDataString(url);
  11844. }
  11845. catch (Exception ex)
  11846. {
  11847. return "llUnescapeURL: " + ex.ToString();
  11848. }
  11849. }
  11850. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  11851. {
  11852. m_host.AddScriptLPS(1);
  11853. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  11854. if (detectedParams == null)
  11855. {
  11856. if (m_host.ParentGroup.IsAttachment == true)
  11857. {
  11858. detectedParams = new DetectParams
  11859. {
  11860. Key = m_host.OwnerID
  11861. };
  11862. }
  11863. else
  11864. {
  11865. return;
  11866. }
  11867. }
  11868. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  11869. if (avatar != null)
  11870. {
  11871. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  11872. simname, pos, lookAt);
  11873. }
  11874. ScriptSleep(m_sleepMsOnMapDestination);
  11875. }
  11876. public void llAddToLandBanList(LSL_Key avatar, LSL_Float hours)
  11877. {
  11878. m_host.AddScriptLPS(1);
  11879. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11880. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11881. {
  11882. int expires = 0;
  11883. if (hours != 0)
  11884. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  11885. if (UUID.TryParse(avatar, out UUID key))
  11886. {
  11887. int idx = land.LandData.ParcelAccessList.FindIndex(
  11888. delegate(LandAccessEntry e)
  11889. {
  11890. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11891. return true;
  11892. return false;
  11893. });
  11894. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  11895. return;
  11896. if (idx != -1)
  11897. land.LandData.ParcelAccessList.RemoveAt(idx);
  11898. LandAccessEntry entry = new LandAccessEntry
  11899. {
  11900. AgentID = key,
  11901. Flags = AccessList.Ban,
  11902. Expires = expires
  11903. };
  11904. land.LandData.ParcelAccessList.Add(entry);
  11905. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11906. }
  11907. }
  11908. ScriptSleep(m_sleepMsOnAddToLandBanList);
  11909. }
  11910. public void llRemoveFromLandPassList(string avatar)
  11911. {
  11912. m_host.AddScriptLPS(1);
  11913. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11914. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  11915. {
  11916. if (UUID.TryParse(avatar, out UUID key))
  11917. {
  11918. int idx = land.LandData.ParcelAccessList.FindIndex(
  11919. delegate(LandAccessEntry e)
  11920. {
  11921. if (e.AgentID == key && e.Flags == AccessList.Access)
  11922. return true;
  11923. return false;
  11924. });
  11925. if (idx != -1)
  11926. {
  11927. land.LandData.ParcelAccessList.RemoveAt(idx);
  11928. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11929. }
  11930. }
  11931. }
  11932. ScriptSleep(m_sleepMsOnRemoveFromLandPassList);
  11933. }
  11934. public void llRemoveFromLandBanList(string avatar)
  11935. {
  11936. m_host.AddScriptLPS(1);
  11937. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11938. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11939. {
  11940. if (UUID.TryParse(avatar, out UUID key))
  11941. {
  11942. int idx = land.LandData.ParcelAccessList.FindIndex(
  11943. delegate(LandAccessEntry e)
  11944. {
  11945. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11946. return true;
  11947. return false;
  11948. });
  11949. if (idx != -1)
  11950. {
  11951. land.LandData.ParcelAccessList.RemoveAt(idx);
  11952. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11953. }
  11954. }
  11955. }
  11956. ScriptSleep(m_sleepMsOnRemoveFromLandBanList);
  11957. }
  11958. public void llSetCameraParams(LSL_List rules)
  11959. {
  11960. m_host.AddScriptLPS(1);
  11961. // the object we are in
  11962. UUID objectID = m_host.ParentUUID;
  11963. if (objectID == UUID.Zero)
  11964. return;
  11965. // we need the permission first, to know which avatar we want to set the camera for
  11966. UUID agentID = m_item.PermsGranter;
  11967. if (agentID == UUID.Zero)
  11968. return;
  11969. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11970. return;
  11971. ScenePresence presence = World.GetScenePresence(agentID);
  11972. // we are not interested in child-agents
  11973. if (presence.IsChildAgent) return;
  11974. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  11975. object[] data = rules.Data;
  11976. for (int i = 0; i < data.Length; ++i)
  11977. {
  11978. int type;
  11979. try
  11980. {
  11981. type = Convert.ToInt32(data[i++].ToString());
  11982. }
  11983. catch
  11984. {
  11985. Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
  11986. return;
  11987. }
  11988. if (i >= data.Length) break; // odd number of entries => ignore the last
  11989. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  11990. switch (type)
  11991. {
  11992. case ScriptBaseClass.CAMERA_FOCUS:
  11993. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11994. case ScriptBaseClass.CAMERA_POSITION:
  11995. LSL_Vector v = (LSL_Vector)data[i];
  11996. try
  11997. {
  11998. parameters.Add(type + 1, (float)v.x);
  11999. }
  12000. catch
  12001. {
  12002. switch(type)
  12003. {
  12004. case ScriptBaseClass.CAMERA_FOCUS:
  12005. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
  12006. return;
  12007. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12008. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
  12009. return;
  12010. case ScriptBaseClass.CAMERA_POSITION:
  12011. Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
  12012. return;
  12013. }
  12014. }
  12015. try
  12016. {
  12017. parameters.Add(type + 2, (float)v.y);
  12018. }
  12019. catch
  12020. {
  12021. switch(type)
  12022. {
  12023. case ScriptBaseClass.CAMERA_FOCUS:
  12024. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
  12025. return;
  12026. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12027. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
  12028. return;
  12029. case ScriptBaseClass.CAMERA_POSITION:
  12030. Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
  12031. return;
  12032. }
  12033. }
  12034. try
  12035. {
  12036. parameters.Add(type + 3, (float)v.z);
  12037. }
  12038. catch
  12039. {
  12040. switch(type)
  12041. {
  12042. case ScriptBaseClass.CAMERA_FOCUS:
  12043. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
  12044. return;
  12045. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12046. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
  12047. return;
  12048. case ScriptBaseClass.CAMERA_POSITION:
  12049. Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
  12050. return;
  12051. }
  12052. }
  12053. break;
  12054. default:
  12055. // TODO: clean that up as soon as the implicit casts are in
  12056. if (data[i] is LSL_Float)
  12057. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  12058. else if (data[i] is LSL_Integer)
  12059. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  12060. else
  12061. {
  12062. try
  12063. {
  12064. parameters.Add(type, Convert.ToSingle(data[i]));
  12065. }
  12066. catch
  12067. {
  12068. Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
  12069. }
  12070. }
  12071. break;
  12072. }
  12073. }
  12074. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  12075. }
  12076. public void llClearCameraParams()
  12077. {
  12078. m_host.AddScriptLPS(1);
  12079. // the object we are in
  12080. UUID objectID = m_host.ParentUUID;
  12081. if (objectID == UUID.Zero)
  12082. return;
  12083. // we need the permission first, to know which avatar we want to clear the camera for
  12084. UUID agentID = m_item.PermsGranter;
  12085. if (agentID == UUID.Zero)
  12086. return;
  12087. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  12088. return;
  12089. ScenePresence presence = World.GetScenePresence(agentID);
  12090. // we are not interested in child-agents
  12091. if (presence.IsChildAgent)
  12092. return;
  12093. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  12094. }
  12095. public LSL_Float llListStatistics(int operation, LSL_List src)
  12096. {
  12097. m_host.AddScriptLPS(1);
  12098. switch (operation)
  12099. {
  12100. case ScriptBaseClass.LIST_STAT_RANGE:
  12101. return src.Range();
  12102. case ScriptBaseClass.LIST_STAT_MIN:
  12103. return src.Min();
  12104. case ScriptBaseClass.LIST_STAT_MAX:
  12105. return src.Max();
  12106. case ScriptBaseClass.LIST_STAT_MEAN:
  12107. return src.Mean();
  12108. case ScriptBaseClass.LIST_STAT_MEDIAN:
  12109. return LSL_List.ToDoubleList(src).Median();
  12110. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  12111. return src.NumericLength();
  12112. case ScriptBaseClass.LIST_STAT_STD_DEV:
  12113. return src.StdDev();
  12114. case ScriptBaseClass.LIST_STAT_SUM:
  12115. return src.Sum();
  12116. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  12117. return src.SumSqrs();
  12118. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  12119. return src.GeometricMean();
  12120. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  12121. return src.HarmonicMean();
  12122. default:
  12123. return 0.0;
  12124. }
  12125. }
  12126. public LSL_Integer llGetUnixTime()
  12127. {
  12128. m_host.AddScriptLPS(1);
  12129. return Util.UnixTimeSinceEpoch();
  12130. }
  12131. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  12132. {
  12133. m_host.AddScriptLPS(1);
  12134. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  12135. }
  12136. public LSL_Integer llGetRegionFlags()
  12137. {
  12138. m_host.AddScriptLPS(1);
  12139. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  12140. if (estate == null)
  12141. return 67108864;
  12142. return (int)estate.GetRegionFlags();
  12143. }
  12144. private const string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  12145. public LSL_String llXorBase64Strings(string str1, string str2)
  12146. {
  12147. int padding = 0;
  12148. ScriptSleep(300);
  12149. m_host.AddScriptLPS(1);
  12150. if (str1 == string.Empty)
  12151. return string.Empty;
  12152. if (str2 == string.Empty)
  12153. return str1;
  12154. int len = str2.Length;
  12155. if ((len % 4) != 0) // LL is EVIL!!!!
  12156. {
  12157. while (str2.EndsWith("="))
  12158. str2 = str2.Substring(0, str2.Length - 1);
  12159. len = str2.Length;
  12160. int mod = len % 4;
  12161. if (mod == 1)
  12162. str2 = str2.Substring(0, str2.Length - 1);
  12163. else if (mod == 2)
  12164. str2 += "==";
  12165. else if (mod == 3)
  12166. str2 += "=";
  12167. }
  12168. byte[] data1;
  12169. byte[] data2;
  12170. try
  12171. {
  12172. data1 = Convert.FromBase64String(str1);
  12173. data2 = Convert.FromBase64String(str2);
  12174. }
  12175. catch
  12176. {
  12177. return string.Empty;
  12178. }
  12179. // Remove padding
  12180. while (str1.EndsWith("="))
  12181. {
  12182. str1 = str1.Substring(0, str1.Length - 1);
  12183. padding++;
  12184. }
  12185. while (str2.EndsWith("="))
  12186. str2 = str2.Substring(0, str2.Length - 1);
  12187. byte[] d1 = new byte[str1.Length];
  12188. byte[] d2 = new byte[str2.Length];
  12189. for (int i = 0; i < str1.Length; i++)
  12190. {
  12191. int idx = b64.IndexOf(str1.Substring(i, 1));
  12192. if (idx == -1)
  12193. idx = 0;
  12194. d1[i] = (byte)idx;
  12195. }
  12196. for (int i = 0; i < str2.Length; i++)
  12197. {
  12198. int idx = b64.IndexOf(str2.Substring(i, 1));
  12199. if (idx == -1)
  12200. idx = 0;
  12201. d2[i] = (byte)idx;
  12202. }
  12203. string output = string.Empty;
  12204. for (int pos = 0; pos < d1.Length; pos++)
  12205. output += b64[d1[pos] ^ d2[pos % d2.Length]];
  12206. // Here's a funny thing: LL blithely violate the base64
  12207. // standard pretty much everywhere. Here, padding is
  12208. // added only if the first input string had it, rather
  12209. // than when the data actually needs it. This can result
  12210. // in invalid base64 being returned. Go figure.
  12211. while (padding-- > 0)
  12212. output += "=";
  12213. return output;
  12214. }
  12215. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  12216. {
  12217. m_host.AddScriptLPS(1);
  12218. if (str1 == string.Empty)
  12219. return string.Empty;
  12220. if (str2 == string.Empty)
  12221. return str1;
  12222. int len = str2.Length;
  12223. if ((len % 4) != 0) // LL is EVIL!!!!
  12224. {
  12225. str2.TrimEnd(new char[] { '=' });
  12226. len = str2.Length;
  12227. if(len == 0)
  12228. return str1;
  12229. int mod = len % 4;
  12230. if (mod == 1)
  12231. str2 = str2.Substring(0, len - 1);
  12232. else if (mod == 2)
  12233. str2 += "==";
  12234. else if (mod == 3)
  12235. str2 += "=";
  12236. }
  12237. byte[] data1;
  12238. byte[] data2;
  12239. try
  12240. {
  12241. data1 = Convert.FromBase64String(str1);
  12242. data2 = Convert.FromBase64String(str2);
  12243. }
  12244. catch (Exception)
  12245. {
  12246. return string.Empty;
  12247. }
  12248. int len2 = data2.Length;
  12249. if (len2 == 0)
  12250. return str1;
  12251. for (int pos = 0, pos2 = 0; pos < data1.Length; pos++)
  12252. {
  12253. data1[pos] ^= data2[pos2];
  12254. if (++pos2 >= len2)
  12255. pos2 = 0;
  12256. }
  12257. return Convert.ToBase64String(data1);
  12258. }
  12259. private string truncateBase64(string input)
  12260. {
  12261. if (string.IsNullOrEmpty(input))
  12262. return string.Empty;
  12263. int paddingPos = -1;
  12264. for (int i = 0; i < input.Length; i++)
  12265. {
  12266. char c = input[i];
  12267. if (c >= 'A' && c <= 'Z')
  12268. continue;
  12269. if (c >= 'a' && c <= 'z')
  12270. continue;
  12271. if (c >= '0' && c <= '9')
  12272. continue;
  12273. if (c == '+' || c == '/')
  12274. continue;
  12275. paddingPos = i;
  12276. break;
  12277. }
  12278. if (paddingPos == 0)
  12279. return string.Empty;
  12280. if (paddingPos > 0)
  12281. input = input.Substring(0, paddingPos);
  12282. int remainder = input.Length % 4;
  12283. switch(remainder)
  12284. {
  12285. case 0:
  12286. return input;
  12287. case 1:
  12288. return input.Substring(0, input.Length - 1);
  12289. case 2:
  12290. return input + "==";
  12291. }
  12292. return input + "=";
  12293. }
  12294. public LSL_String llXorBase64(string str1, string str2)
  12295. {
  12296. m_host.AddScriptLPS(1);
  12297. if (string.IsNullOrEmpty(str2))
  12298. return str1;
  12299. str1 = truncateBase64(str1);
  12300. if (string.IsNullOrEmpty(str1))
  12301. return string.Empty;
  12302. str2 = truncateBase64(str2);
  12303. if (string.IsNullOrEmpty(str2))
  12304. return str1;
  12305. byte[] data1;
  12306. byte[] data2;
  12307. try
  12308. {
  12309. data1 = Convert.FromBase64String(str1);
  12310. data2 = Convert.FromBase64String(str2);
  12311. }
  12312. catch (Exception)
  12313. {
  12314. return string.Empty;
  12315. }
  12316. int len2 = data2.Length;
  12317. if (len2 == 0)
  12318. return str1;
  12319. for (int pos = 0, pos2 = 0; pos < data1.Length; pos++)
  12320. {
  12321. data1[pos] ^= data2[pos2];
  12322. if (++pos2 >= len2)
  12323. pos2 = 0;
  12324. }
  12325. return Convert.ToBase64String(data1);
  12326. }
  12327. public LSL_Key llHTTPRequest(string url, LSL_List parameters, string body)
  12328. {
  12329. m_host.AddScriptLPS(1);
  12330. IHttpRequestModule httpScriptMod = m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  12331. if(httpScriptMod == null)
  12332. return string.Empty;
  12333. if(!httpScriptMod.CheckThrottle(m_host.LocalId, m_host.OwnerID))
  12334. return ScriptBaseClass.NULL_KEY;
  12335. try
  12336. {
  12337. Uri m_checkuri = new Uri(url);
  12338. if (m_checkuri.Scheme != Uri.UriSchemeHttp && m_checkuri.Scheme != Uri.UriSchemeHttps)
  12339. {
  12340. Error("llHTTPRequest", "Invalid url schema");
  12341. ScriptSleep(200);
  12342. return string.Empty;
  12343. }
  12344. }
  12345. catch
  12346. {
  12347. Error("llHTTPRequest", "Invalid url");
  12348. ScriptSleep(200);
  12349. return string.Empty;
  12350. }
  12351. List<string> param = new List<string>();
  12352. bool ok;
  12353. int nCustomHeaders = 0;
  12354. for (int i = 0; i < parameters.Data.Length; i += 2)
  12355. {
  12356. ok = Int32.TryParse(parameters.Data[i].ToString(), out int flag);
  12357. if (!ok || flag < 0 ||
  12358. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  12359. {
  12360. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  12361. }
  12362. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  12363. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  12364. {
  12365. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  12366. }
  12367. else
  12368. {
  12369. //Parameters are in pairs and custom header takes
  12370. //arguments in pairs so adjust for header marker.
  12371. ++i;
  12372. //Maximum of 8 headers are allowed based on the
  12373. //Second Life documentation for llHTTPRequest.
  12374. for (int count = 1; count <= 8; ++count)
  12375. {
  12376. if(nCustomHeaders >= 8)
  12377. {
  12378. Error("llHTTPRequest", "Max number of custom headers is 8, excess ignored");
  12379. break;
  12380. }
  12381. //Enough parameters remaining for (another) header?
  12382. if (parameters.Data.Length - i < 2)
  12383. {
  12384. //There must be at least one name/value pair for custom header
  12385. if (count == 1)
  12386. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  12387. break;
  12388. }
  12389. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString()))
  12390. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  12391. param.Add(parameters.Data[i].ToString());
  12392. param.Add(parameters.Data[i+1].ToString());
  12393. nCustomHeaders++;
  12394. //Have we reached the end of the list of headers?
  12395. //End is marked by a string with a single digit.
  12396. if (i + 2 >= parameters.Data.Length ||
  12397. Char.IsDigit(parameters.Data[i + 2].ToString()[0]))
  12398. {
  12399. break;
  12400. }
  12401. i += 2;
  12402. }
  12403. }
  12404. }
  12405. Vector3 position = m_host.AbsolutePosition;
  12406. Vector3 velocity = m_host.Velocity;
  12407. Quaternion rotation = m_host.GetWorldRotation();
  12408. string ownerName = string.Empty;
  12409. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  12410. if (scenePresence == null)
  12411. ownerName = resolveName(m_host.OwnerID);
  12412. else
  12413. ownerName = scenePresence.Name;
  12414. RegionInfo regionInfo = World.RegionInfo;
  12415. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  12416. if (!string.IsNullOrWhiteSpace(m_lsl_shard))
  12417. httpHeaders["X-SecondLife-Shard"] = m_lsl_shard;
  12418. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  12419. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  12420. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.WorldLocX, regionInfo.WorldLocY);
  12421. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  12422. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  12423. httpHeaders["X-SecondLife-Local-Rotation"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000})", rotation.X, rotation.Y, rotation.Z, rotation.W);
  12424. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  12425. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  12426. if (!string.IsNullOrWhiteSpace(m_lsl_user_agent))
  12427. httpHeaders["User-Agent"] = m_lsl_user_agent;
  12428. // See if the URL contains any header hacks
  12429. string[] urlParts = url.Split(new char[] {'\n'});
  12430. if (urlParts.Length > 1)
  12431. {
  12432. // Iterate the passed headers and parse them
  12433. for (int i = 1 ; i < urlParts.Length ; i++ )
  12434. {
  12435. // The rest of those would be added to the body in SL.
  12436. // Let's not do that.
  12437. if (urlParts[i] == string.Empty)
  12438. break;
  12439. // See if this could be a valid header
  12440. string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
  12441. if (headerParts.Length != 2)
  12442. continue;
  12443. string headerName = headerParts[0].Trim();
  12444. if(!HttpForbiddenInHeaders.Contains(headerName))
  12445. {
  12446. string headerValue = headerParts[1].Trim();
  12447. httpHeaders[headerName] = headerValue;
  12448. }
  12449. }
  12450. // Finally, strip any protocol specifier from the URL
  12451. url = urlParts[0].Trim();
  12452. int idx = url.IndexOf(" HTTP/");
  12453. if (idx != -1)
  12454. url = url.Substring(0, idx);
  12455. }
  12456. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  12457. Regex r = new Regex(authregex);
  12458. int[] gnums = r.GetGroupNumbers();
  12459. Match m = r.Match(url);
  12460. if (m.Success)
  12461. {
  12462. for (int i = 1; i < gnums.Length; i++)
  12463. {
  12464. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  12465. //CaptureCollection cc = g.Captures;
  12466. }
  12467. if (m.Groups.Count == 5)
  12468. {
  12469. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  12470. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  12471. }
  12472. }
  12473. UUID reqID = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body,
  12474. out HttpInitialRequestStatus status);
  12475. if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER)
  12476. Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url));
  12477. if (reqID != UUID.Zero)
  12478. return reqID.ToString();
  12479. else
  12480. return "";
  12481. }
  12482. public void llHTTPResponse(LSL_Key id, int status, string body)
  12483. {
  12484. // Partial implementation: support for parameter flags needed
  12485. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  12486. m_host.AddScriptLPS(1);
  12487. if (m_UrlModule != null)
  12488. m_UrlModule.HttpResponse(new UUID(id), status,body);
  12489. }
  12490. public void llResetLandBanList()
  12491. {
  12492. m_host.AddScriptLPS(1);
  12493. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12494. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12495. {
  12496. var todelete = new List<LandAccessEntry>();
  12497. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12498. {
  12499. if (entry.Flags == AccessList.Ban)
  12500. todelete.Add(entry);
  12501. }
  12502. foreach (LandAccessEntry entry in todelete)
  12503. land.ParcelAccessList.Remove(entry);
  12504. }
  12505. ScriptSleep(m_sleepMsOnResetLandBanList);
  12506. }
  12507. public void llResetLandPassList()
  12508. {
  12509. m_host.AddScriptLPS(1);
  12510. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12511. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12512. {
  12513. var todelete = new List<LandAccessEntry>();
  12514. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12515. {
  12516. if (entry.Flags == AccessList.Access)
  12517. todelete.Add(entry);
  12518. }
  12519. foreach (LandAccessEntry entry in todelete)
  12520. land.ParcelAccessList.Remove(entry);
  12521. }
  12522. ScriptSleep(m_sleepMsOnResetLandPassList);
  12523. }
  12524. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  12525. {
  12526. m_host.AddScriptLPS(1);
  12527. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12528. if (lo == null)
  12529. return 0;
  12530. IPrimCounts pc = lo.PrimCounts;
  12531. if (sim_wide != ScriptBaseClass.FALSE)
  12532. {
  12533. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12534. {
  12535. return pc.Simulator;
  12536. }
  12537. else
  12538. {
  12539. // counts not implemented yet
  12540. return 0;
  12541. }
  12542. }
  12543. else
  12544. {
  12545. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12546. return pc.Total;
  12547. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  12548. return pc.Owner;
  12549. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  12550. return pc.Group;
  12551. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  12552. return pc.Others;
  12553. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  12554. return pc.Selected;
  12555. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  12556. return 0; // counts not implemented yet
  12557. }
  12558. return 0;
  12559. }
  12560. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  12561. {
  12562. m_host.AddScriptLPS(1);
  12563. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12564. LSL_List ret = new LSL_List();
  12565. if (land != null)
  12566. {
  12567. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  12568. {
  12569. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  12570. ret.Add(new LSL_Integer(detectedParams.Value));
  12571. }
  12572. }
  12573. ScriptSleep(m_sleepMsOnGetParcelPrimOwners);
  12574. return ret;
  12575. }
  12576. public LSL_Integer llGetObjectPrimCount(LSL_Key object_id)
  12577. {
  12578. m_host.AddScriptLPS(1);
  12579. if(!UUID.TryParse(object_id, out UUID id))
  12580. return 0;
  12581. SceneObjectPart part = World.GetSceneObjectPart(id);
  12582. if (part == null)
  12583. return 0;
  12584. return part.ParentGroup.PrimCount;
  12585. }
  12586. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  12587. {
  12588. m_host.AddScriptLPS(1);
  12589. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12590. if (lo == null)
  12591. return 0;
  12592. if (sim_wide != 0)
  12593. return lo.GetSimulatorMaxPrimCount();
  12594. else
  12595. return lo.GetParcelMaxPrimCount();
  12596. }
  12597. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  12598. {
  12599. m_host.AddScriptLPS(1);
  12600. LandData land = World.GetLandData(pos);
  12601. if (land == null)
  12602. {
  12603. return new LSL_List(0);
  12604. }
  12605. LSL_List ret = new LSL_List();
  12606. foreach (object o in param.Data)
  12607. {
  12608. switch (o.ToString())
  12609. {
  12610. case "0":
  12611. ret.Add(new LSL_String(land.Name));
  12612. break;
  12613. case "1":
  12614. ret.Add(new LSL_String(land.Description));
  12615. break;
  12616. case "2":
  12617. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  12618. break;
  12619. case "3":
  12620. ret.Add(new LSL_Key(land.GroupID.ToString()));
  12621. break;
  12622. case "4":
  12623. ret.Add(new LSL_Integer(land.Area));
  12624. break;
  12625. case "5":
  12626. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  12627. break;
  12628. case "64":
  12629. ret.Add(new LSL_Integer(land.Dwell));
  12630. break;
  12631. default:
  12632. ret.Add(new LSL_Integer(0));
  12633. break;
  12634. }
  12635. }
  12636. return ret;
  12637. }
  12638. public LSL_String llStringTrim(LSL_String src, LSL_Integer type)
  12639. {
  12640. m_host.AddScriptLPS(1);
  12641. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return ((string)src).TrimStart(); }
  12642. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return ((string)src).TrimEnd(); }
  12643. if (type == (int)ScriptBaseClass.STRING_TRIM) { return ((string)src).Trim(); }
  12644. return src;
  12645. }
  12646. public LSL_List llGetObjectDetails(LSL_Key id, LSL_List args)
  12647. {
  12648. m_host.AddScriptLPS(1);
  12649. LSL_List ret = new LSL_List();
  12650. UUID key = new UUID();
  12651. if (!UUID.TryParse(id, out key))
  12652. return ret;
  12653. int count = 0;
  12654. ScenePresence av = World.GetScenePresence(key);
  12655. if (av != null)
  12656. {
  12657. List<SceneObjectGroup> Attachments = null;
  12658. int? nAnimated = null;
  12659. foreach (object o in args.Data)
  12660. {
  12661. switch (int.Parse(o.ToString()))
  12662. {
  12663. case ScriptBaseClass.OBJECT_NAME:
  12664. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  12665. break;
  12666. case ScriptBaseClass.OBJECT_DESC:
  12667. ret.Add(new LSL_String(""));
  12668. break;
  12669. case ScriptBaseClass.OBJECT_POS:
  12670. Vector3 avpos;
  12671. if (av.ParentID != 0 && av.ParentPart != null &&
  12672. av.ParentPart.ParentGroup != null && av.ParentPart.ParentGroup.RootPart != null )
  12673. {
  12674. avpos = av.OffsetPosition;
  12675. if(!av.LegacySitOffsets)
  12676. {
  12677. Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
  12678. avpos -= sitOffset;
  12679. }
  12680. SceneObjectPart sitRoot = av.ParentPart.ParentGroup.RootPart;
  12681. avpos = sitRoot.GetWorldPosition() + avpos * sitRoot.GetWorldRotation();
  12682. }
  12683. else
  12684. avpos = av.AbsolutePosition;
  12685. ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
  12686. break;
  12687. case ScriptBaseClass.OBJECT_ROT:
  12688. Quaternion avrot = av.GetWorldRotation();
  12689. ret.Add(new LSL_Rotation(avrot));
  12690. break;
  12691. case ScriptBaseClass.OBJECT_VELOCITY:
  12692. Vector3 avvel = av.GetWorldVelocity();
  12693. ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
  12694. break;
  12695. case ScriptBaseClass.OBJECT_OWNER:
  12696. ret.Add(new LSL_Key((string)id));
  12697. break;
  12698. case ScriptBaseClass.OBJECT_GROUP:
  12699. ret.Add(new LSL_String(ScriptBaseClass.NULL_KEY));
  12700. break;
  12701. case ScriptBaseClass.OBJECT_CREATOR:
  12702. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12703. break;
  12704. // For the following 8 see the Object version below
  12705. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12706. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  12707. break;
  12708. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12709. ret.Add(new LSL_Integer(av.ScriptCount()));
  12710. break;
  12711. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12712. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  12713. break;
  12714. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12715. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  12716. break;
  12717. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12718. ret.Add(new LSL_Integer(1));
  12719. break;
  12720. case ScriptBaseClass.OBJECT_SERVER_COST:
  12721. ret.Add(new LSL_Float(0));
  12722. break;
  12723. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12724. ret.Add(new LSL_Float(0));
  12725. break;
  12726. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12727. ret.Add(new LSL_Float(0));
  12728. break;
  12729. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12730. ret.Add(new LSL_Float(0));
  12731. break;
  12732. case ScriptBaseClass.OBJECT_ROOT:
  12733. SceneObjectPart p = av.ParentPart;
  12734. if (p != null)
  12735. {
  12736. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  12737. }
  12738. else
  12739. {
  12740. ret.Add(new LSL_Key((string)id));
  12741. }
  12742. break;
  12743. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12744. ret.Add(new LSL_Integer(0));
  12745. break;
  12746. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  12747. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  12748. break;
  12749. case ScriptBaseClass.OBJECT_PHYSICS:
  12750. ret.Add(new LSL_Integer(0));
  12751. break;
  12752. case ScriptBaseClass.OBJECT_PHANTOM:
  12753. ret.Add(new LSL_Integer(0));
  12754. break;
  12755. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12756. ret.Add(new LSL_Integer(0));
  12757. break;
  12758. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12759. ret.Add(new LSL_Integer(-1));
  12760. break;
  12761. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12762. ret.Add(new LSL_Float(0));
  12763. break;
  12764. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12765. LSL_Float shapeType;
  12766. if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0)
  12767. shapeType = new LSL_Float(1);
  12768. else
  12769. shapeType = new LSL_Float(0);
  12770. ret.Add(shapeType);
  12771. break;
  12772. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12773. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12774. break;
  12775. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12776. ret.Add(new LSL_Integer(0));
  12777. break;
  12778. case ScriptBaseClass.OBJECT_OMEGA:
  12779. ret.Add(new LSL_Vector(Vector3.Zero));
  12780. break;
  12781. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12782. if (Attachments == null)
  12783. Attachments = av.GetAttachments();
  12784. count = 0;
  12785. try
  12786. {
  12787. foreach (SceneObjectGroup Attachment in Attachments)
  12788. count += Attachment.PrimCount;
  12789. }
  12790. catch { };
  12791. ret.Add(new LSL_Integer(count));
  12792. break;
  12793. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12794. if (Attachments == null)
  12795. Attachments = av.GetAttachments();
  12796. count = 0;
  12797. try
  12798. {
  12799. foreach (SceneObjectGroup Attachment in Attachments)
  12800. {
  12801. SceneObjectPart[] parts = Attachment.Parts;
  12802. for(int i = 0; i < parts.Length; i++)
  12803. count += parts[i].Inventory.Count;
  12804. }
  12805. } catch { };
  12806. ret.Add(new LSL_Integer(count));
  12807. break;
  12808. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12809. ret.Add(new LSL_Key((string)id));
  12810. break;
  12811. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12812. ret.Add(new LSL_String(av.Grouptitle));
  12813. break;
  12814. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12815. ret.Add(new LSL_Integer(0));
  12816. break;
  12817. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  12818. ret.Add(new LSL_Integer(Constants.MaxAgentAttachments - av.GetAttachmentsCount()));
  12819. break;
  12820. case ScriptBaseClass.OBJECT_CREATION_TIME:
  12821. ret.Add(new LSL_String(""));
  12822. break;
  12823. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  12824. ret.Add(new LSL_Integer(0));
  12825. break;
  12826. case ScriptBaseClass.OBJECT_SIT_COUNT:
  12827. ret.Add(new LSL_Integer(0));
  12828. break;
  12829. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  12830. count = 0;
  12831. if (nAnimated.HasValue)
  12832. count = nAnimated.Value;
  12833. else
  12834. {
  12835. if (Attachments == null)
  12836. Attachments = av.GetAttachments();
  12837. try
  12838. {
  12839. for(int i = 0; i < Attachments.Count;++i)
  12840. {
  12841. if(Attachments[i].RootPart.Shape.MeshFlagEntry)
  12842. ++count;
  12843. }
  12844. }
  12845. catch { };
  12846. nAnimated = count;
  12847. }
  12848. ret.Add(new LSL_Integer(count));
  12849. break;
  12850. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  12851. count = 0;
  12852. if (nAnimated.HasValue)
  12853. count = nAnimated.Value;
  12854. else
  12855. {
  12856. if (Attachments == null)
  12857. Attachments = av.GetAttachments();
  12858. count = 0;
  12859. try
  12860. {
  12861. for (int i = 0; i < Attachments.Count; ++i)
  12862. {
  12863. if (Attachments[i].RootPart.Shape.MeshFlagEntry)
  12864. ++count;
  12865. }
  12866. }
  12867. catch { };
  12868. nAnimated = count;
  12869. }
  12870. count = 2 - count; // for now hardcoded max (simulator features, viewers settings, etc)
  12871. if(count < 0)
  12872. count = 0;
  12873. ret.Add(new LSL_Integer(count));
  12874. break;
  12875. default:
  12876. // Invalid or unhandled constant.
  12877. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12878. break;
  12879. }
  12880. }
  12881. return ret;
  12882. }
  12883. SceneObjectPart obj = World.GetSceneObjectPart(key);
  12884. if (obj != null)
  12885. {
  12886. foreach (object o in args.Data)
  12887. {
  12888. switch (int.Parse(o.ToString()))
  12889. {
  12890. case ScriptBaseClass.OBJECT_NAME:
  12891. ret.Add(new LSL_String(obj.Name));
  12892. break;
  12893. case ScriptBaseClass.OBJECT_DESC:
  12894. ret.Add(new LSL_String(obj.Description));
  12895. break;
  12896. case ScriptBaseClass.OBJECT_POS:
  12897. Vector3 opos = obj.AbsolutePosition;
  12898. ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
  12899. break;
  12900. case ScriptBaseClass.OBJECT_ROT:
  12901. Quaternion rot = Quaternion.Identity;
  12902. if (obj.ParentGroup.IsAttachment)
  12903. {
  12904. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12905. if (sp != null)
  12906. rot = sp.GetWorldRotation();
  12907. }
  12908. else
  12909. {
  12910. if (obj.ParentGroup.RootPart == obj)
  12911. rot = obj.ParentGroup.GroupRotation;
  12912. else
  12913. rot = obj.GetWorldRotation();
  12914. }
  12915. LSL_Rotation objrot = new LSL_Rotation(rot);
  12916. ret.Add(objrot);
  12917. break;
  12918. case ScriptBaseClass.OBJECT_VELOCITY:
  12919. Vector3 vel = Vector3.Zero;
  12920. if (obj.ParentGroup.IsAttachment)
  12921. {
  12922. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12923. if (sp != null)
  12924. vel = sp.GetWorldVelocity();
  12925. }
  12926. else
  12927. {
  12928. vel = obj.Velocity;
  12929. }
  12930. ret.Add(vel);
  12931. break;
  12932. case ScriptBaseClass.OBJECT_OWNER:
  12933. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  12934. break;
  12935. case ScriptBaseClass.OBJECT_GROUP:
  12936. ret.Add(new LSL_String(obj.GroupID.ToString()));
  12937. break;
  12938. case ScriptBaseClass.OBJECT_CREATOR:
  12939. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  12940. break;
  12941. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12942. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  12943. break;
  12944. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12945. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  12946. break;
  12947. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12948. // The value returned in SL for mono scripts is 65536 * number of active scripts
  12949. // and 16384 * number of active scripts for LSO. since llGetFreememory
  12950. // is coded to give the LSO value use it here
  12951. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  12952. break;
  12953. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12954. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  12955. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  12956. break;
  12957. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12958. // according to the SL wiki A prim or linkset will have prim
  12959. // equivalent of the number of prims in a linkset if it does not
  12960. // contain a mesh anywhere in the link set or is not a normal prim
  12961. // The value returned in SL for normal prims is prim count
  12962. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12963. break;
  12964. // costs below may need to be diferent for root parts, need to check
  12965. case ScriptBaseClass.OBJECT_SERVER_COST:
  12966. // The linden calculation is here
  12967. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  12968. // The value returned in SL for normal prims looks like the prim count
  12969. ret.Add(new LSL_Float(0));
  12970. break;
  12971. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12972. // The value returned in SL for normal prims is prim count * 0.06
  12973. ret.Add(new LSL_Float(obj.StreamingCost));
  12974. break;
  12975. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12976. // The value returned in SL for normal prims is prim count
  12977. ret.Add(new LSL_Float(obj.PhysicsCost));
  12978. break;
  12979. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12980. ret.Add(new LSL_Float(0));
  12981. break;
  12982. case ScriptBaseClass.OBJECT_ROOT:
  12983. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  12984. break;
  12985. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12986. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  12987. break;
  12988. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  12989. byte pcode = obj.Shape.PCode;
  12990. if (obj.ParentGroup.AttachmentPoint != 0
  12991. || pcode == (byte)PCode.Grass
  12992. || pcode == (byte)PCode.Tree
  12993. || pcode == (byte)PCode.NewTree)
  12994. {
  12995. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  12996. }
  12997. else
  12998. {
  12999. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  13000. }
  13001. break;
  13002. case ScriptBaseClass.OBJECT_PHYSICS:
  13003. if (obj.ParentGroup.AttachmentPoint != 0)
  13004. {
  13005. ret.Add(new LSL_Integer(0)); // Always false if attached
  13006. }
  13007. else
  13008. {
  13009. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  13010. }
  13011. break;
  13012. case ScriptBaseClass.OBJECT_PHANTOM:
  13013. if (obj.ParentGroup.AttachmentPoint != 0)
  13014. {
  13015. ret.Add(new LSL_Integer(0)); // Always false if attached
  13016. }
  13017. else
  13018. {
  13019. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  13020. }
  13021. break;
  13022. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  13023. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  13024. break;
  13025. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  13026. ret.Add(new LSL_Integer(0));
  13027. break;
  13028. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  13029. ret.Add(new LSL_Float(0));
  13030. break;
  13031. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  13032. ret.Add(new LSL_Float(-1));
  13033. break;
  13034. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  13035. ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString()));
  13036. break;
  13037. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  13038. ret.Add(new LSL_Integer(obj.ClickAction));
  13039. break;
  13040. case ScriptBaseClass.OBJECT_OMEGA:
  13041. ret.Add(new LSL_Vector(obj.AngularVelocity));
  13042. break;
  13043. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  13044. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  13045. break;
  13046. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  13047. SceneObjectPart[] parts = obj.ParentGroup.Parts;
  13048. count = 0;
  13049. for(int i = 0; i < parts.Length; i++)
  13050. count += parts[i].Inventory.Count;
  13051. ret.Add(new LSL_Integer(count));
  13052. break;
  13053. case ScriptBaseClass.OBJECT_REZZER_KEY:
  13054. ret.Add(new LSL_Key(obj.ParentGroup.RezzerID.ToString()));
  13055. break;
  13056. case ScriptBaseClass.OBJECT_GROUP_TAG:
  13057. ret.Add(new LSL_String(String.Empty));
  13058. break;
  13059. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  13060. if (obj.ParentGroup.AttachmentPoint != 0 && obj.ParentGroup.FromItemID == UUID.Zero)
  13061. {
  13062. ret.Add(new LSL_Integer(1));
  13063. }
  13064. else
  13065. {
  13066. ret.Add(new LSL_Integer(0));
  13067. }
  13068. break;
  13069. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  13070. ret.Add(new LSL_Integer(0));
  13071. break;
  13072. case ScriptBaseClass.OBJECT_CREATION_TIME:
  13073. DateTime date = Util.ToDateTime(m_host.ParentGroup.RootPart.CreationDate);
  13074. ret.Add(new LSL_String(date.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)));
  13075. break;
  13076. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  13077. ret.Add(new LSL_Integer(0));
  13078. break;
  13079. case ScriptBaseClass.OBJECT_SIT_COUNT:
  13080. ret.Add(new LSL_Integer(m_host.ParentGroup.GetSittingAvatarsCount()));
  13081. break;
  13082. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  13083. if(m_host.ParentGroup.RootPart.Shape.MeshFlagEntry)
  13084. ret.Add(new LSL_Integer(1));
  13085. else
  13086. ret.Add(new LSL_Integer(0));
  13087. break;
  13088. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  13089. ret.Add(new LSL_Integer(0));
  13090. break;
  13091. default:
  13092. // Invalid or unhandled constant.
  13093. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  13094. break;
  13095. }
  13096. }
  13097. }
  13098. return ret;
  13099. }
  13100. internal UUID GetScriptByName(string name)
  13101. {
  13102. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13103. if (item == null || item.Type != 10)
  13104. return UUID.Zero;
  13105. return item.ItemID;
  13106. }
  13107. /// <summary>
  13108. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  13109. /// </summary>
  13110. /// <param name="command">The name of the command that generated the error.</param>
  13111. /// <param name="message">The error message to report to the user.</param>
  13112. internal void Error(string command, string message)
  13113. {
  13114. string text = command + ": " + message;
  13115. if (text.Length > 1023)
  13116. {
  13117. text = text.Substring(0, 1023);
  13118. }
  13119. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  13120. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  13121. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  13122. if (wComm != null)
  13123. {
  13124. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  13125. }
  13126. Sleep(1000);
  13127. }
  13128. /// <summary>
  13129. /// Reports that the command is not implemented as a script error.
  13130. /// </summary>
  13131. /// <param name="command">The name of the command that is not implemented.</param>
  13132. /// <param name="message">Additional information to report to the user. (Optional)</param>
  13133. internal void NotImplemented(string command, string message = "")
  13134. {
  13135. if (throwErrorOnNotImplemented)
  13136. {
  13137. if (message != "")
  13138. {
  13139. message = " - " + message;
  13140. }
  13141. throw new NotImplementedException("Command not implemented: " + command + message);
  13142. }
  13143. else
  13144. {
  13145. string text = "Command not implemented";
  13146. if (message != "")
  13147. {
  13148. text = text + " - " + message;
  13149. }
  13150. Error(command, text);
  13151. }
  13152. }
  13153. /// <summary>
  13154. /// Reports that the command is deprecated as a script error.
  13155. /// </summary>
  13156. /// <param name="command">The name of the command that is deprecated.</param>
  13157. /// <param name="message">Additional information to report to the user. (Optional)</param>
  13158. internal void Deprecated(string command, string message = "")
  13159. {
  13160. string text = "Command deprecated";
  13161. if (message != "")
  13162. {
  13163. text = text + " - " + message;
  13164. }
  13165. Error(command, text);
  13166. }
  13167. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  13168. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  13169. {
  13170. World.AssetService.Get(assetID.ToString(), this,
  13171. delegate(string i, object sender, AssetBase a)
  13172. {
  13173. UUID uuid = UUID.Zero;
  13174. UUID.TryParse(i, out uuid);
  13175. cb(uuid, a);
  13176. });
  13177. }
  13178. public LSL_Key llGetNumberOfNotecardLines(string name)
  13179. {
  13180. m_host.AddScriptLPS(1);
  13181. UUID assetID = UUID.Zero;
  13182. if (!UUID.TryParse(name, out assetID))
  13183. {
  13184. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13185. if (item != null && item.Type == 7)
  13186. assetID = item.AssetID;
  13187. }
  13188. if (assetID == UUID.Zero)
  13189. {
  13190. // => complain loudly, as specified by the LSL docs
  13191. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  13192. return ScriptBaseClass.NULL_KEY;
  13193. }
  13194. if (NotecardCache.IsCached(assetID))
  13195. {
  13196. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId, m_item.ItemID, NotecardCache.GetLines(assetID).ToString());
  13197. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  13198. return ftid;
  13199. }
  13200. Action<string> act = eventID =>
  13201. {
  13202. if (NotecardCache.IsCached(assetID))
  13203. {
  13204. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLines(assetID).ToString());
  13205. return;
  13206. }
  13207. AssetBase a = World.AssetService.Get(assetID.ToString());
  13208. if (a == null || a.Type != 7)
  13209. {
  13210. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, string.Empty);
  13211. return;
  13212. }
  13213. NotecardCache.Cache(assetID, a.Data);
  13214. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLines(assetID).ToString());
  13215. };
  13216. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13217. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  13218. return tid.ToString();
  13219. }
  13220. public LSL_Key llGetNotecardLine(string name, int line)
  13221. {
  13222. m_host.AddScriptLPS(1);
  13223. UUID assetID = UUID.Zero;
  13224. if (!UUID.TryParse(name, out assetID))
  13225. {
  13226. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13227. if (item != null && item.Type == 7)
  13228. assetID = item.AssetID;
  13229. }
  13230. if (assetID == UUID.Zero)
  13231. {
  13232. // => complain loudly, as specified by the LSL docs
  13233. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  13234. return ScriptBaseClass.NULL_KEY;
  13235. }
  13236. if (NotecardCache.IsCached(assetID))
  13237. {
  13238. string eid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId, m_item.ItemID,
  13239. NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13240. ScriptSleep(m_sleepMsOnGetNotecardLine);
  13241. return eid;
  13242. }
  13243. Action<string> act = eventID =>
  13244. {
  13245. if (NotecardCache.IsCached(assetID))
  13246. {
  13247. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13248. return;
  13249. }
  13250. AssetBase a = World.AssetService.Get(assetID.ToString());
  13251. if (a == null || a.Type != 7)
  13252. {
  13253. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, string.Empty);
  13254. return;
  13255. }
  13256. NotecardCache.Cache(assetID, a.Data);
  13257. m_AsyncCommands.DataserverPlugin.DataserverReply(
  13258. eventID, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13259. };
  13260. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13261. ScriptSleep(m_sleepMsOnGetNotecardLine);
  13262. return tid.ToString();
  13263. }
  13264. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  13265. {
  13266. if (!UUID.TryParse(prim, out UUID id))
  13267. return;
  13268. SceneObjectPart obj = World.GetSceneObjectPart(id);
  13269. if (obj == null || obj.OwnerID != m_host.OwnerID)
  13270. return;
  13271. uint rulesParsed = 0;
  13272. LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
  13273. while (remaining.Length > 2)
  13274. {
  13275. int linknumber;
  13276. try
  13277. {
  13278. linknumber = remaining.GetLSLIntegerItem(0);
  13279. }
  13280. catch (InvalidCastException)
  13281. {
  13282. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET parameter must be integer", rulesParsed));
  13283. return;
  13284. }
  13285. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13286. if (entities.Count == 0)
  13287. break;
  13288. rules = remaining.GetSublist(1, -1);
  13289. foreach (ISceneEntity entity in entities)
  13290. {
  13291. if (entity is SceneObjectPart)
  13292. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  13293. else
  13294. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  13295. }
  13296. }
  13297. }
  13298. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  13299. {
  13300. LSL_List result = new LSL_List();
  13301. if (!UUID.TryParse(prim, out UUID id))
  13302. return result;
  13303. SceneObjectPart obj = World.GetSceneObjectPart(id);
  13304. if (obj == null || obj.OwnerID != m_host.OwnerID)
  13305. return result;
  13306. LSL_List remaining = GetPrimParams(obj, rules, ref result);
  13307. while (remaining.Length > 1)
  13308. {
  13309. int linknumber;
  13310. try
  13311. {
  13312. linknumber = remaining.GetLSLIntegerItem(0);
  13313. }
  13314. catch (InvalidCastException)
  13315. {
  13316. Error("", string.Format("Error PRIM_LINK_TARGET: parameter must be integer"));
  13317. return result;
  13318. }
  13319. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13320. if (entities.Count == 0)
  13321. break;
  13322. rules = remaining.GetSublist(1, -1);
  13323. foreach (ISceneEntity entity in entities)
  13324. {
  13325. if (entity is SceneObjectPart)
  13326. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  13327. else
  13328. remaining = GetPrimParams((ScenePresence)entity, rules, ref result);
  13329. }
  13330. }
  13331. return result;
  13332. }
  13333. public void print(string str)
  13334. {
  13335. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  13336. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  13337. if (ossl != null)
  13338. {
  13339. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  13340. m_log.Info("LSL print():" + str);
  13341. }
  13342. }
  13343. public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
  13344. {
  13345. List<SceneObjectPart> parts = GetLinkParts(link);
  13346. if (parts.Count < 1)
  13347. return 0;
  13348. return GetNumberOfSides(parts[0]);
  13349. }
  13350. private string Name2Username(string name)
  13351. {
  13352. string[] parts = name.Split(new char[] {' '});
  13353. if (parts.Length < 2)
  13354. return name.ToLower();
  13355. if (parts[1] == "Resident")
  13356. return parts[0].ToLower();
  13357. return name.Replace(" ", ".").ToLower();
  13358. }
  13359. public LSL_String llGetUsername(LSL_Key id)
  13360. {
  13361. return Name2Username(llKey2Name(id));
  13362. }
  13363. public LSL_Key llRequestUsername(LSL_Key id)
  13364. {
  13365. m_host.AddScriptLPS(1);
  13366. if (!UUID.TryParse(id, out UUID key) || key == UUID.Zero)
  13367. return string.Empty;
  13368. ScenePresence lpresence = World.GetScenePresence(key);
  13369. if (lpresence != null)
  13370. {
  13371. string lname = lpresence.Name;
  13372. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  13373. m_item.ItemID, Name2Username(lname));
  13374. return ftid;
  13375. }
  13376. Action<string> act = eventID =>
  13377. {
  13378. string name = String.Empty;
  13379. ScenePresence presence = World.GetScenePresence(key);
  13380. if (presence != null)
  13381. {
  13382. name = presence.Name;
  13383. }
  13384. else if (World.TryGetSceneObjectPart(key, out SceneObjectPart sop ) && sop != null)
  13385. {
  13386. name = sop.Name;
  13387. }
  13388. else
  13389. {
  13390. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, key);
  13391. if(account != null)
  13392. {
  13393. name = account.FirstName + " " + account.LastName;
  13394. }
  13395. }
  13396. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, Name2Username(name));
  13397. };
  13398. UUID rq = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13399. ScriptSleep(m_sleepMsOnRequestAgentData);
  13400. return rq.ToString();
  13401. }
  13402. public LSL_String llGetDisplayName(LSL_Key id)
  13403. {
  13404. m_host.AddScriptLPS(1);
  13405. if (UUID.TryParse(id, out UUID key) && key != UUID.Zero)
  13406. {
  13407. ScenePresence presence = World.GetScenePresence(key);
  13408. if (presence != null)
  13409. {
  13410. return presence.Name;
  13411. }
  13412. }
  13413. return String.Empty;
  13414. }
  13415. public LSL_Key llRequestDisplayName(LSL_Key id)
  13416. {
  13417. m_host.AddScriptLPS(1);
  13418. if (!UUID.TryParse(id, out UUID key) || key == UUID.Zero)
  13419. return string.Empty;
  13420. ScenePresence lpresence = World.GetScenePresence(key);
  13421. if (lpresence != null)
  13422. {
  13423. string lname = lpresence.Name;
  13424. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  13425. m_item.ItemID, lname);
  13426. return ftid;
  13427. }
  13428. Action<string> act = eventID =>
  13429. {
  13430. string name = String.Empty;
  13431. ScenePresence presence = World.GetScenePresence(key);
  13432. if (presence != null)
  13433. {
  13434. name = presence.Name;
  13435. }
  13436. else if (World.TryGetSceneObjectPart(key, out SceneObjectPart sop) && sop != null)
  13437. {
  13438. name = sop.Name;
  13439. }
  13440. else
  13441. {
  13442. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, key);
  13443. if (account != null)
  13444. {
  13445. name = account.FirstName + " " + account.LastName;
  13446. }
  13447. }
  13448. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, name);
  13449. };
  13450. UUID rq = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13451. return rq.ToString();
  13452. }
  13453. private struct Tri
  13454. {
  13455. public Vector3 p1;
  13456. public Vector3 p2;
  13457. public Vector3 p3;
  13458. }
  13459. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  13460. {
  13461. float height = avatar.Appearance.AvatarHeight;
  13462. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  13463. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  13464. if (point.X > b1.X && point.X < b2.X &&
  13465. point.Y > b1.Y && point.Y < b2.Y &&
  13466. point.Z > b1.Z && point.Z < b2.Z)
  13467. return true;
  13468. return false;
  13469. }
  13470. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd, bool skipPhys)
  13471. {
  13472. List<ContactResult> contacts = new List<ContactResult>();
  13473. Vector3 ab = rayEnd - rayStart;
  13474. float ablen = ab.Length();
  13475. World.ForEachScenePresence(delegate(ScenePresence sp)
  13476. {
  13477. if(skipPhys && sp.PhysicsActor != null)
  13478. return;
  13479. Vector3 ac = sp.AbsolutePosition - rayStart;
  13480. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / ablen);
  13481. if (d > 1.5)
  13482. return;
  13483. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13484. if (d2 > 0)
  13485. return;
  13486. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  13487. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  13488. if (!InBoundingBox(sp, p))
  13489. return;
  13490. ContactResult result = new ContactResult
  13491. {
  13492. ConsumerID = sp.LocalId,
  13493. Depth = Vector3.Distance(rayStart, p),
  13494. Normal = Vector3.Zero,
  13495. Pos = p
  13496. };
  13497. contacts.Add(result);
  13498. });
  13499. return contacts.ToArray();
  13500. }
  13501. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  13502. {
  13503. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13504. List<ContactResult> contacts = new List<ContactResult>();
  13505. Vector3 ab = rayEnd - rayStart;
  13506. World.ForEachSOG(delegate(SceneObjectGroup group)
  13507. {
  13508. if (m_host.ParentGroup == group)
  13509. return;
  13510. if (group.IsAttachment)
  13511. return;
  13512. if (group.RootPart.PhysActor == null)
  13513. {
  13514. if (!includePhantom)
  13515. return;
  13516. }
  13517. else
  13518. {
  13519. if (group.RootPart.PhysActor.IsPhysical)
  13520. {
  13521. if (!includePhysical)
  13522. return;
  13523. }
  13524. else
  13525. {
  13526. if (!includeNonPhysical)
  13527. return;
  13528. }
  13529. }
  13530. // Find the radius ouside of which we don't even need to hit test
  13531. float radius = 0.0f;
  13532. group.GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ);
  13533. if (Math.Abs(minX) > radius)
  13534. radius = Math.Abs(minX);
  13535. if (Math.Abs(minY) > radius)
  13536. radius = Math.Abs(minY);
  13537. if (Math.Abs(minZ) > radius)
  13538. radius = Math.Abs(minZ);
  13539. if (Math.Abs(maxX) > radius)
  13540. radius = Math.Abs(maxX);
  13541. if (Math.Abs(maxY) > radius)
  13542. radius = Math.Abs(maxY);
  13543. if (Math.Abs(maxZ) > radius)
  13544. radius = Math.Abs(maxZ);
  13545. radius = radius*1.413f;
  13546. Vector3 ac = group.AbsolutePosition - rayStart;
  13547. // Vector3 bc = group.AbsolutePosition - rayEnd;
  13548. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  13549. // Too far off ray, don't bother
  13550. if (d > radius)
  13551. return;
  13552. // Behind ray, drop
  13553. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13554. if (d2 > 0)
  13555. return;
  13556. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13557. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  13558. // Miss.
  13559. if (!intersection.HitTF)
  13560. return;
  13561. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  13562. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  13563. //m_log.DebugFormat("[LLCASTRAY]: min<{0},{1},{2}>, max<{3},{4},{5}> = hitp<{6},{7},{8}>", b1.X,b1.Y,b1.Z,b2.X,b2.Y,b2.Z,intersection.ipoint.X,intersection.ipoint.Y,intersection.ipoint.Z);
  13564. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  13565. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  13566. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  13567. return;
  13568. ContactResult result = new ContactResult
  13569. {
  13570. ConsumerID = group.LocalId,
  13571. //Depth = intersection.distance;
  13572. Normal = intersection.normal,
  13573. Pos = intersection.ipoint
  13574. };
  13575. result.Depth = Vector3.Mag(rayStart - result.Pos);
  13576. contacts.Add(result);
  13577. });
  13578. return contacts.ToArray();
  13579. }
  13580. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  13581. {
  13582. double[,] heightfield = World.Heightmap.GetDoubles();
  13583. List<ContactResult> contacts = new List<ContactResult>();
  13584. double min = 2048.0;
  13585. double max = 0.0;
  13586. // Find the min and max of the heightfield
  13587. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  13588. {
  13589. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  13590. {
  13591. if (heightfield[x, y] > max)
  13592. max = heightfield[x, y];
  13593. if (heightfield[x, y] < min)
  13594. min = heightfield[x, y];
  13595. }
  13596. }
  13597. // A ray extends past rayEnd, but doesn't go back before
  13598. // rayStart. If the start is above the highest point of the ground
  13599. // and the ray goes up, we can't hit the ground. Ever.
  13600. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  13601. return null;
  13602. // Same for going down
  13603. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  13604. return null;
  13605. List<Tri> trilist = new List<Tri>();
  13606. // Create our triangle list
  13607. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  13608. {
  13609. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  13610. {
  13611. Tri t1 = new Tri();
  13612. Tri t2 = new Tri();
  13613. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  13614. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  13615. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  13616. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  13617. t1.p1 = p1;
  13618. t1.p2 = p2;
  13619. t1.p3 = p3;
  13620. t2.p1 = p3;
  13621. t2.p2 = p4;
  13622. t2.p3 = p1;
  13623. trilist.Add(t1);
  13624. trilist.Add(t2);
  13625. }
  13626. }
  13627. // Ray direction
  13628. Vector3 rayDirection = rayEnd - rayStart;
  13629. foreach (Tri t in trilist)
  13630. {
  13631. // Compute triangle plane normal and edges
  13632. Vector3 u = t.p2 - t.p1;
  13633. Vector3 v = t.p3 - t.p1;
  13634. Vector3 n = Vector3.Cross(u, v);
  13635. if (n == Vector3.Zero)
  13636. continue;
  13637. Vector3 w0 = rayStart - t.p1;
  13638. double a = -Vector3.Dot(n, w0);
  13639. double b = Vector3.Dot(n, rayDirection);
  13640. // Not intersecting the plane, or in plane (same thing)
  13641. // Ignoring this MAY cause the ground to not be detected
  13642. // sometimes
  13643. if (Math.Abs(b) < 0.000001)
  13644. continue;
  13645. double r = a / b;
  13646. // ray points away from plane
  13647. if (r < 0.0)
  13648. continue;
  13649. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  13650. float uu = Vector3.Dot(u, u);
  13651. float uv = Vector3.Dot(u, v);
  13652. float vv = Vector3.Dot(v, v);
  13653. Vector3 w = ip - t.p1;
  13654. float wu = Vector3.Dot(w, u);
  13655. float wv = Vector3.Dot(w, v);
  13656. float d = uv * uv - uu * vv;
  13657. float cs = (uv * wv - vv * wu) / d;
  13658. if (cs < 0 || cs > 1.0)
  13659. continue;
  13660. float ct = (uv * wu - uu * wv) / d;
  13661. if (ct < 0 || (cs + ct) > 1.0)
  13662. continue;
  13663. // Add contact point
  13664. ContactResult result = new ContactResult
  13665. {
  13666. ConsumerID = 0,
  13667. Depth = Vector3.Distance(rayStart, ip),
  13668. Normal = n,
  13669. Pos = ip
  13670. };
  13671. contacts.Add(result);
  13672. }
  13673. if (contacts.Count == 0)
  13674. return null;
  13675. contacts.Sort(delegate(ContactResult a, ContactResult b)
  13676. {
  13677. return (int)(a.Depth - b.Depth);
  13678. });
  13679. return contacts[0];
  13680. }
  13681. /*
  13682. // not done:
  13683. private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
  13684. {
  13685. ContactResult[] contacts = null;
  13686. World.ForEachSOG(delegate(SceneObjectGroup group)
  13687. {
  13688. if (m_host.ParentGroup == group)
  13689. return;
  13690. if (group.IsAttachment)
  13691. return;
  13692. if(group.RootPart.PhysActor != null)
  13693. return;
  13694. contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
  13695. });
  13696. return contacts;
  13697. }
  13698. */
  13699. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  13700. {
  13701. LSL_List list = new LSL_List();
  13702. m_host.AddScriptLPS(1);
  13703. Vector3 rayStart = start;
  13704. Vector3 rayEnd = end;
  13705. Vector3 dir = rayEnd - rayStart;
  13706. float dist = dir.Length();
  13707. int count = 1;
  13708. bool detectPhantom = false;
  13709. int dataFlags = 0;
  13710. int rejectTypes = 0;
  13711. for (int i = 0; i < options.Length; i += 2)
  13712. {
  13713. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13714. count = options.GetLSLIntegerItem(i + 1);
  13715. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13716. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  13717. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13718. dataFlags = options.GetLSLIntegerItem(i + 1);
  13719. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13720. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13721. }
  13722. if (count > 16)
  13723. count = 16;
  13724. List<ContactResult> results = new List<ContactResult>();
  13725. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  13726. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  13727. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  13728. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  13729. bool rejectHost = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOST) != 0);
  13730. bool rejectHostGroup = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOSTGROUP) != 0);
  13731. if (World.SupportsRayCastFiltered())
  13732. {
  13733. if (dist == 0)
  13734. return list;
  13735. RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull;
  13736. if (checkTerrain)
  13737. rayfilter |= RayFilterFlags.land;
  13738. if (checkAgents)
  13739. rayfilter |= RayFilterFlags.agent;
  13740. if (checkPhysical)
  13741. rayfilter |= RayFilterFlags.physical;
  13742. if (checkNonPhysical)
  13743. rayfilter |= RayFilterFlags.nonphysical;
  13744. if (detectPhantom)
  13745. rayfilter |= RayFilterFlags.LSLPhantom;
  13746. Vector3 direction = dir * ( 1/dist);
  13747. if(rayfilter == 0)
  13748. {
  13749. list.Add(new LSL_Integer(0));
  13750. return list;
  13751. }
  13752. // get some more contacts to sort ???
  13753. int physcount = 4 * count;
  13754. if (physcount > 20)
  13755. physcount = 20;
  13756. object physresults;
  13757. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  13758. if (physresults == null)
  13759. {
  13760. // list.Add(new LSL_Integer(-3)); // timeout error
  13761. // return list;
  13762. results = new List<ContactResult>();
  13763. }
  13764. else
  13765. results = (List<ContactResult>)physresults;
  13766. // for now physics doesn't detect sitted avatars so do it outside physics
  13767. if (checkAgents)
  13768. {
  13769. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, true);
  13770. foreach (ContactResult r in agentHits)
  13771. results.Add(r);
  13772. }
  13773. // TODO: Replace this with a better solution. ObjectIntersection can only
  13774. // detect nonphysical phantoms. They are detected by virtue of being
  13775. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  13776. // physicsl phantoms as done by the physics scene
  13777. // We don't want anything else but phantoms here.
  13778. if (detectPhantom)
  13779. {
  13780. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  13781. foreach (ContactResult r in objectHits)
  13782. results.Add(r);
  13783. }
  13784. // Double check this because of current ODE distance problems
  13785. if (checkTerrain && dist > 60)
  13786. {
  13787. bool skipGroundCheck = false;
  13788. foreach (ContactResult c in results)
  13789. {
  13790. if (c.ConsumerID == 0) // Physics gave us a ground collision
  13791. skipGroundCheck = true;
  13792. }
  13793. if (!skipGroundCheck)
  13794. {
  13795. float tmp = dir.X * dir.X + dir.Y * dir.Y;
  13796. if(tmp > 2500)
  13797. {
  13798. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13799. if (groundContact != null)
  13800. results.Add((ContactResult)groundContact);
  13801. }
  13802. }
  13803. }
  13804. }
  13805. else
  13806. {
  13807. if (checkAgents)
  13808. {
  13809. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, false);
  13810. foreach (ContactResult r in agentHits)
  13811. results.Add(r);
  13812. }
  13813. if (checkPhysical || checkNonPhysical || detectPhantom)
  13814. {
  13815. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  13816. for (int iter = 0; iter < objectHits.Length; iter++)
  13817. {
  13818. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  13819. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  13820. results.Add(objectHits[iter]);
  13821. }
  13822. }
  13823. if (checkTerrain)
  13824. {
  13825. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13826. if (groundContact != null)
  13827. results.Add((ContactResult)groundContact);
  13828. }
  13829. }
  13830. results.Sort(delegate(ContactResult a, ContactResult b)
  13831. {
  13832. return a.Depth.CompareTo(b.Depth);
  13833. });
  13834. int values = 0;
  13835. SceneObjectGroup thisgrp = m_host.ParentGroup;
  13836. foreach (ContactResult result in results)
  13837. {
  13838. if (result.Depth > dist)
  13839. continue;
  13840. // physics ray can return colisions with host prim
  13841. if (rejectHost && m_host.LocalId == result.ConsumerID)
  13842. continue;
  13843. UUID itemID = UUID.Zero;
  13844. int linkNum = 0;
  13845. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  13846. // It's a prim!
  13847. if (part != null)
  13848. {
  13849. if (rejectHostGroup && part.ParentGroup == thisgrp)
  13850. continue;
  13851. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  13852. itemID = part.ParentGroup.UUID;
  13853. else
  13854. itemID = part.UUID;
  13855. linkNum = part.LinkNum;
  13856. }
  13857. else
  13858. {
  13859. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  13860. /// It it a boy? a girl?
  13861. if (sp != null)
  13862. itemID = sp.UUID;
  13863. }
  13864. list.Add(new LSL_String(itemID.ToString()));
  13865. list.Add(new LSL_String(result.Pos.ToString()));
  13866. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  13867. list.Add(new LSL_Integer(linkNum));
  13868. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  13869. list.Add(new LSL_Vector(result.Normal));
  13870. values++;
  13871. if (values >= count)
  13872. break;
  13873. }
  13874. list.Add(new LSL_Integer(values));
  13875. return list;
  13876. }
  13877. /// <summary>
  13878. /// Implementation of llCastRay similar to SL 2015-04-21.
  13879. /// http://wiki.secondlife.com/wiki/LlCastRay
  13880. /// Uses pure geometry, bounding shapes, meshing and no physics
  13881. /// for prims, sculpts, meshes, avatars and terrain.
  13882. /// Implements all flags, reject types and data flags.
  13883. /// Can handle both objects/groups and prims/parts, by config.
  13884. /// May sometimes be inaccurate owing to calculation precision,
  13885. /// meshing detail level and a bug in libopenmetaverse PrimMesher.
  13886. /// </summary>
  13887. public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options)
  13888. {
  13889. m_host.AddScriptLPS(1);
  13890. LSL_List result = new LSL_List();
  13891. // Prepare throttle data
  13892. int calledMs = Environment.TickCount;
  13893. Stopwatch stopWatch = new Stopwatch();
  13894. stopWatch.Start();
  13895. UUID regionId = World.RegionInfo.RegionID;
  13896. UUID userId = UUID.Zero;
  13897. int msAvailable = 0;
  13898. // Throttle per owner when attachment or "vehicle" (sat upon)
  13899. if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatarsCount() > 0)
  13900. {
  13901. userId = m_host.OwnerID;
  13902. msAvailable = m_msPerAvatarInCastRay;
  13903. }
  13904. // Throttle per parcel when not attachment or vehicle
  13905. else
  13906. {
  13907. LandData land = World.GetLandData(m_host.GetWorldPosition());
  13908. if (land != null)
  13909. msAvailable = m_msPerRegionInCastRay * land.Area / 65536;
  13910. }
  13911. // Clamp for "oversized" parcels on varregions
  13912. if (msAvailable > m_msMaxInCastRay)
  13913. msAvailable = m_msMaxInCastRay;
  13914. // Check throttle data
  13915. int fromCalledMs = calledMs - m_msThrottleInCastRay;
  13916. lock (m_castRayCalls)
  13917. {
  13918. for (int i = m_castRayCalls.Count - 1; i >= 0; i--)
  13919. {
  13920. // Delete old calls from throttle data
  13921. if (m_castRayCalls[i].CalledMs < fromCalledMs)
  13922. m_castRayCalls.RemoveAt(i);
  13923. // Use current region (in multi-region sims)
  13924. else if (m_castRayCalls[i].RegionId == regionId)
  13925. {
  13926. // Reduce available time with recent calls
  13927. if (m_castRayCalls[i].UserId == userId)
  13928. msAvailable -= m_castRayCalls[i].UsedMs;
  13929. }
  13930. }
  13931. // Return failure if not enough available time
  13932. if (msAvailable < m_msMinInCastRay)
  13933. {
  13934. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED));
  13935. return result;
  13936. }
  13937. }
  13938. // Initialize
  13939. List<RayHit> rayHits = new List<RayHit>();
  13940. float tol = m_floatToleranceInCastRay;
  13941. Vector3 pos1Ray = start;
  13942. Vector3 pos2Ray = end;
  13943. // Get input options
  13944. int rejectTypes = 0;
  13945. int dataFlags = 0;
  13946. int maxHits = 1;
  13947. bool notdetectPhantom = true;
  13948. for (int i = 0; i < options.Length; i += 2)
  13949. {
  13950. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13951. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13952. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13953. dataFlags = options.GetLSLIntegerItem(i + 1);
  13954. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13955. maxHits = options.GetLSLIntegerItem(i + 1);
  13956. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13957. notdetectPhantom = (options.GetLSLIntegerItem(i + 1) == 0);
  13958. }
  13959. if (maxHits > m_maxHitsInCastRay)
  13960. maxHits = m_maxHitsInCastRay;
  13961. bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0);
  13962. bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0);
  13963. bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0);
  13964. bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0);
  13965. bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0);
  13966. bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0);
  13967. bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0);
  13968. // Calculate some basic parameters
  13969. Vector3 vecRay = pos2Ray - pos1Ray;
  13970. float rayLength = vecRay.Length();
  13971. // Try to get a mesher and return failure if none, degenerate ray, or max 0 hits
  13972. IRendering primMesher = null;
  13973. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  13974. if (renderers.Count < 1 || rayLength < tol || m_maxHitsInCastRay < 1)
  13975. {
  13976. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN));
  13977. return result;
  13978. }
  13979. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  13980. // Iterate over all objects/groups and prims/parts in region
  13981. World.ForEachSOG(
  13982. delegate(SceneObjectGroup group)
  13983. {
  13984. if(group.IsDeleted || group.RootPart == null)
  13985. return;
  13986. // Check group filters unless part filters are configured
  13987. bool isPhysical = (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical);
  13988. bool isNonphysical = !isPhysical;
  13989. bool isPhantom = group.IsPhantom || group.IsVolumeDetect;
  13990. bool isAttachment = group.IsAttachment;
  13991. if (isPhysical && rejectPhysical)
  13992. return;
  13993. if (isNonphysical && rejectNonphysical)
  13994. return;
  13995. if (isPhantom && notdetectPhantom)
  13996. return;
  13997. if (isAttachment && !m_doAttachmentsInCastRay)
  13998. return;
  13999. // Parse object/group if passed filters
  14000. // Iterate over all prims/parts in object/group
  14001. foreach(SceneObjectPart part in group.Parts)
  14002. {
  14003. // ignore PhysicsShapeType.None as physics engines do
  14004. // or we will get into trouble in future
  14005. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  14006. continue;
  14007. isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical);
  14008. isNonphysical = !isPhysical;
  14009. isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) ||
  14010. (part.VolumeDetectActive);
  14011. if (isPhysical && rejectPhysical)
  14012. continue;
  14013. if (isNonphysical && rejectNonphysical)
  14014. continue;
  14015. if (isPhantom && notdetectPhantom)
  14016. continue;
  14017. // Parse prim/part and project ray if passed filters
  14018. Vector3 scalePart = part.Scale;
  14019. Vector3 posPart = part.GetWorldPosition();
  14020. Quaternion rotPart = part.GetWorldRotation();
  14021. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  14022. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  14023. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  14024. // Filter parts by shape bounding boxes
  14025. Vector3 shapeBoxMax = new Vector3(0.5f, 0.5f, 0.5f);
  14026. if (!part.Shape.SculptEntry)
  14027. shapeBoxMax = shapeBoxMax * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ));
  14028. shapeBoxMax = shapeBoxMax + (new Vector3(tol, tol, tol));
  14029. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  14030. {
  14031. // Prepare data needed to check for ray hits
  14032. RayTrans rayTrans = new RayTrans
  14033. {
  14034. PartId = part.UUID,
  14035. GroupId = part.ParentGroup.UUID,
  14036. Link = group.PrimCount > 1 ? part.LinkNum : 0,
  14037. ScalePart = scalePart,
  14038. PositionPart = posPart,
  14039. RotationPart = rotPart,
  14040. ShapeNeedsEnds = true,
  14041. Position1Ray = pos1Ray,
  14042. Position1RayProj = pos1RayProj,
  14043. VectorRayProj = pos2RayProj - pos1RayProj
  14044. };
  14045. // Get detail level depending on type
  14046. int lod = 0;
  14047. // Mesh detail level
  14048. if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  14049. lod = (int)m_meshLodInCastRay;
  14050. // Sculpt detail level
  14051. else if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  14052. lod = (int)m_sculptLodInCastRay;
  14053. // Shape detail level
  14054. else if (!part.Shape.SculptEntry)
  14055. lod = (int)m_primLodInCastRay;
  14056. // Try to get cached mesh if configured
  14057. ulong meshKey = 0;
  14058. FacetedMesh mesh = null;
  14059. if (m_useMeshCacheInCastRay)
  14060. {
  14061. meshKey = part.Shape.GetMeshKey(Vector3.One, (float)(4 << lod));
  14062. lock (m_cachedMeshes)
  14063. {
  14064. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  14065. }
  14066. }
  14067. // Create mesh if no cached mesh
  14068. if (mesh == null)
  14069. {
  14070. // Make an OMV prim to be able to mesh part
  14071. Primitive omvPrim = part.Shape.ToOmvPrimitive(posPart, rotPart);
  14072. byte[] sculptAsset = null;
  14073. if (omvPrim.Sculpt != null)
  14074. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  14075. // When part is mesh, get mesh
  14076. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  14077. {
  14078. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  14079. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, m_meshLodInCastRay, out mesh);
  14080. meshAsset = null;
  14081. }
  14082. // When part is sculpt, create mesh
  14083. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  14084. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  14085. {
  14086. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  14087. if (imgDecoder != null)
  14088. {
  14089. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  14090. if (sculpt != null)
  14091. {
  14092. mesh = primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, m_sculptLodInCastRay);
  14093. sculpt.Dispose();
  14094. }
  14095. }
  14096. }
  14097. // When part is shape, create mesh
  14098. else if (omvPrim.Sculpt == null)
  14099. {
  14100. if (
  14101. omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 &&
  14102. omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 &&
  14103. omvPrim.PrimData.PathSkew == 0.0 &&
  14104. omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0
  14105. )
  14106. rayTrans.ShapeNeedsEnds = false;
  14107. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_primLodInCastRay);
  14108. }
  14109. // Cache mesh if configured
  14110. if (m_useMeshCacheInCastRay && mesh != null)
  14111. {
  14112. lock(m_cachedMeshes)
  14113. {
  14114. if (!m_cachedMeshes.ContainsKey(meshKey))
  14115. m_cachedMeshes.Add(meshKey, mesh);
  14116. }
  14117. }
  14118. }
  14119. // Check mesh for ray hits
  14120. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  14121. mesh = null;
  14122. }
  14123. }
  14124. }
  14125. );
  14126. // Check avatar filter
  14127. if (!rejectAgents)
  14128. {
  14129. // Iterate over all avatars in region
  14130. World.ForEachRootScenePresence(
  14131. delegate (ScenePresence sp)
  14132. {
  14133. // Get bounding box
  14134. BoundingBoxOfScenePresence(sp, out Vector3 lower, out Vector3 upper);
  14135. // Parse avatar
  14136. Vector3 scalePart = upper - lower;
  14137. Vector3 posPart = sp.AbsolutePosition;
  14138. Quaternion rotPart = sp.GetWorldRotation();
  14139. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  14140. posPart = posPart + (lower + upper) * 0.5f * rotPart;
  14141. // Project ray
  14142. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  14143. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  14144. // Filter avatars by shape bounding boxes
  14145. Vector3 shapeBoxMax = new Vector3(0.5f + tol, 0.5f + tol, 0.5f + tol);
  14146. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  14147. {
  14148. // Prepare data needed to check for ray hits
  14149. RayTrans rayTrans = new RayTrans
  14150. {
  14151. PartId = sp.UUID,
  14152. GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID,
  14153. Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0,
  14154. ScalePart = scalePart,
  14155. PositionPart = posPart,
  14156. RotationPart = rotPart,
  14157. ShapeNeedsEnds = false,
  14158. Position1Ray = pos1Ray,
  14159. Position1RayProj = pos1RayProj,
  14160. VectorRayProj = pos2RayProj - pos1RayProj
  14161. };
  14162. // Try to get cached mesh if configured
  14163. PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere();
  14164. int lod = (int)m_avatarLodInCastRay;
  14165. ulong meshKey = prim.GetMeshKey(Vector3.One, (float)(4 << lod));
  14166. FacetedMesh mesh = null;
  14167. if (m_useMeshCacheInCastRay)
  14168. {
  14169. lock (m_cachedMeshes)
  14170. {
  14171. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  14172. }
  14173. }
  14174. // Create mesh if no cached mesh
  14175. if (mesh == null)
  14176. {
  14177. // Make OMV prim and create mesh
  14178. prim.Scale = scalePart;
  14179. Primitive omvPrim = prim.ToOmvPrimitive(posPart, rotPart);
  14180. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_avatarLodInCastRay);
  14181. // Cache mesh if configured
  14182. if (m_useMeshCacheInCastRay && mesh != null)
  14183. {
  14184. lock(m_cachedMeshes)
  14185. {
  14186. if (!m_cachedMeshes.ContainsKey(meshKey))
  14187. m_cachedMeshes.Add(meshKey, mesh);
  14188. }
  14189. }
  14190. }
  14191. // Check mesh for ray hits
  14192. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  14193. mesh = null;
  14194. }
  14195. }
  14196. );
  14197. }
  14198. // Check terrain filter
  14199. if (!rejectLand)
  14200. {
  14201. // Parse terrain
  14202. // Mesh terrain and check bounding box
  14203. List<Tri> triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out Vector3 lower, out Vector3 upper);
  14204. lower.Z -= tol;
  14205. upper.Z += tol;
  14206. if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z))
  14207. {
  14208. // Prepare data needed to check for ray hits
  14209. RayTrans rayTrans = new RayTrans
  14210. {
  14211. PartId = UUID.Zero,
  14212. GroupId = UUID.Zero,
  14213. Link = 0,
  14214. ScalePart = new Vector3(1.0f, 1.0f, 1.0f),
  14215. PositionPart = Vector3.Zero,
  14216. RotationPart = Quaternion.Identity,
  14217. ShapeNeedsEnds = true,
  14218. Position1Ray = pos1Ray,
  14219. Position1RayProj = pos1Ray,
  14220. VectorRayProj = vecRay
  14221. };
  14222. // Check mesh
  14223. AddRayInTris(triangles, rayTrans, ref rayHits);
  14224. triangles = null;
  14225. }
  14226. }
  14227. // Sort hits by ascending distance
  14228. rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance));
  14229. // Check excess hits per part and group
  14230. for (int t = 0; t < 2; t++)
  14231. {
  14232. int maxHitsPerType = 0;
  14233. UUID id = UUID.Zero;
  14234. if (t == 0)
  14235. maxHitsPerType = m_maxHitsPerPrimInCastRay;
  14236. else
  14237. maxHitsPerType = m_maxHitsPerObjectInCastRay;
  14238. // Handle excess hits only when needed
  14239. if (maxHitsPerType < m_maxHitsInCastRay)
  14240. {
  14241. // Find excess hits
  14242. Hashtable hits = new Hashtable();
  14243. for (int i = rayHits.Count - 1; i >= 0; i--)
  14244. {
  14245. if (t == 0)
  14246. id = rayHits[i].PartId;
  14247. else
  14248. id = rayHits[i].GroupId;
  14249. if (hits.ContainsKey(id))
  14250. hits[id] = (int)hits[id] + 1;
  14251. else
  14252. hits[id] = 1;
  14253. }
  14254. // Remove excess hits
  14255. for (int i = rayHits.Count - 1; i >= 0; i--)
  14256. {
  14257. if (t == 0)
  14258. id = rayHits[i].PartId;
  14259. else
  14260. id = rayHits[i].GroupId;
  14261. int hit = (int)hits[id];
  14262. if (hit > m_maxHitsPerPrimInCastRay)
  14263. {
  14264. rayHits.RemoveAt(i);
  14265. hit--;
  14266. hits[id] = hit;
  14267. }
  14268. }
  14269. }
  14270. }
  14271. // Parse hits into result list according to data flags
  14272. int hitCount = rayHits.Count;
  14273. if (hitCount > maxHits)
  14274. hitCount = maxHits;
  14275. for (int i = 0; i < hitCount; i++)
  14276. {
  14277. RayHit rayHit = rayHits[i];
  14278. if (getRootKey)
  14279. result.Add(new LSL_Key(rayHit.GroupId.ToString()));
  14280. else
  14281. result.Add(new LSL_Key(rayHit.PartId.ToString()));
  14282. result.Add(new LSL_Vector(rayHit.Position));
  14283. if (getLinkNum)
  14284. result.Add(new LSL_Integer(rayHit.Link));
  14285. if (getNormal)
  14286. result.Add(new LSL_Vector(rayHit.Normal));
  14287. }
  14288. result.Add(new LSL_Integer(hitCount));
  14289. // Add to throttle data
  14290. stopWatch.Stop();
  14291. lock (m_castRayCalls)
  14292. {
  14293. CastRayCall castRayCall = new CastRayCall
  14294. {
  14295. RegionId = regionId,
  14296. UserId = userId,
  14297. CalledMs = calledMs,
  14298. UsedMs = (int)stopWatch.ElapsedMilliseconds
  14299. };
  14300. m_castRayCalls.Add(castRayCall);
  14301. }
  14302. // Return hits
  14303. return result;
  14304. }
  14305. /// <summary>
  14306. /// Struct for transmitting parameters required for finding llCastRay ray hits.
  14307. /// </summary>
  14308. public struct RayTrans
  14309. {
  14310. public UUID PartId;
  14311. public UUID GroupId;
  14312. public int Link;
  14313. public Vector3 ScalePart;
  14314. public Vector3 PositionPart;
  14315. public Quaternion RotationPart;
  14316. public bool ShapeNeedsEnds;
  14317. public Vector3 Position1Ray;
  14318. public Vector3 Position1RayProj;
  14319. public Vector3 VectorRayProj;
  14320. }
  14321. /// <summary>
  14322. /// Struct for llCastRay ray hits.
  14323. /// </summary>
  14324. public struct RayHit
  14325. {
  14326. public UUID PartId;
  14327. public UUID GroupId;
  14328. public int Link;
  14329. public Vector3 Position;
  14330. public Vector3 Normal;
  14331. public float Distance;
  14332. }
  14333. /// <summary>
  14334. /// Struct for llCastRay throttle data.
  14335. /// </summary>
  14336. public struct CastRayCall
  14337. {
  14338. public UUID RegionId;
  14339. public UUID UserId;
  14340. public int CalledMs;
  14341. public int UsedMs;
  14342. }
  14343. /// <summary>
  14344. /// Helper to check if a ray intersects a shape bounding box.
  14345. /// </summary>
  14346. private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax)
  14347. {
  14348. // Skip if ray can't intersect bounding box;
  14349. Vector3 rayBoxProjMin = Vector3.Min(pos1RayProj, pos2RayProj);
  14350. Vector3 rayBoxProjMax = Vector3.Max(pos1RayProj, pos2RayProj);
  14351. if (
  14352. rayBoxProjMin.X > shapeBoxMax.X || rayBoxProjMin.Y > shapeBoxMax.Y || rayBoxProjMin.Z > shapeBoxMax.Z ||
  14353. rayBoxProjMax.X < -shapeBoxMax.X || rayBoxProjMax.Y < -shapeBoxMax.Y || rayBoxProjMax.Z < -shapeBoxMax.Z
  14354. )
  14355. return false;
  14356. // Check if ray intersect any bounding box side
  14357. int sign = 0;
  14358. float dist = 0.0f;
  14359. Vector3 posProj = Vector3.Zero;
  14360. Vector3 vecRayProj = pos2RayProj - pos1RayProj;
  14361. // Check both X sides unless ray is parallell to them
  14362. if (Math.Abs(vecRayProj.X) > m_floatToleranceInCastRay)
  14363. {
  14364. for (sign = -1; sign <= 1; sign += 2)
  14365. {
  14366. dist = ((float)sign * shapeBoxMax.X - pos1RayProj.X) / vecRayProj.X;
  14367. posProj = pos1RayProj + vecRayProj * dist;
  14368. if (Math.Abs(posProj.Y) <= shapeBoxMax.Y && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14369. return true;
  14370. }
  14371. }
  14372. // Check both Y sides unless ray is parallell to them
  14373. if (Math.Abs(vecRayProj.Y) > m_floatToleranceInCastRay)
  14374. {
  14375. for (sign = -1; sign <= 1; sign += 2)
  14376. {
  14377. dist = ((float)sign * shapeBoxMax.Y - pos1RayProj.Y) / vecRayProj.Y;
  14378. posProj = pos1RayProj + vecRayProj * dist;
  14379. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14380. return true;
  14381. }
  14382. }
  14383. // Check both Z sides unless ray is parallell to them
  14384. if (Math.Abs(vecRayProj.Z) > m_floatToleranceInCastRay)
  14385. {
  14386. for (sign = -1; sign <= 1; sign += 2)
  14387. {
  14388. dist = ((float)sign * shapeBoxMax.Z - pos1RayProj.Z) / vecRayProj.Z;
  14389. posProj = pos1RayProj + vecRayProj * dist;
  14390. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Y) <= shapeBoxMax.Y)
  14391. return true;
  14392. }
  14393. }
  14394. // No hits on bounding box so return false
  14395. return false;
  14396. }
  14397. /// <summary>
  14398. /// Helper to parse FacetedMesh for ray hits.
  14399. /// </summary>
  14400. private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  14401. {
  14402. if (mesh != null)
  14403. {
  14404. foreach (Face face in mesh.Faces)
  14405. {
  14406. for (int i = 0; i < face.Indices.Count; i += 3)
  14407. {
  14408. Tri triangle = new Tri
  14409. {
  14410. p1 = face.Vertices[face.Indices[i]].Position,
  14411. p2 = face.Vertices[face.Indices[i + 1]].Position,
  14412. p3 = face.Vertices[face.Indices[i + 2]].Position
  14413. };
  14414. AddRayInTri(triangle, rayTrans, ref rayHits);
  14415. }
  14416. }
  14417. }
  14418. }
  14419. /// <summary>
  14420. /// Helper to parse Tri (triangle) List for ray hits.
  14421. /// </summary>
  14422. private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits)
  14423. {
  14424. foreach (Tri triangle in triangles)
  14425. {
  14426. AddRayInTri(triangle, rayTrans, ref rayHits);
  14427. }
  14428. }
  14429. /// <summary>
  14430. /// Helper to add ray hit in a Tri (triangle).
  14431. /// </summary>
  14432. private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits)
  14433. {
  14434. // Check for hit in triangle
  14435. if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out Vector3 posHitProj, out Vector3 normalProj))
  14436. {
  14437. // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center
  14438. if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds)
  14439. return;
  14440. // Transform hit and normal to region coordinate system
  14441. Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart;
  14442. Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart);
  14443. // Remove duplicate hits at triangle intersections
  14444. float distance = Vector3.Distance(rayTrans.Position1Ray, posHit);
  14445. for (int i = rayHits.Count - 1; i >= 0; i--)
  14446. {
  14447. if (rayHits[i].PartId != rayTrans.PartId)
  14448. break;
  14449. if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay)
  14450. return;
  14451. }
  14452. // Build result data set
  14453. RayHit rayHit = new RayHit
  14454. {
  14455. PartId = rayTrans.PartId,
  14456. GroupId = rayTrans.GroupId,
  14457. Link = rayTrans.Link,
  14458. Position = posHit,
  14459. Normal = normal,
  14460. Distance = distance
  14461. };
  14462. rayHits.Add(rayHit);
  14463. }
  14464. }
  14465. /// <summary>
  14466. /// Helper to find ray hit in triangle
  14467. /// </summary>
  14468. bool HitRayInTri(Tri triProj, Vector3 pos1RayProj, Vector3 vecRayProj, out Vector3 posHitProj, out Vector3 normalProj)
  14469. {
  14470. float tol = m_floatToleranceInCastRay;
  14471. posHitProj = Vector3.Zero;
  14472. // Calculate triangle edge vectors
  14473. Vector3 vec1Proj = triProj.p2 - triProj.p1;
  14474. Vector3 vec2Proj = triProj.p3 - triProj.p2;
  14475. Vector3 vec3Proj = triProj.p1 - triProj.p3;
  14476. // Calculate triangle normal
  14477. normalProj = Vector3.Cross(vec1Proj, vec2Proj);
  14478. // Skip if degenerate triangle or ray parallell with triangle plane
  14479. float divisor = Vector3.Dot(vecRayProj, normalProj);
  14480. if (Math.Abs(divisor) < tol)
  14481. return false;
  14482. // Skip if exit and not configured to detect
  14483. if (divisor > tol && !m_detectExitsInCastRay)
  14484. return false;
  14485. // Skip if outside ray ends
  14486. float distanceProj = Vector3.Dot(triProj.p1 - pos1RayProj, normalProj) / divisor;
  14487. if (distanceProj < -tol || distanceProj > 1 + tol)
  14488. return false;
  14489. // Calculate hit position in triangle
  14490. posHitProj = pos1RayProj + vecRayProj * distanceProj;
  14491. // Skip if outside triangle bounding box
  14492. Vector3 triProjMin = Vector3.Min(Vector3.Min(triProj.p1, triProj.p2), triProj.p3);
  14493. Vector3 triProjMax = Vector3.Max(Vector3.Max(triProj.p1, triProj.p2), triProj.p3);
  14494. if (
  14495. posHitProj.X < triProjMin.X - tol || posHitProj.Y < triProjMin.Y - tol || posHitProj.Z < triProjMin.Z - tol ||
  14496. posHitProj.X > triProjMax.X + tol || posHitProj.Y > triProjMax.Y + tol || posHitProj.Z > triProjMax.Z + tol
  14497. )
  14498. return false;
  14499. // Skip if outside triangle
  14500. if (
  14501. Vector3.Dot(Vector3.Cross(vec1Proj, normalProj), posHitProj - triProj.p1) > tol ||
  14502. Vector3.Dot(Vector3.Cross(vec2Proj, normalProj), posHitProj - triProj.p2) > tol ||
  14503. Vector3.Dot(Vector3.Cross(vec3Proj, normalProj), posHitProj - triProj.p3) > tol
  14504. )
  14505. return false;
  14506. // Return hit
  14507. return true;
  14508. }
  14509. /// <summary>
  14510. /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box.
  14511. /// </summary>
  14512. private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper)
  14513. {
  14514. // Get bounding X-Y rectangle of terrain under ray
  14515. lower = Vector3.Min(posStart, posEnd);
  14516. upper = Vector3.Max(posStart, posEnd);
  14517. lower.X = (float)Math.Floor(lower.X);
  14518. lower.Y = (float)Math.Floor(lower.Y);
  14519. float zLower = float.MaxValue;
  14520. upper.X = (float)Math.Ceiling(upper.X);
  14521. upper.Y = (float)Math.Ceiling(upper.Y);
  14522. float zUpper = float.MinValue;
  14523. // Initialize Tri (triangle) List
  14524. List<Tri> triangles = new List<Tri>();
  14525. // Set parsing lane direction to major ray X-Y axis
  14526. Vector3 vec = posEnd - posStart;
  14527. float xAbs = Math.Abs(vec.X);
  14528. float yAbs = Math.Abs(vec.Y);
  14529. bool bigX = true;
  14530. if (yAbs > xAbs)
  14531. {
  14532. bigX = false;
  14533. vec = vec / yAbs;
  14534. }
  14535. else if (xAbs > yAbs || xAbs > 0.0f)
  14536. vec = vec / xAbs;
  14537. else
  14538. vec = new Vector3(1.0f, 1.0f, 0.0f);
  14539. // Simplify by start parsing in lower end of lane
  14540. if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f))
  14541. {
  14542. Vector3 posTemp = posStart;
  14543. posStart = posEnd;
  14544. posEnd = posTemp;
  14545. vec = vec * -1.0f;
  14546. }
  14547. // First 1x1 rectangle under ray
  14548. float xFloorOld = 0.0f;
  14549. float yFloorOld = 0.0f;
  14550. Vector3 pos = posStart;
  14551. float xFloor = (float)Math.Floor(pos.X);
  14552. float yFloor = (float)Math.Floor(pos.Y);
  14553. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14554. // Parse every remaining 1x1 rectangle under ray
  14555. while (pos != posEnd)
  14556. {
  14557. // Next 1x1 rectangle under ray
  14558. xFloorOld = xFloor;
  14559. yFloorOld = yFloor;
  14560. pos = pos + vec;
  14561. // Clip position to 1x1 rectangle border
  14562. xFloor = (float)Math.Floor(pos.X);
  14563. yFloor = (float)Math.Floor(pos.Y);
  14564. if (bigX && pos.X > xFloor)
  14565. {
  14566. pos.Y -= vec.Y * (pos.X - xFloor);
  14567. pos.X = xFloor;
  14568. }
  14569. else if (!bigX && pos.Y > yFloor)
  14570. {
  14571. pos.X -= vec.X * (pos.Y - yFloor);
  14572. pos.Y = yFloor;
  14573. }
  14574. // Last 1x1 rectangle under ray
  14575. if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y))
  14576. {
  14577. pos = posEnd;
  14578. xFloor = (float)Math.Floor(pos.X);
  14579. yFloor = (float)Math.Floor(pos.Y);
  14580. }
  14581. // Add new 1x1 rectangle in lane
  14582. if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld))
  14583. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14584. // Add last 1x1 rectangle in old lane at lane shift
  14585. if (bigX && yFloor != yFloorOld)
  14586. AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper);
  14587. if (!bigX && xFloor != xFloorOld)
  14588. AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper);
  14589. }
  14590. // Finalize bounding box Z
  14591. lower.Z = zLower;
  14592. upper.Z = zUpper;
  14593. // Done and returning Tri (triangle)List
  14594. return triangles;
  14595. }
  14596. /// <summary>
  14597. /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box.
  14598. /// </summary>
  14599. private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper)
  14600. {
  14601. int xInt = (int)xPos;
  14602. int yInt = (int)yPos;
  14603. // Corner 1 of 1x1 rectangle
  14604. int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14605. int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14606. Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14607. // Adjust bounding box
  14608. zLower = Math.Min(zLower, pos1.Z);
  14609. zUpper = Math.Max(zUpper, pos1.Z);
  14610. // Corner 2 of 1x1 rectangle
  14611. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14612. y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14613. Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14614. // Adjust bounding box
  14615. zLower = Math.Min(zLower, pos2.Z);
  14616. zUpper = Math.Max(zUpper, pos2.Z);
  14617. // Corner 3 of 1x1 rectangle
  14618. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14619. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14620. Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14621. // Adjust bounding box
  14622. zLower = Math.Min(zLower, pos3.Z);
  14623. zUpper = Math.Max(zUpper, pos3.Z);
  14624. // Corner 4 of 1x1 rectangle
  14625. x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14626. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14627. Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14628. // Adjust bounding box
  14629. zLower = Math.Min(zLower, pos4.Z);
  14630. zUpper = Math.Max(zUpper, pos4.Z);
  14631. // Add triangle 1
  14632. Tri triangle1 = new Tri
  14633. {
  14634. p1 = pos1,
  14635. p2 = pos2,
  14636. p3 = pos3
  14637. };
  14638. triangles.Add(triangle1);
  14639. // Add triangle 2
  14640. Tri triangle2 = new Tri
  14641. {
  14642. p1 = pos3,
  14643. p2 = pos4,
  14644. p3 = pos1
  14645. };
  14646. triangles.Add(triangle2);
  14647. }
  14648. /// <summary>
  14649. /// Helper to get link number for a UUID.
  14650. /// </summary>
  14651. private int UUID2LinkNumber(SceneObjectPart part, UUID id)
  14652. {
  14653. SceneObjectGroup group = part.ParentGroup;
  14654. if (group != null)
  14655. {
  14656. // Parse every link for UUID
  14657. int linkCount = group.PrimCount + group.GetSittingAvatarsCount();
  14658. for (int link = linkCount; link > 0; link--)
  14659. {
  14660. ISceneEntity entity = GetLinkEntity(part, link);
  14661. // Return link number if UUID match
  14662. if (entity != null && entity.UUID == id)
  14663. return link;
  14664. }
  14665. }
  14666. // Return link number 0 if no links or UUID matches
  14667. return 0;
  14668. }
  14669. public LSL_Integer llManageEstateAccess(int action, string avatar)
  14670. {
  14671. m_host.AddScriptLPS(1);
  14672. EstateSettings estate = World.RegionInfo.EstateSettings;
  14673. bool isAccount = false;
  14674. bool isGroup = false;
  14675. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  14676. return 0;
  14677. UUID id = new UUID();
  14678. if (!UUID.TryParse(avatar, out id))
  14679. return 0;
  14680. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, id);
  14681. isAccount = account != null ? true : false;
  14682. if (!isAccount)
  14683. {
  14684. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  14685. if (groups != null)
  14686. {
  14687. GroupRecord group = groups.GetGroupRecord(id);
  14688. isGroup = group != null ? true : false;
  14689. if (!isGroup)
  14690. return 0;
  14691. }
  14692. else
  14693. return 0;
  14694. }
  14695. switch (action)
  14696. {
  14697. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  14698. if (!isAccount) return 0;
  14699. if (estate.HasAccess(id)) return 1;
  14700. if (estate.IsBanned(id, World.GetUserFlags(id)))
  14701. estate.RemoveBan(id);
  14702. estate.AddEstateUser(id);
  14703. break;
  14704. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  14705. if (!isAccount || !estate.HasAccess(id)) return 0;
  14706. estate.RemoveEstateUser(id);
  14707. break;
  14708. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  14709. if (!isGroup) return 0;
  14710. if (estate.GroupAccess(id)) return 1;
  14711. estate.AddEstateGroup(id);
  14712. break;
  14713. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  14714. if (!isGroup || !estate.GroupAccess(id)) return 0;
  14715. estate.RemoveEstateGroup(id);
  14716. break;
  14717. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  14718. if (!isAccount) return 0;
  14719. if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
  14720. EstateBan ban = new EstateBan
  14721. {
  14722. EstateID = estate.EstateID,
  14723. BannedUserID = id
  14724. };
  14725. estate.AddBan(ban);
  14726. break;
  14727. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  14728. if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
  14729. estate.RemoveBan(id);
  14730. break;
  14731. default: return 0;
  14732. }
  14733. return 1;
  14734. }
  14735. public LSL_Integer llGetMemoryLimit()
  14736. {
  14737. m_host.AddScriptLPS(1);
  14738. // The value returned for Mono scripts in SL
  14739. return 65536;
  14740. }
  14741. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  14742. {
  14743. m_host.AddScriptLPS(1);
  14744. // Treat as an LSO script
  14745. return ScriptBaseClass.FALSE;
  14746. }
  14747. public LSL_Integer llGetSPMaxMemory()
  14748. {
  14749. m_host.AddScriptLPS(1);
  14750. // The value returned for Mono scripts in SL
  14751. return 65536;
  14752. }
  14753. public virtual LSL_Integer llGetUsedMemory()
  14754. {
  14755. m_host.AddScriptLPS(1);
  14756. // The value returned for Mono scripts in SL
  14757. return 65536;
  14758. }
  14759. public void llScriptProfiler(LSL_Integer flags)
  14760. {
  14761. m_host.AddScriptLPS(1);
  14762. // This does nothing for LSO scripts in SL
  14763. }
  14764. #region Not Implemented
  14765. //
  14766. // Listing the unimplemented lsl functions here, please move
  14767. // them from this region as they are completed
  14768. //
  14769. public void llSetSoundQueueing(int queue)
  14770. {
  14771. m_host.AddScriptLPS(1);
  14772. if (m_SoundModule != null)
  14773. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  14774. }
  14775. public void llCollisionSprite(LSL_String impact_sprite)
  14776. {
  14777. m_host.AddScriptLPS(1);
  14778. // Viewer 2.0 broke this and it's likely LL has no intention
  14779. // of fixing it. Therefore, letting this be a NOP seems appropriate.
  14780. }
  14781. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  14782. {
  14783. m_host.AddScriptLPS(1);
  14784. if (!World.Permissions.IsGod(m_host.OwnerID))
  14785. NotImplemented("llGodLikeRezObject");
  14786. AssetBase rezAsset = World.AssetService.Get(inventory);
  14787. if (rezAsset == null)
  14788. {
  14789. llSay(0, "Asset not found");
  14790. return;
  14791. }
  14792. SceneObjectGroup group = null;
  14793. try
  14794. {
  14795. string xmlData = Utils.BytesToString(rezAsset.Data);
  14796. group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
  14797. }
  14798. catch
  14799. {
  14800. llSay(0, "Asset not found");
  14801. return;
  14802. }
  14803. if (group == null)
  14804. {
  14805. llSay(0, "Asset not found");
  14806. return;
  14807. }
  14808. group.RootPart.AttachedPos = group.AbsolutePosition;
  14809. group.ResetIDs();
  14810. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  14811. World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
  14812. group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
  14813. group.ScheduleGroupForFullUpdate();
  14814. // objects rezzed with this method are die_at_edge by default.
  14815. group.RootPart.SetDieAtEdge(true);
  14816. group.ResumeScripts();
  14817. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  14818. "object_rez", new Object[] {
  14819. new LSL_String(
  14820. group.RootPart.UUID.ToString()) },
  14821. new DetectParams[0]));
  14822. }
  14823. public LSL_Key llTransferLindenDollars(LSL_Key destination, LSL_Integer amount)
  14824. {
  14825. m_host.AddScriptLPS(1);
  14826. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  14827. UUID txn = UUID.Random();
  14828. UUID toID = UUID.Zero;
  14829. string replydata = "UnKnownError";
  14830. bool bad = true;
  14831. while(true)
  14832. {
  14833. if (amount <= 0)
  14834. {
  14835. replydata = "INVALID_AMOUNT";
  14836. break;
  14837. }
  14838. if (money == null)
  14839. {
  14840. replydata = "TRANSFERS_DISABLED";
  14841. break;
  14842. }
  14843. if (m_host.OwnerID == m_host.GroupID)
  14844. {
  14845. replydata = "GROUP_OWNED";
  14846. break;
  14847. }
  14848. if (m_item == null)
  14849. {
  14850. replydata = "SERVICE_ERROR";
  14851. break;
  14852. }
  14853. if (m_item.PermsGranter == UUID.Zero)
  14854. {
  14855. replydata = "MISSING_PERMISSION_DEBIT";
  14856. break;
  14857. }
  14858. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  14859. {
  14860. replydata = "MISSING_PERMISSION_DEBIT";
  14861. break;
  14862. }
  14863. if (!UUID.TryParse(destination, out toID))
  14864. {
  14865. replydata = "INVALID_AGENT";
  14866. break;
  14867. }
  14868. bad = false;
  14869. break;
  14870. }
  14871. if(bad)
  14872. {
  14873. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14874. "transaction_result", new Object[] {
  14875. new LSL_String(txn.ToString()),
  14876. new LSL_Integer(0),
  14877. new LSL_String(replydata) },
  14878. new DetectParams[0]));
  14879. return txn.ToString();
  14880. }
  14881. //fire and forget...
  14882. Action<string> act = eventID =>
  14883. {
  14884. int replycode = 0;
  14885. try
  14886. {
  14887. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, toID);
  14888. if (account == null)
  14889. {
  14890. replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST";
  14891. return;
  14892. }
  14893. bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID,
  14894. toID, amount, txn, out string reason);
  14895. if (result)
  14896. {
  14897. replycode = 1;
  14898. replydata = destination + "," + amount.ToString();
  14899. return;
  14900. }
  14901. replydata = reason;
  14902. }
  14903. finally
  14904. {
  14905. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14906. "transaction_result", new Object[] {
  14907. new LSL_String(txn.ToString()),
  14908. new LSL_Integer(replycode),
  14909. new LSL_String(replydata) },
  14910. new DetectParams[0]));
  14911. }
  14912. };
  14913. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  14914. return txn.ToString();
  14915. }
  14916. #endregion
  14917. protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
  14918. {
  14919. //This is a special version of SetPrimParams to deal with avatars which are sitting on the linkset.
  14920. int idx = 0;
  14921. int idxStart = 0;
  14922. bool positionChanged = false;
  14923. try
  14924. {
  14925. while (idx < rules.Length)
  14926. {
  14927. ++rulesParsed;
  14928. int code = rules.GetLSLIntegerItem(idx++);
  14929. int remain = rules.Length - idx;
  14930. idxStart = idx;
  14931. switch (code)
  14932. {
  14933. case (int)ScriptBaseClass.PRIM_POSITION:
  14934. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14935. {
  14936. if (remain < 1)
  14937. return new LSL_List();
  14938. LSL_Vector v;
  14939. v = rules.GetVector3Item(idx++);
  14940. if(!av.LegacySitOffsets)
  14941. {
  14942. LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
  14943. v = v + 2 * sitOffset;
  14944. }
  14945. av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
  14946. positionChanged = true;
  14947. }
  14948. break;
  14949. case (int)ScriptBaseClass.PRIM_ROTATION:
  14950. {
  14951. if (remain < 1)
  14952. return new LSL_List();
  14953. Quaternion r;
  14954. r = rules.GetQuaternionItem(idx++);
  14955. av.Rotation = m_host.GetWorldRotation() * r;
  14956. positionChanged = true;
  14957. }
  14958. break;
  14959. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14960. {
  14961. if (remain < 1)
  14962. return new LSL_List();
  14963. LSL_Rotation r;
  14964. r = rules.GetQuaternionItem(idx++);
  14965. av.Rotation = r;
  14966. positionChanged = true;
  14967. }
  14968. break;
  14969. // parse rest doing nothing but number of parameters error check
  14970. case (int)ScriptBaseClass.PRIM_SIZE:
  14971. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14972. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14973. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14974. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  14975. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14976. case (int)ScriptBaseClass.PRIM_NAME:
  14977. case (int)ScriptBaseClass.PRIM_DESC:
  14978. if (remain < 1)
  14979. return new LSL_List();
  14980. idx++;
  14981. break;
  14982. case (int)ScriptBaseClass.PRIM_GLOW:
  14983. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14984. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14985. if (remain < 2)
  14986. return new LSL_List();
  14987. idx += 2;
  14988. break;
  14989. case (int)ScriptBaseClass.PRIM_TYPE:
  14990. if (remain < 3)
  14991. return new LSL_List();
  14992. code = (int)rules.GetLSLIntegerItem(idx++);
  14993. remain = rules.Length - idx;
  14994. switch (code)
  14995. {
  14996. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  14997. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  14998. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  14999. if (remain < 6)
  15000. return new LSL_List();
  15001. idx += 6;
  15002. break;
  15003. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  15004. if (remain < 5)
  15005. return new LSL_List();
  15006. idx += 5;
  15007. break;
  15008. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  15009. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  15010. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  15011. if (remain < 11)
  15012. return new LSL_List();
  15013. idx += 11;
  15014. break;
  15015. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  15016. if (remain < 2)
  15017. return new LSL_List();
  15018. idx += 2;
  15019. break;
  15020. }
  15021. break;
  15022. case (int)ScriptBaseClass.PRIM_COLOR:
  15023. case (int)ScriptBaseClass.PRIM_TEXT:
  15024. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  15025. case (int)ScriptBaseClass.PRIM_OMEGA:
  15026. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  15027. if (remain < 3)
  15028. return new LSL_List();
  15029. idx += 3;
  15030. break;
  15031. case (int)ScriptBaseClass.PRIM_TEXTURE:
  15032. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  15033. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  15034. if (remain < 5)
  15035. return new LSL_List();
  15036. idx += 5;
  15037. break;
  15038. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  15039. if (remain < 7)
  15040. return new LSL_List();
  15041. idx += 7;
  15042. break;
  15043. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  15044. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  15045. return new LSL_List();
  15046. return rules.GetSublist(idx, -1);
  15047. }
  15048. }
  15049. }
  15050. catch (InvalidCastException e)
  15051. {
  15052. Error(originFunc,string.Format(
  15053. " error running rule #{0}: arg #{1} {2}",
  15054. rulesParsed, idx - idxStart, e.Message));
  15055. }
  15056. finally
  15057. {
  15058. if (positionChanged)
  15059. av.SendTerseUpdateToAllClients();
  15060. }
  15061. return new LSL_List();
  15062. }
  15063. public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
  15064. {
  15065. // avatars case
  15066. // replies as SL wiki
  15067. // SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
  15068. SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
  15069. int idx = 0;
  15070. while (idx < rules.Length)
  15071. {
  15072. int code = (int)rules.GetLSLIntegerItem(idx++);
  15073. int remain = rules.Length - idx;
  15074. switch (code)
  15075. {
  15076. case (int)ScriptBaseClass.PRIM_MATERIAL:
  15077. res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
  15078. break;
  15079. case (int)ScriptBaseClass.PRIM_PHYSICS:
  15080. res.Add(new LSL_Integer(0));
  15081. break;
  15082. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  15083. res.Add(new LSL_Integer(0));
  15084. break;
  15085. case (int)ScriptBaseClass.PRIM_PHANTOM:
  15086. res.Add(new LSL_Integer(0));
  15087. break;
  15088. case (int)ScriptBaseClass.PRIM_POSITION:
  15089. Vector3 pos;
  15090. if (sitPart.ParentGroup.RootPart != null)
  15091. {
  15092. pos = avatar.OffsetPosition;
  15093. if(!avatar.LegacySitOffsets)
  15094. {
  15095. Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
  15096. pos -= sitOffset;
  15097. }
  15098. SceneObjectPart sitroot = sitPart.ParentGroup.RootPart;
  15099. pos = sitroot.AbsolutePosition + pos * sitroot.GetWorldRotation();
  15100. }
  15101. else
  15102. pos = avatar.AbsolutePosition;
  15103. res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
  15104. break;
  15105. case (int)ScriptBaseClass.PRIM_SIZE:
  15106. Vector3 s = avatar.Appearance.AvatarSize;
  15107. res.Add(new LSL_Vector(s.X, s.Y, s.Z));
  15108. break;
  15109. case (int)ScriptBaseClass.PRIM_ROTATION:
  15110. res.Add(new LSL_Rotation(avatar.GetWorldRotation()));
  15111. break;
  15112. case (int)ScriptBaseClass.PRIM_TYPE:
  15113. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  15114. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  15115. res.Add(new LSL_Vector(0f,1.0f,0f));
  15116. res.Add(new LSL_Float(0.0f));
  15117. res.Add(new LSL_Vector(0, 0, 0));
  15118. res.Add(new LSL_Vector(1.0f,1.0f,0f));
  15119. res.Add(new LSL_Vector(0, 0, 0));
  15120. break;
  15121. case (int)ScriptBaseClass.PRIM_TEXTURE:
  15122. if (remain < 1)
  15123. return new LSL_List();
  15124. int face = (int)rules.GetLSLIntegerItem(idx++);
  15125. if (face == ScriptBaseClass.ALL_SIDES)
  15126. {
  15127. for (face = 0; face < 21; face++)
  15128. {
  15129. res.Add(new LSL_String(""));
  15130. res.Add(new LSL_Vector(0,0,0));
  15131. res.Add(new LSL_Vector(0,0,0));
  15132. res.Add(new LSL_Float(0.0));
  15133. }
  15134. }
  15135. else
  15136. {
  15137. if (face >= 0 && face < 21)
  15138. {
  15139. res.Add(new LSL_String(""));
  15140. res.Add(new LSL_Vector(0,0,0));
  15141. res.Add(new LSL_Vector(0,0,0));
  15142. res.Add(new LSL_Float(0.0));
  15143. }
  15144. }
  15145. break;
  15146. case (int)ScriptBaseClass.PRIM_COLOR:
  15147. if (remain < 1)
  15148. return new LSL_List();
  15149. face = (int)rules.GetLSLIntegerItem(idx++);
  15150. if (face == ScriptBaseClass.ALL_SIDES)
  15151. {
  15152. for (face = 0; face < 21; face++)
  15153. {
  15154. res.Add(new LSL_Vector(0,0,0));
  15155. res.Add(new LSL_Float(0));
  15156. }
  15157. }
  15158. else
  15159. {
  15160. res.Add(new LSL_Vector(0,0,0));
  15161. res.Add(new LSL_Float(0));
  15162. }
  15163. break;
  15164. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  15165. if (remain < 1)
  15166. return new LSL_List();
  15167. face = (int)rules.GetLSLIntegerItem(idx++);
  15168. if (face == ScriptBaseClass.ALL_SIDES)
  15169. {
  15170. for (face = 0; face < 21; face++)
  15171. {
  15172. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  15173. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  15174. }
  15175. }
  15176. else
  15177. {
  15178. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  15179. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  15180. }
  15181. break;
  15182. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  15183. if (remain < 1)
  15184. return new LSL_List();
  15185. face = (int)rules.GetLSLIntegerItem(idx++);
  15186. if (face == ScriptBaseClass.ALL_SIDES)
  15187. {
  15188. for (face = 0; face < 21; face++)
  15189. {
  15190. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  15191. }
  15192. }
  15193. else
  15194. {
  15195. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  15196. }
  15197. break;
  15198. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  15199. res.Add(new LSL_Integer(0));
  15200. res.Add(new LSL_Integer(0));// softness
  15201. res.Add(new LSL_Float(0.0f)); // gravity
  15202. res.Add(new LSL_Float(0.0f)); // friction
  15203. res.Add(new LSL_Float(0.0f)); // wind
  15204. res.Add(new LSL_Float(0.0f)); // tension
  15205. res.Add(new LSL_Vector(0f,0f,0f));
  15206. break;
  15207. case (int)ScriptBaseClass.PRIM_TEXGEN:
  15208. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  15209. if (remain < 1)
  15210. return new LSL_List();
  15211. face = (int)rules.GetLSLIntegerItem(idx++);
  15212. if (face == ScriptBaseClass.ALL_SIDES)
  15213. {
  15214. for (face = 0; face < 21; face++)
  15215. {
  15216. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  15217. }
  15218. }
  15219. else
  15220. {
  15221. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  15222. }
  15223. break;
  15224. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  15225. res.Add(new LSL_Integer(0));
  15226. res.Add(new LSL_Vector(0f,0f,0f));
  15227. res.Add(new LSL_Float(0f)); // intensity
  15228. res.Add(new LSL_Float(0f)); // radius
  15229. res.Add(new LSL_Float(0f)); // falloff
  15230. break;
  15231. case (int)ScriptBaseClass.PRIM_GLOW:
  15232. if (remain < 1)
  15233. return new LSL_List();
  15234. face = (int)rules.GetLSLIntegerItem(idx++);
  15235. if (face == ScriptBaseClass.ALL_SIDES)
  15236. {
  15237. for (face = 0; face < 21; face++)
  15238. {
  15239. res.Add(new LSL_Float(0f));
  15240. }
  15241. }
  15242. else
  15243. {
  15244. res.Add(new LSL_Float(0f));
  15245. }
  15246. break;
  15247. case (int)ScriptBaseClass.PRIM_TEXT:
  15248. res.Add(new LSL_String(""));
  15249. res.Add(new LSL_Vector(0f,0f,0f));
  15250. res.Add(new LSL_Float(1.0f));
  15251. break;
  15252. case (int)ScriptBaseClass.PRIM_NAME:
  15253. res.Add(new LSL_String(avatar.Name));
  15254. break;
  15255. case (int)ScriptBaseClass.PRIM_DESC:
  15256. res.Add(new LSL_String(""));
  15257. break;
  15258. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  15259. Quaternion lrot = avatar.Rotation;
  15260. res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
  15261. break;
  15262. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  15263. Vector3 lpos = avatar.OffsetPosition;
  15264. if(!avatar.LegacySitOffsets)
  15265. {
  15266. Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
  15267. lpos -= lsitOffset;
  15268. }
  15269. res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
  15270. break;
  15271. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  15272. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  15273. return new LSL_List();
  15274. return rules.GetSublist(idx, -1);
  15275. }
  15276. }
  15277. return new LSL_List();
  15278. }
  15279. public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
  15280. {
  15281. string state = String.Empty;
  15282. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15283. {
  15284. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15285. {
  15286. state = kvp.Key;
  15287. break;
  15288. }
  15289. }
  15290. if (state == String.Empty)
  15291. {
  15292. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Invalid animation state " + animState);
  15293. return;
  15294. }
  15295. if (m_item.PermsGranter == UUID.Zero)
  15296. {
  15297. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15298. return;
  15299. }
  15300. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  15301. {
  15302. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15303. return;
  15304. }
  15305. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15306. if (presence == null)
  15307. return;
  15308. UUID animID;
  15309. animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  15310. if (animID == UUID.Zero)
  15311. {
  15312. String animupper = ((string)anim).ToUpperInvariant();
  15313. DefaultAvatarAnimations.AnimsUUIDbyName.TryGetValue(animupper, out animID);
  15314. }
  15315. if (animID == UUID.Zero)
  15316. {
  15317. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Animation not found");
  15318. return;
  15319. }
  15320. presence.SetAnimationOverride(state, animID);
  15321. }
  15322. public void llResetAnimationOverride(LSL_String animState)
  15323. {
  15324. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15325. if (presence == null)
  15326. return;
  15327. if (m_item.PermsGranter == UUID.Zero)
  15328. {
  15329. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15330. return;
  15331. }
  15332. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  15333. {
  15334. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15335. return;
  15336. }
  15337. if (animState == "ALL")
  15338. {
  15339. presence.SetAnimationOverride("ALL", UUID.Zero);
  15340. return;
  15341. }
  15342. string state = String.Empty;
  15343. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15344. {
  15345. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15346. {
  15347. state = kvp.Key;
  15348. break;
  15349. }
  15350. }
  15351. if (state == String.Empty)
  15352. {
  15353. return;
  15354. }
  15355. presence.SetAnimationOverride(state, UUID.Zero);
  15356. }
  15357. public LSL_String llGetAnimationOverride(LSL_String animState)
  15358. {
  15359. m_host.AddScriptLPS(1);
  15360. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15361. if (presence == null)
  15362. return String.Empty;
  15363. if (m_item.PermsGranter == UUID.Zero)
  15364. {
  15365. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15366. return String.Empty;
  15367. }
  15368. if ((m_item.PermsMask & (ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION)) == 0)
  15369. {
  15370. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15371. return String.Empty;
  15372. }
  15373. string state = String.Empty;
  15374. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15375. {
  15376. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15377. {
  15378. state = kvp.Key;
  15379. break;
  15380. }
  15381. }
  15382. if (state == String.Empty)
  15383. {
  15384. return String.Empty;
  15385. }
  15386. UUID animID = presence.GetAnimationOverride(state);
  15387. if (animID == UUID.Zero)
  15388. return animState;
  15389. foreach (KeyValuePair<string, UUID> kvp in DefaultAvatarAnimations.AnimsUUIDbyName)
  15390. {
  15391. if (kvp.Value == animID)
  15392. return kvp.Key.ToLower();
  15393. }
  15394. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  15395. {
  15396. if (item.AssetID == animID)
  15397. return item.Name;
  15398. }
  15399. return String.Empty;
  15400. }
  15401. public LSL_Integer llGetDayLength()
  15402. {
  15403. m_host.AddScriptLPS(1);
  15404. if (m_envModule == null)
  15405. return 14400;
  15406. return m_envModule.GetDayLength(m_host.GetWorldPosition());
  15407. }
  15408. public LSL_Integer llGetRegionDayLength()
  15409. {
  15410. m_host.AddScriptLPS(1);
  15411. if (m_envModule == null)
  15412. return 14400;
  15413. return m_envModule.GetRegionDayLength();
  15414. }
  15415. public LSL_Integer llGetDayOffset()
  15416. {
  15417. m_host.AddScriptLPS(1);
  15418. if (m_envModule == null)
  15419. return 57600;
  15420. return m_envModule.GetDayOffset(m_host.GetWorldPosition());
  15421. }
  15422. public LSL_Integer llGetRegionDayOffset()
  15423. {
  15424. m_host.AddScriptLPS(1);
  15425. if (m_envModule == null)
  15426. return 57600;
  15427. return m_envModule.GetRegionDayOffset();
  15428. }
  15429. public LSL_Vector llGetSunDirection()
  15430. {
  15431. m_host.AddScriptLPS(1);
  15432. if (m_envModule == null)
  15433. return Vector3.Zero;
  15434. return m_envModule.GetSunDir(m_host.GetWorldPosition());
  15435. }
  15436. public LSL_Vector llGetRegionSunDirection()
  15437. {
  15438. m_host.AddScriptLPS(1);
  15439. if (m_envModule == null)
  15440. return Vector3.Zero;
  15441. float z = m_host.GetWorldPosition().Z;
  15442. return m_envModule.GetRegionSunDir(z);
  15443. }
  15444. public LSL_Vector llGetMoonDirection()
  15445. {
  15446. m_host.AddScriptLPS(1);
  15447. if (m_envModule == null)
  15448. return Vector3.Zero;
  15449. return m_envModule.GetMoonDir(m_host.GetWorldPosition());
  15450. }
  15451. public LSL_Vector llGetRegionMoonDirection()
  15452. {
  15453. m_host.AddScriptLPS(1);
  15454. if (m_envModule == null)
  15455. return Vector3.Zero;
  15456. float z = m_host.GetWorldPosition().Z;
  15457. return m_envModule.GetRegionMoonDir(z);
  15458. }
  15459. public LSL_Rotation llGetSunRotation()
  15460. {
  15461. m_host.AddScriptLPS(1);
  15462. if (m_envModule == null)
  15463. return Quaternion.Identity;
  15464. return m_envModule.GetSunRot(m_host.GetWorldPosition());
  15465. }
  15466. public LSL_Rotation llGetRegionSunRotation()
  15467. {
  15468. m_host.AddScriptLPS(1);
  15469. if (m_envModule == null)
  15470. return Quaternion.Identity;
  15471. float z = m_host.GetWorldPosition().Z;
  15472. return m_envModule.GetRegionSunRot(z);
  15473. }
  15474. public LSL_Rotation llGetMoonRotation()
  15475. {
  15476. m_host.AddScriptLPS(1);
  15477. if (m_envModule == null)
  15478. return Quaternion.Identity;
  15479. return m_envModule.GetMoonRot(m_host.GetWorldPosition());
  15480. }
  15481. public LSL_Rotation llGetRegionMoonRotation()
  15482. {
  15483. m_host.AddScriptLPS(1);
  15484. if (m_envModule == null)
  15485. return Quaternion.Identity;
  15486. float z = m_host.GetWorldPosition().Z;
  15487. return m_envModule.GetRegionMoonRot(z);
  15488. }
  15489. public LSL_List llJson2List(LSL_String json)
  15490. {
  15491. m_host.AddScriptLPS(1);
  15492. if (String.IsNullOrEmpty(json))
  15493. return new LSL_List();
  15494. if(json == "[]")
  15495. return new LSL_List();
  15496. if(json == "{}")
  15497. return new LSL_List();
  15498. char first = ((string)json)[0];
  15499. if(first != '[' && first !='{')
  15500. {
  15501. // we already have a single element
  15502. LSL_List l = new LSL_List();
  15503. l.Add(json);
  15504. return l;
  15505. }
  15506. LitJson.JsonData jsdata;
  15507. try
  15508. {
  15509. jsdata = LitJson.JsonMapper.ToObject(json);
  15510. }
  15511. catch (Exception e)
  15512. {
  15513. string m = e.Message; // debug point
  15514. return json;
  15515. }
  15516. try
  15517. {
  15518. return JsonParseTop(jsdata);
  15519. }
  15520. catch (Exception e)
  15521. {
  15522. string m = e.Message; // debug point
  15523. return (LSL_String)ScriptBaseClass.JSON_INVALID;
  15524. }
  15525. }
  15526. private LSL_List JsonParseTop(LitJson.JsonData elem)
  15527. {
  15528. LSL_List retl = new LSL_List();
  15529. if(elem == null)
  15530. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15531. LitJson.JsonType elemType = elem.GetJsonType();
  15532. switch (elemType)
  15533. {
  15534. case LitJson.JsonType.Int:
  15535. retl.Add(new LSL_Integer((int)elem));
  15536. return retl;
  15537. case LitJson.JsonType.Boolean:
  15538. retl.Add((LSL_String)((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE));
  15539. return retl;
  15540. case LitJson.JsonType.Double:
  15541. retl.Add(new LSL_Float((double)elem));
  15542. return retl;
  15543. case LitJson.JsonType.None:
  15544. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15545. return retl;
  15546. case LitJson.JsonType.String:
  15547. retl.Add(new LSL_String((string)elem));
  15548. return retl;
  15549. case LitJson.JsonType.Array:
  15550. foreach (LitJson.JsonData subelem in elem)
  15551. retl.Add(JsonParseTopNodes(subelem));
  15552. return retl;
  15553. case LitJson.JsonType.Object:
  15554. IDictionaryEnumerator e = ((IOrderedDictionary)elem).GetEnumerator();
  15555. while (e.MoveNext())
  15556. {
  15557. retl.Add(new LSL_String((string)e.Key));
  15558. retl.Add(JsonParseTopNodes((LitJson.JsonData)e.Value));
  15559. }
  15560. return retl;
  15561. default:
  15562. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15563. }
  15564. }
  15565. private object JsonParseTopNodes(LitJson.JsonData elem)
  15566. {
  15567. if(elem == null)
  15568. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15569. LitJson.JsonType elemType = elem.GetJsonType();
  15570. switch (elemType)
  15571. {
  15572. case LitJson.JsonType.Int:
  15573. return (new LSL_Integer((int)elem));
  15574. case LitJson.JsonType.Boolean:
  15575. return ((bool)elem ? (LSL_String)ScriptBaseClass.JSON_TRUE : (LSL_String)ScriptBaseClass.JSON_FALSE);
  15576. case LitJson.JsonType.Double:
  15577. return (new LSL_Float((double)elem));
  15578. case LitJson.JsonType.None:
  15579. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15580. case LitJson.JsonType.String:
  15581. return (new LSL_String((string)elem));
  15582. case LitJson.JsonType.Array:
  15583. case LitJson.JsonType.Object:
  15584. string s = LitJson.JsonMapper.ToJson(elem);
  15585. return (LSL_String)s;
  15586. default:
  15587. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15588. }
  15589. }
  15590. public LSL_String llList2Json(LSL_String type, LSL_List values)
  15591. {
  15592. try
  15593. {
  15594. StringBuilder sb = new StringBuilder();
  15595. if (type == ScriptBaseClass.JSON_ARRAY)
  15596. {
  15597. sb.Append("[");
  15598. int i= 0;
  15599. foreach (object o in values.Data)
  15600. {
  15601. sb.Append(ListToJson(o));
  15602. if((i++) < values.Data.Length - 1)
  15603. sb.Append(",");
  15604. }
  15605. sb.Append("]");
  15606. return (LSL_String)sb.ToString();;
  15607. }
  15608. else if (type == ScriptBaseClass.JSON_OBJECT)
  15609. {
  15610. sb.Append("{");
  15611. for (int i = 0; i < values.Data.Length; i += 2)
  15612. {
  15613. if (!(values.Data[i] is LSL_String))
  15614. return ScriptBaseClass.JSON_INVALID;
  15615. string key = ((LSL_String)values.Data[i]).m_string;
  15616. key = EscapeForJSON(key, true);
  15617. sb.Append(key);
  15618. sb.Append(":");
  15619. sb.Append(ListToJson(values.Data[i+1]));
  15620. if(i < values.Data.Length - 2)
  15621. sb.Append(",");
  15622. }
  15623. sb.Append("}");
  15624. return (LSL_String)sb.ToString();
  15625. }
  15626. return ScriptBaseClass.JSON_INVALID;
  15627. }
  15628. catch
  15629. {
  15630. return ScriptBaseClass.JSON_INVALID;
  15631. }
  15632. }
  15633. private string ListToJson(object o)
  15634. {
  15635. if (o is LSL_Float || o is double)
  15636. {
  15637. double float_val;
  15638. if (o is double)
  15639. float_val = ((double)o);
  15640. else
  15641. float_val = ((LSL_Float)o).value;
  15642. if(double.IsInfinity(float_val))
  15643. return "\"Inf\"";
  15644. if(double.IsNaN(float_val))
  15645. return "\"NaN\"";
  15646. return ((LSL_Float)float_val).ToString();
  15647. }
  15648. if (o is LSL_Integer || o is int)
  15649. {
  15650. int i;
  15651. if (o is int)
  15652. i = ((int)o);
  15653. else
  15654. i = ((LSL_Integer)o).value;
  15655. return i.ToString();
  15656. }
  15657. if (o is LSL_Rotation)
  15658. {
  15659. StringBuilder sb = new StringBuilder(128);
  15660. sb.Append("\"");
  15661. LSL_Rotation r = (LSL_Rotation)o;
  15662. sb.Append(r.ToString());
  15663. sb.Append("\"");
  15664. return sb.ToString();
  15665. }
  15666. if (o is LSL_Vector)
  15667. {
  15668. StringBuilder sb = new StringBuilder(128);
  15669. sb.Append("\"");
  15670. LSL_Vector v = (LSL_Vector)o;
  15671. sb.Append(v.ToString());
  15672. sb.Append("\"");
  15673. return sb.ToString();
  15674. }
  15675. if (o is LSL_String || o is string)
  15676. {
  15677. string str;
  15678. if (o is string)
  15679. str = ((string)o);
  15680. else
  15681. str = ((LSL_String)o).m_string;
  15682. if(str == ScriptBaseClass.JSON_TRUE || str == "true")
  15683. return "true";
  15684. if(str == ScriptBaseClass.JSON_FALSE ||str == "false")
  15685. return "false";
  15686. if(str == ScriptBaseClass.JSON_NULL || str == "null")
  15687. return "null";
  15688. str.Trim();
  15689. if(str.Length == 0)
  15690. return "\"\"";
  15691. if (str[0] == '{')
  15692. return str;
  15693. if (str[0] == '[')
  15694. return str;
  15695. return EscapeForJSON(str, true);
  15696. }
  15697. throw new IndexOutOfRangeException();
  15698. }
  15699. private string EscapeForJSON(string s, bool AddOuter)
  15700. {
  15701. int i;
  15702. char c;
  15703. String t;
  15704. int len = s.Length;
  15705. StringBuilder sb = new StringBuilder(len + 64);
  15706. if(AddOuter)
  15707. sb.Append("\"");
  15708. for (i = 0; i < len; i++)
  15709. {
  15710. c = s[i];
  15711. switch (c)
  15712. {
  15713. case '\\':
  15714. case '"':
  15715. case '/':
  15716. sb.Append('\\');
  15717. sb.Append(c);
  15718. break;
  15719. case '\b':
  15720. sb.Append("\\b");
  15721. break;
  15722. case '\t':
  15723. sb.Append("\\t");
  15724. break;
  15725. case '\n':
  15726. sb.Append("\\n");
  15727. break;
  15728. case '\f':
  15729. sb.Append("\\f");
  15730. break;
  15731. case '\r':
  15732. sb.Append("\\r");
  15733. break;
  15734. default:
  15735. if (c < ' ')
  15736. {
  15737. t = "000" + String.Format("{0:X}", c);
  15738. sb.Append("\\u" + t.Substring(t.Length - 4));
  15739. }
  15740. else
  15741. {
  15742. sb.Append(c);
  15743. }
  15744. break;
  15745. }
  15746. }
  15747. if(AddOuter)
  15748. sb.Append("\"");
  15749. return sb.ToString();
  15750. }
  15751. public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
  15752. {
  15753. bool noSpecifiers = specifiers.Length == 0;
  15754. LitJson.JsonData workData;
  15755. try
  15756. {
  15757. if(noSpecifiers)
  15758. specifiers.Add(new LSL_Integer(0));
  15759. if(!String.IsNullOrEmpty(json))
  15760. workData = LitJson.JsonMapper.ToObject(json);
  15761. else
  15762. {
  15763. workData = new LitJson.JsonData();
  15764. workData.SetJsonType(LitJson.JsonType.Array);
  15765. }
  15766. }
  15767. catch (Exception e)
  15768. {
  15769. string m = e.Message; // debug point
  15770. return ScriptBaseClass.JSON_INVALID;
  15771. }
  15772. try
  15773. {
  15774. LitJson.JsonData replace = JsonSetSpecific(workData, specifiers, 0, value);
  15775. if(replace != null)
  15776. workData = replace;
  15777. }
  15778. catch (Exception e)
  15779. {
  15780. string m = e.Message; // debug point
  15781. return ScriptBaseClass.JSON_INVALID;
  15782. }
  15783. try
  15784. {
  15785. string r = LitJson.JsonMapper.ToJson(workData);
  15786. if(noSpecifiers)
  15787. r = r.Substring(1,r.Length -2); // strip leading and trailing brakets
  15788. return r;
  15789. }
  15790. catch (Exception e)
  15791. {
  15792. string m = e.Message; // debug point
  15793. }
  15794. return ScriptBaseClass.JSON_INVALID;
  15795. }
  15796. private LitJson.JsonData JsonSetSpecific(LitJson.JsonData elem, LSL_List specifiers, int level, LSL_String val)
  15797. {
  15798. object spec = specifiers.Data[level];
  15799. if(spec is LSL_String)
  15800. spec = ((LSL_String)spec).m_string;
  15801. else if (spec is LSL_Integer)
  15802. spec = ((LSL_Integer)spec).value;
  15803. if(!(spec is string || spec is int))
  15804. throw new IndexOutOfRangeException();
  15805. int speclen = specifiers.Data.Length - 1;
  15806. bool hasvalue = false;
  15807. LitJson.JsonData value = null;
  15808. LitJson.JsonType elemType = elem.GetJsonType();
  15809. if (elemType == LitJson.JsonType.Array)
  15810. {
  15811. if (spec is int)
  15812. {
  15813. int v = (int)spec;
  15814. int c = elem.Count;
  15815. if(v < 0 || (v != 0 && v > c))
  15816. throw new IndexOutOfRangeException();
  15817. if(v == c)
  15818. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15819. else
  15820. {
  15821. hasvalue = true;
  15822. value = elem[v];
  15823. }
  15824. }
  15825. else if (spec is string)
  15826. {
  15827. if((string)spec == ScriptBaseClass.JSON_APPEND)
  15828. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15829. else if(elem.Count < 2)
  15830. {
  15831. // our initial guess of array was wrong
  15832. LitJson.JsonData newdata = new LitJson.JsonData();
  15833. newdata.SetJsonType(LitJson.JsonType.Object);
  15834. IOrderedDictionary no = newdata as IOrderedDictionary;
  15835. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15836. return newdata;
  15837. }
  15838. }
  15839. }
  15840. else if (elemType == LitJson.JsonType.Object)
  15841. {
  15842. if (spec is string)
  15843. {
  15844. IOrderedDictionary e = elem as IOrderedDictionary;
  15845. string key = (string)spec;
  15846. if(e.Contains(key))
  15847. {
  15848. hasvalue = true;
  15849. value = (LitJson.JsonData)e[key];
  15850. }
  15851. else
  15852. e.Add(key, JsonBuildRestOfSpec(specifiers, level + 1, val));
  15853. }
  15854. else if(spec is int && (int)spec == 0)
  15855. {
  15856. //we are replacing a object by a array
  15857. LitJson.JsonData newData = new LitJson.JsonData();
  15858. newData.SetJsonType(LitJson.JsonType.Array);
  15859. newData.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15860. return newData;
  15861. }
  15862. }
  15863. else
  15864. {
  15865. LitJson.JsonData newData = JsonBuildRestOfSpec(specifiers, level, val);
  15866. return newData;
  15867. }
  15868. if (hasvalue)
  15869. {
  15870. if (level < speclen)
  15871. {
  15872. LitJson.JsonData replace = JsonSetSpecific(value, specifiers, level + 1, val);
  15873. if(replace != null)
  15874. {
  15875. if(elemType == LitJson.JsonType.Array)
  15876. {
  15877. if(spec is int)
  15878. elem[(int)spec] = replace;
  15879. else if( spec is string)
  15880. {
  15881. LitJson.JsonData newdata = new LitJson.JsonData();
  15882. newdata.SetJsonType(LitJson.JsonType.Object);
  15883. IOrderedDictionary no = newdata as IOrderedDictionary;
  15884. no.Add((string)spec, replace);
  15885. return newdata;
  15886. }
  15887. }
  15888. else if(elemType == LitJson.JsonType.Object)
  15889. {
  15890. if(spec is string)
  15891. elem[(string)spec] = replace;
  15892. else if(spec is int && (int)spec == 0)
  15893. {
  15894. LitJson.JsonData newdata = new LitJson.JsonData();
  15895. newdata.SetJsonType(LitJson.JsonType.Array);
  15896. newdata.Add(replace);
  15897. return newdata;
  15898. }
  15899. }
  15900. }
  15901. return null;
  15902. }
  15903. else if(speclen == level)
  15904. {
  15905. if(val == ScriptBaseClass.JSON_DELETE)
  15906. {
  15907. if(elemType == LitJson.JsonType.Array)
  15908. {
  15909. if(spec is int)
  15910. {
  15911. IList el = elem as IList;
  15912. el.RemoveAt((int)spec);
  15913. }
  15914. }
  15915. else if(elemType == LitJson.JsonType.Object)
  15916. {
  15917. if(spec is string)
  15918. {
  15919. IOrderedDictionary eo = elem as IOrderedDictionary;
  15920. eo.Remove((string) spec);
  15921. }
  15922. }
  15923. return null;
  15924. }
  15925. LitJson.JsonData newval = null;
  15926. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15927. newval = null;
  15928. else if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15929. newval = new LitJson.JsonData(true);
  15930. else if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15931. newval = new LitJson.JsonData(false);
  15932. else if(float.TryParse(val, out float num))
  15933. {
  15934. // assuming we are at en.us already
  15935. if(num - (int)num == 0.0f && !val.Contains("."))
  15936. newval = new LitJson.JsonData((int)num);
  15937. else
  15938. {
  15939. num = (float)Math.Round(num,6);
  15940. newval = new LitJson.JsonData((double)num);
  15941. }
  15942. }
  15943. else
  15944. {
  15945. string str = val.m_string;
  15946. newval = new LitJson.JsonData(str);
  15947. }
  15948. if(elemType == LitJson.JsonType.Array)
  15949. {
  15950. if(spec is int)
  15951. elem[(int)spec] = newval;
  15952. else if( spec is string)
  15953. {
  15954. LitJson.JsonData newdata = new LitJson.JsonData();
  15955. newdata.SetJsonType(LitJson.JsonType.Object);
  15956. IOrderedDictionary no = newdata as IOrderedDictionary;
  15957. no.Add((string)spec,newval);
  15958. return newdata;
  15959. }
  15960. }
  15961. else if(elemType == LitJson.JsonType.Object)
  15962. {
  15963. if(spec is string)
  15964. elem[(string)spec] = newval;
  15965. else if(spec is int && (int)spec == 0)
  15966. {
  15967. LitJson.JsonData newdata = new LitJson.JsonData();
  15968. newdata.SetJsonType(LitJson.JsonType.Array);
  15969. newdata.Add(newval);
  15970. return newdata;
  15971. }
  15972. }
  15973. }
  15974. }
  15975. if(val == ScriptBaseClass.JSON_DELETE)
  15976. throw new IndexOutOfRangeException();
  15977. return null;
  15978. }
  15979. private LitJson.JsonData JsonBuildRestOfSpec(LSL_List specifiers, int level, LSL_String val)
  15980. {
  15981. object spec = level >= specifiers.Data.Length ? null : specifiers.Data[level];
  15982. // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
  15983. if (spec == null)
  15984. {
  15985. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15986. return null;
  15987. if(val == ScriptBaseClass.JSON_DELETE)
  15988. throw new IndexOutOfRangeException();
  15989. if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15990. return new LitJson.JsonData(true);
  15991. if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15992. return new LitJson.JsonData(false);
  15993. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15994. return null;
  15995. if(float.TryParse(val, out float num))
  15996. {
  15997. // assuming we are at en.us already
  15998. if(num - (int)num == 0.0f && !val.Contains("."))
  15999. return new LitJson.JsonData((int)num);
  16000. else
  16001. {
  16002. num = (float)Math.Round(num,6);
  16003. return new LitJson.JsonData(num);
  16004. }
  16005. }
  16006. else
  16007. {
  16008. string str = val.m_string;
  16009. return new LitJson.JsonData(str);
  16010. }
  16011. throw new IndexOutOfRangeException();
  16012. }
  16013. if(spec is LSL_String)
  16014. spec = ((LSL_String)spec).m_string;
  16015. else if (spec is LSL_Integer)
  16016. spec = ((LSL_Integer)spec).value;
  16017. if (spec is int ||
  16018. (spec is string && ((string)spec) == ScriptBaseClass.JSON_APPEND) )
  16019. {
  16020. if(spec is int && (int)spec != 0)
  16021. throw new IndexOutOfRangeException();
  16022. LitJson.JsonData newdata = new LitJson.JsonData();
  16023. newdata.SetJsonType(LitJson.JsonType.Array);
  16024. newdata.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  16025. return newdata;
  16026. }
  16027. else if (spec is string)
  16028. {
  16029. LitJson.JsonData newdata = new LitJson.JsonData();
  16030. newdata.SetJsonType(LitJson.JsonType.Object);
  16031. IOrderedDictionary no = newdata as IOrderedDictionary;
  16032. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  16033. return newdata;
  16034. }
  16035. throw new IndexOutOfRangeException();
  16036. }
  16037. private bool JsonFind(LitJson.JsonData elem, LSL_List specifiers, int level, out LitJson.JsonData value)
  16038. {
  16039. value = null;
  16040. if(elem == null)
  16041. return false;
  16042. object spec;
  16043. spec = specifiers.Data[level];
  16044. bool haveVal = false;
  16045. LitJson.JsonData next = null;
  16046. if (elem.GetJsonType() == LitJson.JsonType.Array)
  16047. {
  16048. if (spec is LSL_Integer)
  16049. {
  16050. int indx = (LSL_Integer)spec;
  16051. if(indx >= 0 && indx < elem.Count)
  16052. {
  16053. haveVal = true;
  16054. next = (LitJson.JsonData)elem[indx];
  16055. }
  16056. }
  16057. }
  16058. else if (elem.GetJsonType() == LitJson.JsonType.Object)
  16059. {
  16060. if (spec is LSL_String)
  16061. {
  16062. IOrderedDictionary e = elem as IOrderedDictionary;
  16063. string key = (LSL_String)spec;
  16064. if(e.Contains(key))
  16065. {
  16066. haveVal = true;
  16067. next = (LitJson.JsonData)e[key];
  16068. }
  16069. }
  16070. }
  16071. if (haveVal)
  16072. {
  16073. if(level == specifiers.Data.Length - 1)
  16074. {
  16075. value = next;
  16076. return true;
  16077. }
  16078. level++;
  16079. if(next == null)
  16080. return false;
  16081. LitJson.JsonType nextType = next.GetJsonType();
  16082. if(nextType != LitJson.JsonType.Object && nextType != LitJson.JsonType.Array)
  16083. return false;
  16084. return JsonFind(next, specifiers, level, out value);
  16085. }
  16086. return false;
  16087. }
  16088. public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
  16089. {
  16090. if(String.IsNullOrWhiteSpace(json))
  16091. return ScriptBaseClass.JSON_INVALID;
  16092. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  16093. return ScriptBaseClass.JSON_INVALID;
  16094. char first = ((string)json)[0];
  16095. if((first != '[' && first !='{'))
  16096. {
  16097. if(specifiers.Length > 0)
  16098. return ScriptBaseClass.JSON_INVALID;
  16099. json = "[" + json + "]"; // could handle single element case.. but easier like this
  16100. specifiers.Add((LSL_Integer)0);
  16101. }
  16102. LitJson.JsonData jsonData;
  16103. try
  16104. {
  16105. jsonData = LitJson.JsonMapper.ToObject(json);
  16106. }
  16107. catch (Exception e)
  16108. {
  16109. string m = e.Message; // debug point
  16110. return ScriptBaseClass.JSON_INVALID;
  16111. }
  16112. LitJson.JsonData elem = null;
  16113. if(specifiers.Length == 0)
  16114. elem = jsonData;
  16115. else
  16116. {
  16117. if(!JsonFind(jsonData, specifiers, 0, out elem))
  16118. return ScriptBaseClass.JSON_INVALID;
  16119. }
  16120. return JsonElementToString(elem);
  16121. }
  16122. private LSL_String JsonElementToString(LitJson.JsonData elem)
  16123. {
  16124. if(elem == null)
  16125. return ScriptBaseClass.JSON_NULL;
  16126. LitJson.JsonType elemType = elem.GetJsonType();
  16127. switch(elemType)
  16128. {
  16129. case LitJson.JsonType.Array:
  16130. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  16131. case LitJson.JsonType.Boolean:
  16132. return new LSL_String((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE);
  16133. case LitJson.JsonType.Double:
  16134. double d= (double)elem;
  16135. string sd = String.Format(Culture.FormatProvider, "{0:0.0#####}",d);
  16136. return new LSL_String(sd);
  16137. case LitJson.JsonType.Int:
  16138. int i = (int)elem;
  16139. return new LSL_String(i.ToString());
  16140. case LitJson.JsonType.Long:
  16141. long l = (long)elem;
  16142. return new LSL_String(l.ToString());
  16143. case LitJson.JsonType.Object:
  16144. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  16145. case LitJson.JsonType.String:
  16146. string s = (string)elem;
  16147. return new LSL_String(s);
  16148. case LitJson.JsonType.None:
  16149. return ScriptBaseClass.JSON_NULL;
  16150. default:
  16151. return ScriptBaseClass.JSON_INVALID;
  16152. }
  16153. }
  16154. public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
  16155. {
  16156. if(String.IsNullOrWhiteSpace(json))
  16157. return ScriptBaseClass.JSON_INVALID;
  16158. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  16159. return ScriptBaseClass.JSON_INVALID;
  16160. char first = ((string)json)[0];
  16161. if((first != '[' && first !='{'))
  16162. {
  16163. if(specifiers.Length > 0)
  16164. return ScriptBaseClass.JSON_INVALID;
  16165. json = "[" + json + "]"; // could handle single element case.. but easier like this
  16166. specifiers.Add((LSL_Integer)0);
  16167. }
  16168. LitJson.JsonData jsonData;
  16169. try
  16170. {
  16171. jsonData = LitJson.JsonMapper.ToObject(json);
  16172. }
  16173. catch (Exception e)
  16174. {
  16175. string m = e.Message; // debug point
  16176. return ScriptBaseClass.JSON_INVALID;
  16177. }
  16178. LitJson.JsonData elem = null;
  16179. if(specifiers.Length == 0)
  16180. elem = jsonData;
  16181. else
  16182. {
  16183. if(!JsonFind(jsonData, specifiers, 0, out elem))
  16184. return ScriptBaseClass.JSON_INVALID;
  16185. }
  16186. if(elem == null)
  16187. return ScriptBaseClass.JSON_NULL;
  16188. LitJson.JsonType elemType = elem.GetJsonType();
  16189. switch(elemType)
  16190. {
  16191. case LitJson.JsonType.Array:
  16192. return ScriptBaseClass.JSON_ARRAY;
  16193. case LitJson.JsonType.Boolean:
  16194. return (bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
  16195. case LitJson.JsonType.Double:
  16196. case LitJson.JsonType.Int:
  16197. case LitJson.JsonType.Long:
  16198. return ScriptBaseClass.JSON_NUMBER;
  16199. case LitJson.JsonType.Object:
  16200. return ScriptBaseClass.JSON_OBJECT;
  16201. case LitJson.JsonType.String:
  16202. string s = (string)elem;
  16203. if(s == ScriptBaseClass.JSON_NULL)
  16204. return ScriptBaseClass.JSON_NULL;
  16205. if(s == ScriptBaseClass.JSON_TRUE)
  16206. return ScriptBaseClass.JSON_TRUE;
  16207. if(s == ScriptBaseClass.JSON_FALSE)
  16208. return ScriptBaseClass.JSON_FALSE;
  16209. return ScriptBaseClass.JSON_STRING;
  16210. case LitJson.JsonType.None:
  16211. return ScriptBaseClass.JSON_NULL;
  16212. default:
  16213. return ScriptBaseClass.JSON_INVALID;
  16214. }
  16215. }
  16216. }
  16217. public class NotecardCache
  16218. {
  16219. private static ExpiringCacheOS<UUID, string[]> m_Notecards = new ExpiringCacheOS<UUID, string[]>(30000);
  16220. public static void Cache(UUID assetID, byte[] text)
  16221. {
  16222. if (m_Notecards.ContainsKey(assetID, 30000))
  16223. return;
  16224. m_Notecards.AddOrUpdate(assetID, SLUtil.ParseNotecardToArray(text), 30);
  16225. }
  16226. public static bool IsCached(UUID assetID)
  16227. {
  16228. return m_Notecards.ContainsKey(assetID, 30000);
  16229. }
  16230. public static int GetLines(UUID assetID)
  16231. {
  16232. if (m_Notecards.TryGetValue(assetID, 30000, out string[] text))
  16233. return text.Length;
  16234. return -1;
  16235. }
  16236. /// <summary>
  16237. /// Get a notecard line.
  16238. /// </summary>
  16239. /// <param name="assetID"></param>
  16240. /// <param name="lineNumber">Lines start at index 0</param>
  16241. /// <returns></returns>
  16242. public static string GetLine(UUID assetID, int lineNumber)
  16243. {
  16244. if (lineNumber >= 0 && m_Notecards.TryGetValue(assetID, 30000, out string[] text))
  16245. {
  16246. if (lineNumber >= text.Length)
  16247. return "\n\n\n";
  16248. return text[lineNumber];
  16249. }
  16250. return "";
  16251. }
  16252. /// <summary>
  16253. /// Get a notecard line.
  16254. /// </summary>
  16255. /// <param name="assetID"></param>
  16256. /// <param name="lineNumber">Lines start at index 0</param>
  16257. /// <param name="maxLength">
  16258. /// Maximum length of the returned line.
  16259. /// </param>
  16260. /// <returns>
  16261. /// If the line length is longer than <paramref name="maxLength"/>,
  16262. /// the return string will be truncated.
  16263. /// </returns>
  16264. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  16265. {
  16266. string line = GetLine(assetID, lineNumber);
  16267. if (line.Length > maxLength)
  16268. return line.Substring(0, maxLength);
  16269. return line;
  16270. }
  16271. }
  16272. }