LSL_Api.cs 736 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662
  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 Dictionary<string, string> MovementAnimationsForLSL =
  238. new Dictionary<string, string> {
  239. {"CROUCH", "Crouching"},
  240. {"CROUCHWALK", "CrouchWalking"},
  241. {"FALLDOWN", "Falling Down"},
  242. {"FLY", "Flying"},
  243. {"FLYSLOW", "FlyingSlow"},
  244. {"HOVER", "Hovering"},
  245. {"HOVER_UP", "Hovering Up"},
  246. {"HOVER_DOWN", "Hovering Down"},
  247. {"JUMP", "Jumping"},
  248. {"LAND", "Landing"},
  249. {"PREJUMP", "PreJumping"},
  250. {"RUN", "Running"},
  251. {"SIT","Sitting"},
  252. {"SITGROUND","Sitting on Ground"},
  253. {"STAND", "Standing"},
  254. {"STANDUP", "Standing Up"},
  255. {"STRIDE","Striding"},
  256. {"SOFT_LAND", "Soft Landing"},
  257. {"TURNLEFT", "Turning Left"},
  258. {"TURNRIGHT", "Turning Right"},
  259. {"WALK", "Walking"}
  260. };
  261. //An array of HTTP/1.1 headers that are not allowed to be used
  262. //as custom headers by llHTTPRequest.
  263. private HashSet<string> HttpStandardHeaders = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
  264. {
  265. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  266. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  267. "Connection", "Content-Encoding", "Content-Language",
  268. "Content-Length", "Content-Location", "Content-MD5",
  269. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  270. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  271. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  272. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  273. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  274. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  275. "Vary", "Via", "Warning", "WWW-Authenticate"
  276. };
  277. public void Initialize(
  278. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  279. {
  280. m_lastSayShoutCheck = DateTime.UtcNow;
  281. m_ScriptEngine = scriptEngine;
  282. m_host = host;
  283. m_item = item;
  284. m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
  285. LoadConfig();
  286. m_TransferModule =
  287. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  288. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  289. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  290. m_materialsModule = m_ScriptEngine.World.RequestModuleInterface<IMaterialsModule>();
  291. m_emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  292. m_envModule = m_ScriptEngine.World.RequestModuleInterface< IEnvironmentModule>();
  293. m_AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  294. m_userAccountService = World.UserAccountService;
  295. if(World.RegionInfo != null)
  296. RegionScopeID = World.RegionInfo.ScopeID;
  297. }
  298. /// <summary>
  299. /// Load configuration items that affect script, object and run-time behavior. */
  300. /// </summary>
  301. private void LoadConfig()
  302. {
  303. LlRequestAgentDataCacheTimeoutMs = 20000;
  304. IConfig seConfig = m_ScriptEngine.Config;
  305. if (seConfig != null)
  306. {
  307. m_ScriptDelayFactor =
  308. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  309. m_ScriptDistanceFactor =
  310. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  311. m_MinTimerInterval =
  312. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  313. m_automaticLinkPermission =
  314. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  315. m_notecardLineReadCharsMax =
  316. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  317. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  318. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  319. // it by this factor. May be zero to turn off recoil all together.
  320. m_recoilScaleFactor = seConfig.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  321. m_AllowGodFunctions = seConfig.GetBoolean("AllowGodFunctions", false);
  322. }
  323. if (m_notecardLineReadCharsMax > 65535)
  324. m_notecardLineReadCharsMax = 65535;
  325. // load limits for particular subsystems.
  326. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  327. if (seConfigSource != null)
  328. {
  329. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  330. if (lslConfig != null)
  331. {
  332. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  333. m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection);
  334. m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox);
  335. m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox);
  336. m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0);
  337. m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0);
  338. m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0);
  339. m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0);
  340. m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0);
  341. m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1);
  342. m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0);
  343. m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1);
  344. m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0);
  345. m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0);
  346. m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0);
  347. m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0);
  348. m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0);
  349. m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1);
  350. m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0);
  351. m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1);
  352. m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0);
  353. m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0);
  354. m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0);
  355. m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0);
  356. m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0);
  357. m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1);
  358. m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0);
  359. m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1);
  360. m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX);
  361. m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY);
  362. m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ);
  363. m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay);
  364. m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay);
  365. m_primLodInCastRay = (DetailLevel)lslConfig.GetInt("PrimDetailLevelInLlCastRay", (int)m_primLodInCastRay);
  366. m_sculptLodInCastRay = (DetailLevel)lslConfig.GetInt("SculptDetailLevelInLlCastRay", (int)m_sculptLodInCastRay);
  367. m_meshLodInCastRay = (DetailLevel)lslConfig.GetInt("MeshDetailLevelInLlCastRay", (int)m_meshLodInCastRay);
  368. m_avatarLodInCastRay = (DetailLevel)lslConfig.GetInt("AvatarDetailLevelInLlCastRay", (int)m_avatarLodInCastRay);
  369. m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay);
  370. m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay);
  371. m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay);
  372. m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay);
  373. m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay);
  374. m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay);
  375. m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay);
  376. m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay);
  377. m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay);
  378. m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay);
  379. m_useMeshCacheInCastRay = lslConfig.GetBoolean("UseMeshCacheInLlCastRay", m_useMeshCacheInCastRay);
  380. }
  381. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  382. if (smtpConfig != null)
  383. {
  384. // there's an smtp config, so load in the snooze time.
  385. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  386. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  387. }
  388. }
  389. m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000;
  390. }
  391. public override Object InitializeLifetimeService()
  392. {
  393. ILease lease = (ILease)base.InitializeLifetimeService();
  394. if (lease.CurrentState == LeaseState.Initial)
  395. {
  396. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  397. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  398. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  399. }
  400. return lease;
  401. }
  402. protected SceneObjectPart MonitoringObject()
  403. {
  404. UUID m = m_host.ParentGroup.MonitoringObject;
  405. if (m == UUID.Zero)
  406. return null;
  407. SceneObjectPart p = m_ScriptEngine.World.GetSceneObjectPart(m);
  408. if (p == null)
  409. m_host.ParentGroup.MonitoringObject = UUID.Zero;
  410. return p;
  411. }
  412. protected virtual void ScriptSleep(int delay)
  413. {
  414. delay = (int)(delay * m_ScriptDelayFactor);
  415. if (delay < 10)
  416. return;
  417. Sleep(delay);
  418. }
  419. protected virtual void Sleep(int delay)
  420. {
  421. if (m_item == null) // Some unit tests don't set this
  422. Thread.Sleep(delay);
  423. else
  424. m_ScriptEngine.SleepScript(m_item.ItemID, delay);
  425. }
  426. /// <summary>
  427. /// Check for co-operative termination.
  428. /// </summary>
  429. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  430. public Scene World
  431. {
  432. get { return m_ScriptEngine.World; }
  433. }
  434. [DebuggerNonUserCode]
  435. public void state(string newState)
  436. {
  437. m_ScriptEngine.SetState(m_item.ItemID, newState);
  438. }
  439. /// <summary>
  440. /// Reset the named script. The script must be present
  441. /// in the same prim.
  442. /// </summary>
  443. [DebuggerNonUserCode]
  444. public void llResetScript()
  445. {
  446. m_host.AddScriptLPS(1);
  447. // We need to tell the URL module, if we hav one, to release
  448. // the allocated URLs
  449. if (m_UrlModule != null)
  450. m_UrlModule.ScriptRemoved(m_item.ItemID);
  451. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  452. }
  453. public void llResetOtherScript(string name)
  454. {
  455. UUID item;
  456. if ((item = GetScriptByName(name)) == UUID.Zero)
  457. {
  458. m_host.AddScriptLPS(1);
  459. Error("llResetOtherScript", "Can't find script '" + name + "'");
  460. return;
  461. }
  462. if(item == m_item.ItemID)
  463. llResetScript();
  464. else
  465. {
  466. m_host.AddScriptLPS(1);
  467. m_ScriptEngine.ResetScript(item);
  468. }
  469. }
  470. public LSL_Integer llGetScriptState(string name)
  471. {
  472. UUID item;
  473. m_host.AddScriptLPS(1);
  474. if ((item = GetScriptByName(name)) != UUID.Zero)
  475. {
  476. return m_ScriptEngine.GetScriptState(item) ?1:0;
  477. }
  478. Error("llGetScriptState", "Can't find script '" + name + "'");
  479. // If we didn't find it, then it's safe to
  480. // assume it is not running.
  481. return 0;
  482. }
  483. public void llSetScriptState(string name, int run)
  484. {
  485. UUID item;
  486. m_host.AddScriptLPS(1);
  487. // These functions are supposed to be robust,
  488. // so get the state one step at a time.
  489. if ((item = GetScriptByName(name)) != UUID.Zero)
  490. {
  491. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true, item == m_item.ItemID);
  492. }
  493. else
  494. {
  495. Error("llSetScriptState", "Can't find script '" + name + "'");
  496. }
  497. }
  498. public List<ScenePresence> GetLinkAvatars(int linkType)
  499. {
  500. List<ScenePresence> ret = new List<ScenePresence>();
  501. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  502. return ret;
  503. // List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
  504. // this needs check
  505. List<ScenePresence> avs = m_host.ParentGroup.GetSittingAvatars();
  506. switch (linkType)
  507. {
  508. case ScriptBaseClass.LINK_SET:
  509. return avs;
  510. case ScriptBaseClass.LINK_ROOT:
  511. return ret;
  512. case ScriptBaseClass.LINK_ALL_OTHERS:
  513. return avs;
  514. case ScriptBaseClass.LINK_ALL_CHILDREN:
  515. return avs;
  516. case ScriptBaseClass.LINK_THIS:
  517. return ret;
  518. default:
  519. if (linkType < 0)
  520. return ret;
  521. int partCount = m_host.ParentGroup.GetPartCount();
  522. if (linkType <= partCount)
  523. {
  524. return ret;
  525. }
  526. else
  527. {
  528. linkType = linkType - partCount;
  529. if (linkType > avs.Count)
  530. {
  531. return ret;
  532. }
  533. else
  534. {
  535. ret.Add(avs[linkType-1]);
  536. return ret;
  537. }
  538. }
  539. }
  540. }
  541. /// <summary>
  542. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  543. /// </summary>
  544. /// <remarks>
  545. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  546. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  547. /// The ScenePresences receive linknums in the order in which they sat.
  548. /// </remarks>
  549. /// <returns>
  550. /// The link entity. null if not found.
  551. /// </returns>
  552. /// <param name='part'></param>
  553. /// <param name='linknum'>
  554. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  555. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  556. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  557. /// positive integer is given in this case then null is returned.
  558. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  559. /// of entities, then the entity which corresponds to that linknum is returned.
  560. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  561. /// null is returned.
  562. /// </param>
  563. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  564. {
  565. if (linknum < 0)
  566. {
  567. if (linknum == ScriptBaseClass.LINK_THIS)
  568. return part;
  569. else
  570. return null;
  571. }
  572. int actualPrimCount = part.ParentGroup.PrimCount;
  573. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  574. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  575. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  576. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  577. if (linknum == 0)
  578. {
  579. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  580. return part;
  581. return null;
  582. }
  583. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  584. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  585. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  586. {
  587. if (sittingAvatars.Count > 0)
  588. return part.ParentGroup.RootPart;
  589. else
  590. return null;
  591. }
  592. else if (linknum <= adjustedPrimCount)
  593. {
  594. if (linknum <= actualPrimCount)
  595. {
  596. return part.ParentGroup.GetLinkNumPart(linknum);
  597. }
  598. else
  599. {
  600. return sittingAvatars[linknum - actualPrimCount - 1];
  601. }
  602. }
  603. else
  604. {
  605. return null;
  606. }
  607. }
  608. public List<SceneObjectPart> GetLinkParts(int linkType)
  609. {
  610. return GetLinkParts(m_host, linkType);
  611. }
  612. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  613. {
  614. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  615. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  616. return ret;
  617. switch (linkType)
  618. {
  619. case ScriptBaseClass.LINK_SET:
  620. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  621. case ScriptBaseClass.LINK_ROOT:
  622. ret.Add(part.ParentGroup.RootPart);
  623. return ret;
  624. case ScriptBaseClass.LINK_ALL_OTHERS:
  625. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  626. if (ret.Contains(part))
  627. ret.Remove(part);
  628. return ret;
  629. case ScriptBaseClass.LINK_ALL_CHILDREN:
  630. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  631. if (ret.Contains(part.ParentGroup.RootPart))
  632. ret.Remove(part.ParentGroup.RootPart);
  633. return ret;
  634. case ScriptBaseClass.LINK_THIS:
  635. ret.Add(part);
  636. return ret;
  637. default:
  638. if (linkType < 0)
  639. return ret;
  640. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  641. if (target == null)
  642. return ret;
  643. ret.Add(target);
  644. return ret;
  645. }
  646. }
  647. public List<ISceneEntity> GetLinkEntities(int linkType)
  648. {
  649. return GetLinkEntities(m_host, linkType);
  650. }
  651. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  652. {
  653. List<ISceneEntity> ret;
  654. switch (linkType)
  655. {
  656. case ScriptBaseClass.LINK_SET:
  657. return new List<ISceneEntity>(part.ParentGroup.Parts);
  658. case ScriptBaseClass.LINK_ROOT:
  659. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  660. case ScriptBaseClass.LINK_ALL_OTHERS:
  661. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  662. if (ret.Contains(part))
  663. ret.Remove(part);
  664. return ret;
  665. case ScriptBaseClass.LINK_ALL_CHILDREN:
  666. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  667. if (ret.Contains(part.ParentGroup.RootPart))
  668. ret.Remove(part.ParentGroup.RootPart);
  669. List<ScenePresence> avs = part.ParentGroup.GetSittingAvatars();
  670. if(avs!= null && avs.Count > 0)
  671. ret.AddRange(avs);
  672. return ret;
  673. case ScriptBaseClass.LINK_THIS:
  674. return new List<ISceneEntity>() { part };
  675. default:
  676. if (linkType < 0)
  677. return new List<ISceneEntity>();
  678. ISceneEntity target = GetLinkEntity(part, linkType);
  679. if (target == null)
  680. return new List<ISceneEntity>();
  681. return new List<ISceneEntity>() { target };
  682. }
  683. }
  684. //These are the implementations of the various ll-functions used by the LSL scripts.
  685. public LSL_Float llSin(double f)
  686. {
  687. m_host.AddScriptLPS(1);
  688. return Math.Sin(f);
  689. }
  690. public LSL_Float llCos(double f)
  691. {
  692. m_host.AddScriptLPS(1);
  693. return Math.Cos(f);
  694. }
  695. public LSL_Float llTan(double f)
  696. {
  697. m_host.AddScriptLPS(1);
  698. return Math.Tan(f);
  699. }
  700. public LSL_Float llAtan2(LSL_Float x, LSL_Float y)
  701. {
  702. m_host.AddScriptLPS(1);
  703. return Math.Atan2(x, y);
  704. }
  705. public LSL_Float llSqrt(double f)
  706. {
  707. m_host.AddScriptLPS(1);
  708. return Math.Sqrt(f);
  709. }
  710. public LSL_Float llPow(double fbase, double fexponent)
  711. {
  712. m_host.AddScriptLPS(1);
  713. return (double)Math.Pow(fbase, fexponent);
  714. }
  715. public LSL_Integer llAbs(LSL_Integer i)
  716. {
  717. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  718. m_host.AddScriptLPS(1);
  719. if (i == Int32.MinValue)
  720. return i;
  721. else
  722. return (int)Math.Abs(i);
  723. }
  724. public LSL_Float llFabs(double f)
  725. {
  726. m_host.AddScriptLPS(1);
  727. return (double)Math.Abs(f);
  728. }
  729. public LSL_Float llFrand(double mag)
  730. {
  731. m_host.AddScriptLPS(1);
  732. lock (Util.RandomClass)
  733. {
  734. return Util.RandomClass.NextDouble() * mag;
  735. }
  736. }
  737. public LSL_Integer llFloor(double f)
  738. {
  739. m_host.AddScriptLPS(1);
  740. return (int)Math.Floor(f);
  741. }
  742. public LSL_Integer llCeil(double f)
  743. {
  744. m_host.AddScriptLPS(1);
  745. return (int)Math.Ceiling(f);
  746. }
  747. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  748. public LSL_Integer llRound(double f)
  749. {
  750. m_host.AddScriptLPS(1);
  751. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  752. }
  753. //This next group are vector operations involving squaring and square root. ckrinke
  754. public LSL_Float llVecMag(LSL_Vector v)
  755. {
  756. m_host.AddScriptLPS(1);
  757. return LSL_Vector.Mag(v);
  758. }
  759. public LSL_Vector llVecNorm(LSL_Vector v)
  760. {
  761. m_host.AddScriptLPS(1);
  762. return LSL_Vector.Norm(v);
  763. }
  764. private double VecDist(LSL_Vector a, LSL_Vector b)
  765. {
  766. double dx = a.x - b.x;
  767. double dy = a.y - b.y;
  768. double dz = a.z - b.z;
  769. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  770. }
  771. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  772. {
  773. m_host.AddScriptLPS(1);
  774. return VecDist(a, b);
  775. }
  776. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  777. // Utility function for llRot2Euler
  778. public LSL_Vector llRot2Euler(LSL_Rotation q1)
  779. {
  780. m_host.AddScriptLPS(1);
  781. LSL_Vector eul = new LSL_Vector();
  782. double sqw = q1.s*q1.s;
  783. double sqx = q1.x*q1.x;
  784. double sqy = q1.z*q1.z;
  785. double sqz = q1.y*q1.y;
  786. double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  787. double test = q1.x*q1.z + q1.y*q1.s;
  788. if (test > 0.4999*unit) { // singularity at north pole
  789. eul.z = 2 * Math.Atan2(q1.x,q1.s);
  790. eul.y = Math.PI/2;
  791. eul.x = 0;
  792. return eul;
  793. }
  794. if (test < -0.4999*unit) { // singularity at south pole
  795. eul.z = -2 * Math.Atan2(q1.x,q1.s);
  796. eul.y = -Math.PI/2;
  797. eul.x = 0;
  798. return eul;
  799. }
  800. eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
  801. eul.y = Math.Asin(2*test/unit);
  802. eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
  803. return eul;
  804. }
  805. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  806. {
  807. m_host.AddScriptLPS(1);
  808. double x,y,z,s;
  809. v.x *= 0.5;
  810. v.y *= 0.5;
  811. v.z *= 0.5;
  812. double c1 = Math.Cos(v.x);
  813. double c2 = Math.Cos(v.y);
  814. double c1c2 = c1 * c2;
  815. double s1 = Math.Sin(v.x);
  816. double s2 = Math.Sin(v.y);
  817. double s1s2 = s1 * s2;
  818. double c1s2 = c1 * s2;
  819. double s1c2 = s1 * c2;
  820. double c3 = Math.Cos(v.z);
  821. double s3 = Math.Sin(v.z);
  822. x = s1c2 * c3 + c1s2 * s3;
  823. y = c1s2 * c3 - s1c2 * s3;
  824. z = s1s2 * c3 + c1c2 * s3;
  825. s = c1c2 * c3 - s1s2 * s3;
  826. return new LSL_Rotation(x, y, z, s);
  827. }
  828. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  829. {
  830. m_host.AddScriptLPS(1);
  831. double s;
  832. double tr = fwd.x + left.y + up.z + 1.0;
  833. if (tr >= 1.0)
  834. {
  835. s = 0.5 / Math.Sqrt(tr);
  836. return new LSL_Rotation(
  837. (left.z - up.y) * s,
  838. (up.x - fwd.z) * s,
  839. (fwd.y - left.x) * s,
  840. 0.25 / s);
  841. }
  842. else
  843. {
  844. double max = (left.y > up.z) ? left.y : up.z;
  845. if (max < fwd.x)
  846. {
  847. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  848. double x = s * 0.5;
  849. s = 0.5 / s;
  850. return new LSL_Rotation(
  851. x,
  852. (fwd.y + left.x) * s,
  853. (up.x + fwd.z) * s,
  854. (left.z - up.y) * s);
  855. }
  856. else if (max == left.y)
  857. {
  858. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  859. double y = s * 0.5;
  860. s = 0.5 / s;
  861. return new LSL_Rotation(
  862. (fwd.y + left.x) * s,
  863. y,
  864. (left.z + up.y) * s,
  865. (up.x - fwd.z) * s);
  866. }
  867. else
  868. {
  869. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  870. double z = s * 0.5;
  871. s = 0.5 / s;
  872. return new LSL_Rotation(
  873. (up.x + fwd.z) * s,
  874. (left.z + up.y) * s,
  875. z,
  876. (fwd.y - left.x) * s);
  877. }
  878. }
  879. }
  880. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  881. {
  882. m_host.AddScriptLPS(1);
  883. double x, y, z, m;
  884. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  885. // m is always greater than zero
  886. // if m is not equal to 1 then Rotation needs to be normalized
  887. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  888. {
  889. m = 1.0 / Math.Sqrt(m);
  890. r.x *= m;
  891. r.y *= m;
  892. r.z *= m;
  893. r.s *= m;
  894. }
  895. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  896. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  897. y = 2 * (r.x * r.y + r.z * r.s);
  898. z = 2 * (r.x * r.z - r.y * r.s);
  899. return (new LSL_Vector(x, y, z));
  900. }
  901. public LSL_Vector llRot2Left(LSL_Rotation r)
  902. {
  903. m_host.AddScriptLPS(1);
  904. double x, y, z, m;
  905. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  906. // m is always greater than zero
  907. // if m is not equal to 1 then Rotation needs to be normalized
  908. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  909. {
  910. m = 1.0 / Math.Sqrt(m);
  911. r.x *= m;
  912. r.y *= m;
  913. r.z *= m;
  914. r.s *= m;
  915. }
  916. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  917. x = 2 * (r.x * r.y - r.z * r.s);
  918. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  919. z = 2 * (r.x * r.s + r.y * r.z);
  920. return (new LSL_Vector(x, y, z));
  921. }
  922. public LSL_Vector llRot2Up(LSL_Rotation r)
  923. {
  924. m_host.AddScriptLPS(1);
  925. double x, y, z, m;
  926. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  927. // m is always greater than zero
  928. // if m is not equal to 1 then Rotation needs to be normalized
  929. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  930. {
  931. m = 1.0 / Math.Sqrt(m);
  932. r.x *= m;
  933. r.y *= m;
  934. r.z *= m;
  935. r.s *= m;
  936. }
  937. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  938. x = 2 * (r.x * r.z + r.y * r.s);
  939. y = 2 * (-r.x * r.s + r.y * r.z);
  940. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  941. return (new LSL_Vector(x, y, z));
  942. }
  943. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  944. {
  945. //A and B should both be normalized
  946. m_host.AddScriptLPS(1);
  947. // This method mimics the 180 errors found in SL
  948. // See www.euclideanspace.com... angleBetween
  949. // Eliminate zero length
  950. LSL_Float vec_a_mag = LSL_Vector.MagSquare(a);
  951. LSL_Float vec_b_mag = LSL_Vector.MagSquare(b);
  952. if (vec_a_mag < 1e-12 ||
  953. vec_b_mag < 1e-12)
  954. {
  955. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  956. }
  957. // Normalize
  958. a = llVecNorm(a);
  959. b = llVecNorm(b);
  960. // Calculate axis and rotation angle
  961. LSL_Vector axis = a % b;
  962. LSL_Float cos_theta = a * b;
  963. // Check if parallel
  964. if (cos_theta > 0.99999)
  965. {
  966. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  967. }
  968. // Check if anti-parallel
  969. else if (cos_theta < -0.99999)
  970. {
  971. LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (a.x / (a * a) * a);
  972. if (LSL_Vector.MagSquare(orthog_axis) < 1e-12)
  973. orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
  974. return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
  975. }
  976. else // other rotation
  977. {
  978. LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
  979. axis = llVecNorm(axis);
  980. double x, y, z, s, t;
  981. s = Math.Cos(theta);
  982. t = Math.Sin(theta);
  983. x = axis.x * t;
  984. y = axis.y * t;
  985. z = axis.z * t;
  986. return new LSL_Rotation(x,y,z,s);
  987. }
  988. }
  989. public void llWhisper(int channelID, string text)
  990. {
  991. m_host.AddScriptLPS(1);
  992. if (text.Length > 1023)
  993. text = text.Substring(0, 1023);
  994. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  995. World.SimChat(binText,
  996. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  997. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  998. if (wComm != null)
  999. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1000. }
  1001. private void CheckSayShoutTime()
  1002. {
  1003. DateTime now = DateTime.UtcNow;
  1004. if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
  1005. {
  1006. m_lastSayShoutCheck = now;
  1007. m_SayShoutCount = 0;
  1008. }
  1009. else
  1010. m_SayShoutCount++;
  1011. }
  1012. public void llSay(int channelID, string text)
  1013. {
  1014. m_host.AddScriptLPS(1);
  1015. if (channelID == 0)
  1016. // m_SayShoutCount++;
  1017. CheckSayShoutTime();
  1018. if (m_SayShoutCount >= 11)
  1019. ScriptSleep(2000);
  1020. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  1021. {
  1022. Console.WriteLine(text);
  1023. }
  1024. else
  1025. {
  1026. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1027. World.SimChat(binText,
  1028. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1029. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1030. if (wComm != null)
  1031. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1032. }
  1033. }
  1034. public void llShout(int channelID, string text)
  1035. {
  1036. m_host.AddScriptLPS(1);
  1037. if (channelID == 0)
  1038. // m_SayShoutCount++;
  1039. CheckSayShoutTime();
  1040. if (m_SayShoutCount >= 11)
  1041. ScriptSleep(2000);
  1042. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1043. World.SimChat(binText,
  1044. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1045. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1046. if (wComm != null)
  1047. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1048. }
  1049. public void llRegionSay(int channelID, string text)
  1050. {
  1051. if (channelID == 0)
  1052. {
  1053. Error("llRegionSay", "Cannot use on channel 0");
  1054. return;
  1055. }
  1056. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1057. m_host.AddScriptLPS(1);
  1058. // debug channel is also sent to avatars
  1059. if (channelID == ScriptBaseClass.DEBUG_CHANNEL)
  1060. {
  1061. World.SimChat(binText,
  1062. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1063. }
  1064. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1065. if (wComm != null)
  1066. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1067. }
  1068. public void llRegionSayTo(string target, int channel, string msg)
  1069. {
  1070. if (msg.Length > 1023)
  1071. msg = msg.Substring(0, 1023);
  1072. m_host.AddScriptLPS(1);
  1073. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  1074. return;
  1075. UUID.TryParse(target, out UUID TargetID);
  1076. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1077. if (wComm != null)
  1078. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  1079. }
  1080. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  1081. {
  1082. m_host.AddScriptLPS(1);
  1083. UUID.TryParse(ID, out UUID keyID);
  1084. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1085. if (wComm != null)
  1086. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  1087. else
  1088. return -1;
  1089. }
  1090. public void llListenControl(int number, int active)
  1091. {
  1092. m_host.AddScriptLPS(1);
  1093. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1094. if (wComm != null)
  1095. wComm.ListenControl(m_item.ItemID, number, active);
  1096. }
  1097. public void llListenRemove(int number)
  1098. {
  1099. m_host.AddScriptLPS(1);
  1100. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1101. if (wComm != null)
  1102. wComm.ListenRemove(m_item.ItemID, number);
  1103. }
  1104. public void llSensor(string name, string id, int type, double range, double arc)
  1105. {
  1106. m_host.AddScriptLPS(1);
  1107. UUID keyID = UUID.Zero;
  1108. UUID.TryParse(id, out keyID);
  1109. m_AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  1110. }
  1111. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  1112. {
  1113. m_host.AddScriptLPS(1);
  1114. UUID keyID = UUID.Zero;
  1115. UUID.TryParse(id, out keyID);
  1116. m_AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  1117. }
  1118. public void llSensorRemove()
  1119. {
  1120. m_host.AddScriptLPS(1);
  1121. m_AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  1122. }
  1123. public string resolveName(UUID objecUUID)
  1124. {
  1125. // try avatar username surname
  1126. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, objecUUID);
  1127. if (account != null)
  1128. {
  1129. string avatarname = account.Name;
  1130. return avatarname;
  1131. }
  1132. // try an scene object
  1133. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  1134. if (SOP != null)
  1135. {
  1136. string objectname = SOP.Name;
  1137. return objectname;
  1138. }
  1139. World.Entities.TryGetValue(objecUUID, out EntityBase SensedObject);
  1140. if (SensedObject == null)
  1141. {
  1142. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  1143. if (groups != null)
  1144. {
  1145. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  1146. if (gr != null)
  1147. return gr.GroupName;
  1148. }
  1149. return String.Empty;
  1150. }
  1151. return SensedObject.Name;
  1152. }
  1153. public LSL_String llDetectedName(int number)
  1154. {
  1155. m_host.AddScriptLPS(1);
  1156. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1157. if (detectedParams == null)
  1158. return String.Empty;
  1159. return detectedParams.Name;
  1160. }
  1161. public LSL_Key llDetectedKey(int number)
  1162. {
  1163. m_host.AddScriptLPS(1);
  1164. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1165. if (detectedParams == null)
  1166. return String.Empty;
  1167. return detectedParams.Key.ToString();
  1168. }
  1169. public LSL_Key llDetectedOwner(int number)
  1170. {
  1171. m_host.AddScriptLPS(1);
  1172. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1173. if (detectedParams == null)
  1174. return String.Empty;
  1175. return detectedParams.Owner.ToString();
  1176. }
  1177. public LSL_Integer llDetectedType(int number)
  1178. {
  1179. m_host.AddScriptLPS(1);
  1180. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1181. if (detectedParams == null)
  1182. return 0;
  1183. return new LSL_Integer(detectedParams.Type);
  1184. }
  1185. public LSL_Vector llDetectedPos(int number)
  1186. {
  1187. m_host.AddScriptLPS(1);
  1188. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1189. if (detectedParams == null)
  1190. return new LSL_Vector();
  1191. return detectedParams.Position;
  1192. }
  1193. public LSL_Vector llDetectedVel(int number)
  1194. {
  1195. m_host.AddScriptLPS(1);
  1196. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1197. if (detectedParams == null)
  1198. return new LSL_Vector();
  1199. return detectedParams.Velocity;
  1200. }
  1201. public LSL_Vector llDetectedGrab(int number)
  1202. {
  1203. m_host.AddScriptLPS(1);
  1204. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1205. if (parms == null)
  1206. return new LSL_Vector(0, 0, 0);
  1207. return parms.OffsetPos;
  1208. }
  1209. public LSL_Rotation llDetectedRot(int number)
  1210. {
  1211. m_host.AddScriptLPS(1);
  1212. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1213. if (detectedParams == null)
  1214. return new LSL_Rotation();
  1215. return detectedParams.Rotation;
  1216. }
  1217. public LSL_Integer llDetectedGroup(int number)
  1218. {
  1219. m_host.AddScriptLPS(1);
  1220. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1221. if (detectedParams == null)
  1222. return new LSL_Integer(0);
  1223. if (m_host.GroupID == detectedParams.Group)
  1224. return new LSL_Integer(1);
  1225. return new LSL_Integer(0);
  1226. }
  1227. public LSL_Integer llDetectedLinkNumber(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_Integer(0);
  1233. return new LSL_Integer(parms.LinkNum);
  1234. }
  1235. /// <summary>
  1236. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1237. /// </summary>
  1238. public LSL_Vector llDetectedTouchBinormal(int index)
  1239. {
  1240. m_host.AddScriptLPS(1);
  1241. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1242. if (detectedParams == null)
  1243. return new LSL_Vector();
  1244. return detectedParams.TouchBinormal;
  1245. }
  1246. /// <summary>
  1247. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1248. /// </summary>
  1249. public LSL_Integer llDetectedTouchFace(int index)
  1250. {
  1251. m_host.AddScriptLPS(1);
  1252. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1253. if (detectedParams == null)
  1254. return new LSL_Integer(-1);
  1255. return new LSL_Integer(detectedParams.TouchFace);
  1256. }
  1257. /// <summary>
  1258. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1259. /// </summary>
  1260. public LSL_Vector llDetectedTouchNormal(int index)
  1261. {
  1262. m_host.AddScriptLPS(1);
  1263. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1264. if (detectedParams == null)
  1265. return new LSL_Vector();
  1266. return detectedParams.TouchNormal;
  1267. }
  1268. /// <summary>
  1269. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1270. /// </summary>
  1271. public LSL_Vector llDetectedTouchPos(int index)
  1272. {
  1273. m_host.AddScriptLPS(1);
  1274. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1275. if (detectedParams == null)
  1276. return new LSL_Vector();
  1277. return detectedParams.TouchPos;
  1278. }
  1279. /// <summary>
  1280. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1281. /// </summary>
  1282. public LSL_Vector llDetectedTouchST(int index)
  1283. {
  1284. m_host.AddScriptLPS(1);
  1285. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1286. if (detectedParams == null)
  1287. return new LSL_Vector(-1.0, -1.0, 0.0);
  1288. return detectedParams.TouchST;
  1289. }
  1290. /// <summary>
  1291. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1292. /// </summary>
  1293. public LSL_Vector llDetectedTouchUV(int index)
  1294. {
  1295. m_host.AddScriptLPS(1);
  1296. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1297. if (detectedParams == null)
  1298. return new LSL_Vector(-1.0, -1.0, 0.0);
  1299. return detectedParams.TouchUV;
  1300. }
  1301. [DebuggerNonUserCode]
  1302. public virtual void llDie()
  1303. {
  1304. m_host.AddScriptLPS(1);
  1305. if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
  1306. }
  1307. public LSL_Float llGround(LSL_Vector offset)
  1308. {
  1309. m_host.AddScriptLPS(1);
  1310. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1311. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1312. LSL_Vector vsn = llGroundNormal(offset);
  1313. // Clamp to valid position
  1314. if (pos.X < 0)
  1315. pos.X = 0;
  1316. else if (pos.X >= World.Heightmap.Width)
  1317. pos.X = World.Heightmap.Width - 1;
  1318. if (pos.Y < 0)
  1319. pos.Y = 0;
  1320. else if (pos.Y >= World.Heightmap.Height)
  1321. pos.Y = World.Heightmap.Height - 1;
  1322. //Get the height for the integer coordinates from the Heightmap
  1323. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1324. //Calculate the difference between the actual coordinates and the integer coordinates
  1325. float xdiff = pos.X - (float)((int)pos.X);
  1326. float ydiff = pos.Y - (float)((int)pos.Y);
  1327. //Use the equation of the tangent plane to adjust the height to account for slope
  1328. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1329. }
  1330. public LSL_Float llCloud(LSL_Vector offset)
  1331. {
  1332. m_host.AddScriptLPS(1);
  1333. float cloudCover = 0f;
  1334. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1335. if (module != null)
  1336. {
  1337. Vector3 pos = m_host.GetWorldPosition();
  1338. int x = (int)(pos.X + offset.x);
  1339. int y = (int)(pos.Y + offset.y);
  1340. cloudCover = module.CloudCover(x, y, 0);
  1341. }
  1342. return cloudCover;
  1343. }
  1344. public LSL_Vector llWind(LSL_Vector offset)
  1345. {
  1346. m_host.AddScriptLPS(1);
  1347. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1348. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1349. if (module != null)
  1350. {
  1351. Vector3 pos = m_host.GetWorldPosition();
  1352. int x = (int)(pos.X + offset.x);
  1353. int y = (int)(pos.Y + offset.y);
  1354. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1355. wind.x = windSpeed.X;
  1356. wind.y = windSpeed.Y;
  1357. }
  1358. return wind;
  1359. }
  1360. public void llSetStatus(int status, int value)
  1361. {
  1362. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  1363. return;
  1364. m_host.AddScriptLPS(1);
  1365. int statusrotationaxis = 0;
  1366. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1367. {
  1368. if (value != 0)
  1369. {
  1370. SceneObjectGroup group = m_host.ParentGroup;
  1371. bool allow = true;
  1372. int maxprims = World.m_linksetPhysCapacity;
  1373. bool checkShape = (maxprims > 0 && group.PrimCount > maxprims);
  1374. foreach (SceneObjectPart part in group.Parts)
  1375. {
  1376. if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  1377. continue;
  1378. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1379. {
  1380. allow = false;
  1381. break;
  1382. }
  1383. if (checkShape)
  1384. {
  1385. if (--maxprims < 0)
  1386. {
  1387. allow = false;
  1388. break;
  1389. }
  1390. }
  1391. }
  1392. if (!allow)
  1393. return;
  1394. if (m_host.ParentGroup.RootPart.PhysActor != null &&
  1395. m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
  1396. return;
  1397. m_host.ScriptSetPhysicsStatus(true);
  1398. }
  1399. else
  1400. {
  1401. m_host.ScriptSetPhysicsStatus(false);
  1402. }
  1403. }
  1404. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1405. {
  1406. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1407. }
  1408. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1409. {
  1410. m_host.AddFlag(PrimFlags.CastShadows);
  1411. }
  1412. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1413. {
  1414. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1415. }
  1416. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1417. {
  1418. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1419. }
  1420. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1421. {
  1422. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1423. }
  1424. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1425. m_host.BlockGrab = value != 0;
  1426. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1427. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1428. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1429. {
  1430. if (value != 0)
  1431. m_host.SetDieAtEdge(true);
  1432. else
  1433. m_host.SetDieAtEdge(false);
  1434. }
  1435. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1436. {
  1437. if (value != 0)
  1438. m_host.SetReturnAtEdge(true);
  1439. else
  1440. m_host.SetReturnAtEdge(false);
  1441. }
  1442. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1443. {
  1444. if (value != 0)
  1445. m_host.SetStatusSandbox(true);
  1446. else
  1447. m_host.SetStatusSandbox(false);
  1448. }
  1449. if (statusrotationaxis != 0)
  1450. {
  1451. m_host.SetAxisRotation(statusrotationaxis, value);
  1452. }
  1453. }
  1454. private bool IsPhysical()
  1455. {
  1456. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1457. }
  1458. public LSL_Integer llGetStatus(int status)
  1459. {
  1460. m_host.AddScriptLPS(1);
  1461. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1462. switch (status)
  1463. {
  1464. case ScriptBaseClass.STATUS_PHYSICS:
  1465. return IsPhysical() ? 1 : 0;
  1466. case ScriptBaseClass.STATUS_PHANTOM:
  1467. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1468. {
  1469. return 1;
  1470. }
  1471. return 0;
  1472. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1473. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1474. {
  1475. return 1;
  1476. }
  1477. return 0;
  1478. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1479. return m_host.BlockGrab ? 1 : 0;
  1480. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1481. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1482. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1483. if (m_host.GetDieAtEdge())
  1484. return 1;
  1485. else
  1486. return 0;
  1487. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1488. if (m_host.GetReturnAtEdge())
  1489. return 1;
  1490. else
  1491. return 0;
  1492. case ScriptBaseClass.STATUS_ROTATE_X:
  1493. // if (m_host.GetAxisRotation(2) != 0)
  1494. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1495. return 1;
  1496. else
  1497. return 0;
  1498. case ScriptBaseClass.STATUS_ROTATE_Y:
  1499. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1500. return 1;
  1501. else
  1502. return 0;
  1503. case ScriptBaseClass.STATUS_ROTATE_Z:
  1504. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1505. return 1;
  1506. else
  1507. return 0;
  1508. case ScriptBaseClass.STATUS_SANDBOX:
  1509. if (m_host.GetStatusSandbox())
  1510. return 1;
  1511. else
  1512. return 0;
  1513. }
  1514. return 0;
  1515. }
  1516. public LSL_Integer llScaleByFactor(double scaling_factor)
  1517. {
  1518. m_host.AddScriptLPS(1);
  1519. SceneObjectGroup group = m_host.ParentGroup;
  1520. if(scaling_factor < 1e-6)
  1521. return ScriptBaseClass.FALSE;
  1522. if(scaling_factor > 1e6)
  1523. return ScriptBaseClass.FALSE;
  1524. if (group == null || group.IsDeleted || group.inTransit)
  1525. return ScriptBaseClass.FALSE;
  1526. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  1527. return ScriptBaseClass.FALSE;
  1528. if (group.RootPart.KeyframeMotion != null)
  1529. return ScriptBaseClass.FALSE;
  1530. if(group.GroupResize(scaling_factor))
  1531. return ScriptBaseClass.TRUE;
  1532. else
  1533. return ScriptBaseClass.FALSE;
  1534. }
  1535. public LSL_Float llGetMaxScaleFactor()
  1536. {
  1537. m_host.AddScriptLPS(1);
  1538. SceneObjectGroup group = m_host.ParentGroup;
  1539. if (group == null || group.IsDeleted || group.inTransit)
  1540. return 1.0f;
  1541. return (LSL_Float)group.GetMaxGroupResizeScale();
  1542. }
  1543. public LSL_Float llGetMinScaleFactor()
  1544. {
  1545. m_host.AddScriptLPS(1);
  1546. SceneObjectGroup group = m_host.ParentGroup;
  1547. if (group == null || group.IsDeleted || group.inTransit)
  1548. return 1.0f;
  1549. return (LSL_Float)group.GetMinGroupResizeScale();
  1550. }
  1551. public void llSetScale(LSL_Vector scale)
  1552. {
  1553. m_host.AddScriptLPS(1);
  1554. SetScale(m_host, scale);
  1555. }
  1556. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1557. {
  1558. // TODO: this needs to trigger a persistance save as well
  1559. if (part == null || part.ParentGroup.IsDeleted)
  1560. return;
  1561. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1562. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1563. if (pa != null && pa.IsPhysical)
  1564. {
  1565. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1566. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1567. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1568. }
  1569. else
  1570. {
  1571. // If not physical, then we clamp the scale to the non-physical min/max
  1572. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1573. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1574. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1575. }
  1576. Vector3 tmp = part.Scale;
  1577. tmp.X = (float)scale.x;
  1578. tmp.Y = (float)scale.y;
  1579. tmp.Z = (float)scale.z;
  1580. part.Scale = tmp;
  1581. part.ParentGroup.HasGroupChanged = true;
  1582. part.SendFullUpdateToAllClients();
  1583. }
  1584. public LSL_Vector llGetScale()
  1585. {
  1586. m_host.AddScriptLPS(1);
  1587. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1588. }
  1589. public void llSetClickAction(int action)
  1590. {
  1591. m_host.AddScriptLPS(1);
  1592. m_host.ClickAction = (byte)action;
  1593. m_host.ParentGroup.HasGroupChanged = true;
  1594. m_host.ScheduleFullUpdate();
  1595. return;
  1596. }
  1597. public void llSetColor(LSL_Vector color, int face)
  1598. {
  1599. m_host.AddScriptLPS(1);
  1600. SetColor(m_host, color, face);
  1601. }
  1602. protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
  1603. {
  1604. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1605. return;
  1606. m_host.SetFaceColorAlpha(face, color, null);
  1607. }
  1608. public void llSetContentType(LSL_Key reqid, LSL_Integer type)
  1609. {
  1610. m_host.AddScriptLPS(1);
  1611. if (m_UrlModule == null)
  1612. return;
  1613. if(!UUID.TryParse(reqid, out UUID id))
  1614. return;
  1615. // Make sure the content type is text/plain to start with
  1616. m_UrlModule.HttpContentType(id, "text/plain");
  1617. // Is the object owner online and in the region
  1618. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1619. if (agent == null || agent.IsChildAgent || agent.IsDeleted)
  1620. return; // Fail if the owner is not in the same region
  1621. // Is it the embeded browser?
  1622. string userAgent = m_UrlModule.GetHttpHeader(id, "user-agent");
  1623. if (userAgent.IndexOf("SecondLife") < 0)
  1624. return; // Not the embedded browser. Is this check good enough?
  1625. // Use the IP address of the client and check against the request
  1626. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1627. // as the owner is in the region. Same as SL!
  1628. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1629. if (string.IsNullOrEmpty(logonFromIPAddress))
  1630. return;
  1631. string requestFromIPAddress = m_UrlModule.GetHttpHeader(id, "x-remote-ip");
  1632. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1633. if (requestFromIPAddress == null)
  1634. return;
  1635. requestFromIPAddress = requestFromIPAddress.Trim();
  1636. // If the request isnt from the same IP address then the request cannot be from the owner
  1637. if (!requestFromIPAddress.Equals(logonFromIPAddress))
  1638. return;
  1639. switch (type)
  1640. {
  1641. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1642. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1643. break;
  1644. case ScriptBaseClass.CONTENT_TYPE_XML:
  1645. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1646. break;
  1647. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1648. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1649. break;
  1650. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1651. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1652. break;
  1653. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1654. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1655. break;
  1656. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1657. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1658. break;
  1659. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1660. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1661. break;
  1662. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1663. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1664. break;
  1665. default:
  1666. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1667. break;
  1668. }
  1669. }
  1670. public void SetTexGen(SceneObjectPart part, int face,int style)
  1671. {
  1672. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1673. return;
  1674. Primitive.TextureEntry tex = part.Shape.Textures;
  1675. MappingType textype;
  1676. textype = MappingType.Default;
  1677. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1678. textype = MappingType.Planar;
  1679. int nsides = GetNumberOfSides(part);
  1680. if (face >= 0 && face < nsides)
  1681. {
  1682. tex.CreateFace((uint) face);
  1683. tex.FaceTextures[face].TexMapType = textype;
  1684. part.UpdateTextureEntry(tex);
  1685. return;
  1686. }
  1687. else if (face == ScriptBaseClass.ALL_SIDES)
  1688. {
  1689. for (uint i = 0; i < nsides; i++)
  1690. {
  1691. if (tex.FaceTextures[i] != null)
  1692. {
  1693. tex.FaceTextures[i].TexMapType = textype;
  1694. }
  1695. }
  1696. tex.DefaultTexture.TexMapType = textype;
  1697. part.UpdateTextureEntry(tex);
  1698. return;
  1699. }
  1700. }
  1701. public void SetGlow(SceneObjectPart part, int face, float glow)
  1702. {
  1703. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1704. return;
  1705. Primitive.TextureEntry tex = part.Shape.Textures;
  1706. int nsides = GetNumberOfSides(part);
  1707. if (face >= 0 && face < nsides)
  1708. {
  1709. tex.CreateFace((uint) face);
  1710. tex.FaceTextures[face].Glow = glow;
  1711. part.UpdateTextureEntry(tex);
  1712. return;
  1713. }
  1714. else if (face == ScriptBaseClass.ALL_SIDES)
  1715. {
  1716. for (uint i = 0; i < nsides; i++)
  1717. {
  1718. if (tex.FaceTextures[i] != null)
  1719. {
  1720. tex.FaceTextures[i].Glow = glow;
  1721. }
  1722. }
  1723. tex.DefaultTexture.Glow = glow;
  1724. part.UpdateTextureEntry(tex);
  1725. return;
  1726. }
  1727. }
  1728. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1729. {
  1730. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1731. return;
  1732. Shininess sval = new Shininess();
  1733. switch (shiny)
  1734. {
  1735. case 0:
  1736. sval = Shininess.None;
  1737. break;
  1738. case 1:
  1739. sval = Shininess.Low;
  1740. break;
  1741. case 2:
  1742. sval = Shininess.Medium;
  1743. break;
  1744. case 3:
  1745. sval = Shininess.High;
  1746. break;
  1747. default:
  1748. sval = Shininess.None;
  1749. break;
  1750. }
  1751. int nsides = GetNumberOfSides(part);
  1752. Primitive.TextureEntry tex = part.Shape.Textures;
  1753. if (face >= 0 && face < nsides)
  1754. {
  1755. tex.CreateFace((uint) face);
  1756. tex.FaceTextures[face].Shiny = sval;
  1757. tex.FaceTextures[face].Bump = bump;
  1758. part.UpdateTextureEntry(tex);
  1759. return;
  1760. }
  1761. else if (face == ScriptBaseClass.ALL_SIDES)
  1762. {
  1763. for (uint i = 0; i < nsides; i++)
  1764. {
  1765. if (tex.FaceTextures[i] != null)
  1766. {
  1767. tex.FaceTextures[i].Shiny = sval;
  1768. tex.FaceTextures[i].Bump = bump;
  1769. }
  1770. }
  1771. tex.DefaultTexture.Shiny = sval;
  1772. tex.DefaultTexture.Bump = bump;
  1773. part.UpdateTextureEntry(tex);
  1774. return;
  1775. }
  1776. }
  1777. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1778. {
  1779. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1780. return;
  1781. int nsides = GetNumberOfSides(part);
  1782. Primitive.TextureEntry tex = part.Shape.Textures;
  1783. if (face >= 0 && face < nsides)
  1784. {
  1785. tex.CreateFace((uint) face);
  1786. tex.FaceTextures[face].Fullbright = bright;
  1787. part.UpdateTextureEntry(tex);
  1788. return;
  1789. }
  1790. else if (face == ScriptBaseClass.ALL_SIDES)
  1791. {
  1792. for (uint i = 0; i < nsides; i++)
  1793. {
  1794. if (tex.FaceTextures[i] != null)
  1795. {
  1796. tex.FaceTextures[i].Fullbright = bright;
  1797. }
  1798. }
  1799. tex.DefaultTexture.Fullbright = bright;
  1800. part.UpdateTextureEntry(tex);
  1801. return;
  1802. }
  1803. }
  1804. public LSL_Float llGetAlpha(int face)
  1805. {
  1806. m_host.AddScriptLPS(1);
  1807. return GetAlpha(m_host, face);
  1808. }
  1809. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1810. {
  1811. Primitive.TextureEntry tex = part.Shape.Textures;
  1812. int nsides = GetNumberOfSides(part);
  1813. if (face == ScriptBaseClass.ALL_SIDES)
  1814. {
  1815. int i;
  1816. double sum = 0.0;
  1817. for (i = 0 ; i < nsides; i++)
  1818. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1819. return sum;
  1820. }
  1821. if (face >= 0 && face < nsides)
  1822. {
  1823. return (double)tex.GetFace((uint)face).RGBA.A;
  1824. }
  1825. return 0.0;
  1826. }
  1827. public void llSetAlpha(double alpha, int face)
  1828. {
  1829. m_host.AddScriptLPS(1);
  1830. SetAlpha(m_host, alpha, face);
  1831. }
  1832. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1833. {
  1834. m_host.AddScriptLPS(1);
  1835. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1836. if (parts.Count > 0)
  1837. {
  1838. try
  1839. {
  1840. foreach (SceneObjectPart part in parts)
  1841. SetAlpha(part, alpha, face);
  1842. }
  1843. finally { }
  1844. }
  1845. }
  1846. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1847. {
  1848. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1849. return;
  1850. Primitive.TextureEntry tex = part.Shape.Textures;
  1851. int nsides = GetNumberOfSides(part);
  1852. Color4 texcolor;
  1853. if (face >= 0 && face < nsides)
  1854. {
  1855. texcolor = tex.CreateFace((uint)face).RGBA;
  1856. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1857. tex.FaceTextures[face].RGBA = texcolor;
  1858. part.UpdateTextureEntry(tex);
  1859. return;
  1860. }
  1861. else if (face == ScriptBaseClass.ALL_SIDES)
  1862. {
  1863. for (int i = 0; i < nsides; i++)
  1864. {
  1865. if (tex.FaceTextures[i] != null)
  1866. {
  1867. texcolor = tex.FaceTextures[i].RGBA;
  1868. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1869. tex.FaceTextures[i].RGBA = texcolor;
  1870. }
  1871. }
  1872. // In some cases, the default texture can be null, eg when every face
  1873. // has a unique texture
  1874. if (tex.DefaultTexture != null)
  1875. {
  1876. texcolor = tex.DefaultTexture.RGBA;
  1877. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1878. tex.DefaultTexture.RGBA = texcolor;
  1879. }
  1880. part.UpdateTextureEntry(tex);
  1881. return;
  1882. }
  1883. }
  1884. /// <summary>
  1885. /// Set flexi parameters of a part.
  1886. ///
  1887. /// FIXME: Much of this code should probably be within the part itself.
  1888. /// </summary>
  1889. /// <param name="part"></param>
  1890. /// <param name="flexi"></param>
  1891. /// <param name="softness"></param>
  1892. /// <param name="gravity"></param>
  1893. /// <param name="friction"></param>
  1894. /// <param name="wind"></param>
  1895. /// <param name="tension"></param>
  1896. /// <param name="Force"></param>
  1897. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1898. float wind, float tension, LSL_Vector Force)
  1899. {
  1900. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1901. return;
  1902. if (flexi)
  1903. {
  1904. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1905. // work once the prim is already flexi
  1906. part.Shape.FlexiSoftness = softness;
  1907. part.Shape.FlexiGravity = gravity;
  1908. part.Shape.FlexiDrag = friction;
  1909. part.Shape.FlexiWind = wind;
  1910. part.Shape.FlexiTension = tension;
  1911. part.Shape.FlexiForceX = (float)Force.x;
  1912. part.Shape.FlexiForceY = (float)Force.y;
  1913. part.Shape.FlexiForceZ = (float)Force.z;
  1914. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  1915. }
  1916. else
  1917. {
  1918. // Other values not set, they do not seem to be sent to the viewer
  1919. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  1920. part.Shape.PathCurve = (byte)Extrusion.Straight;
  1921. part.Shape.FlexiEntry = false;
  1922. }
  1923. part.ParentGroup.HasGroupChanged = true;
  1924. part.ScheduleFullUpdate();
  1925. }
  1926. /// <summary>
  1927. /// Set a light point on a part
  1928. /// </summary>
  1929. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1930. ///
  1931. /// <param name="part"></param>
  1932. /// <param name="light"></param>
  1933. /// <param name="color"></param>
  1934. /// <param name="intensity"></param>
  1935. /// <param name="radius"></param>
  1936. /// <param name="falloff"></param>
  1937. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1938. {
  1939. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1940. return;
  1941. if (light)
  1942. {
  1943. part.Shape.LightEntry = true;
  1944. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  1945. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  1946. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  1947. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  1948. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  1949. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  1950. }
  1951. else
  1952. {
  1953. part.Shape.LightEntry = false;
  1954. }
  1955. part.ParentGroup.HasGroupChanged = true;
  1956. part.ScheduleFullUpdate();
  1957. }
  1958. public LSL_Vector llGetColor(int face)
  1959. {
  1960. m_host.AddScriptLPS(1);
  1961. return GetColor(m_host, face);
  1962. }
  1963. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  1964. {
  1965. Primitive.TextureEntry tex = part.Shape.Textures;
  1966. Color4 texcolor;
  1967. LSL_Vector rgb = new LSL_Vector();
  1968. int nsides = GetNumberOfSides(part);
  1969. if (face == ScriptBaseClass.ALL_SIDES)
  1970. {
  1971. int i;
  1972. for (i = 0; i < nsides; i++)
  1973. {
  1974. texcolor = tex.GetFace((uint)i).RGBA;
  1975. rgb.x += texcolor.R;
  1976. rgb.y += texcolor.G;
  1977. rgb.z += texcolor.B;
  1978. }
  1979. float invnsides = 1.0f / (float)nsides;
  1980. rgb.x *= invnsides;
  1981. rgb.y *= invnsides;
  1982. rgb.z *= invnsides;
  1983. return rgb;
  1984. }
  1985. if (face >= 0 && face < nsides)
  1986. {
  1987. texcolor = tex.GetFace((uint)face).RGBA;
  1988. rgb.x = texcolor.R;
  1989. rgb.y = texcolor.G;
  1990. rgb.z = texcolor.B;
  1991. return rgb;
  1992. }
  1993. else
  1994. {
  1995. return new LSL_Vector();
  1996. }
  1997. }
  1998. public void llSetTexture(string texture, int face)
  1999. {
  2000. m_host.AddScriptLPS(1);
  2001. SetTexture(m_host, texture, face);
  2002. ScriptSleep(m_sleepMsOnSetTexture);
  2003. }
  2004. public void llSetLinkTexture(int linknumber, string texture, int face)
  2005. {
  2006. m_host.AddScriptLPS(1);
  2007. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  2008. if (parts.Count > 0)
  2009. {
  2010. try
  2011. {
  2012. foreach (SceneObjectPart part in parts)
  2013. SetTexture(part, texture, face);
  2014. }
  2015. finally { }
  2016. }
  2017. ScriptSleep(m_sleepMsOnSetLinkTexture);
  2018. }
  2019. protected void SetTextureParams(SceneObjectPart part, string texture, double scaleU, double ScaleV,
  2020. double offsetU, double offsetV, double rotation, int face)
  2021. {
  2022. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2023. return;
  2024. UUID textureID = new UUID();
  2025. bool dotexture = true;
  2026. if(String.IsNullOrEmpty(texture) || texture == ScriptBaseClass.NULL_KEY)
  2027. dotexture = false;
  2028. else
  2029. {
  2030. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2031. if (textureID == UUID.Zero)
  2032. {
  2033. if (!UUID.TryParse(texture, out textureID))
  2034. dotexture = false;
  2035. }
  2036. }
  2037. Primitive.TextureEntry tex = part.Shape.Textures;
  2038. int nsides = GetNumberOfSides(part);
  2039. if (face >= 0 && face < nsides)
  2040. {
  2041. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2042. if (dotexture)
  2043. texface.TextureID = textureID;
  2044. texface.RepeatU = (float)scaleU;
  2045. texface.RepeatV = (float)ScaleV;
  2046. texface.OffsetU = (float)offsetU;
  2047. texface.OffsetV = (float)offsetV;
  2048. texface.Rotation = (float)rotation;
  2049. tex.FaceTextures[face] = texface;
  2050. part.UpdateTextureEntry(tex);
  2051. return;
  2052. }
  2053. else if (face == ScriptBaseClass.ALL_SIDES)
  2054. {
  2055. for (uint i = 0; i < nsides; i++)
  2056. {
  2057. if (tex.FaceTextures[i] != null)
  2058. {
  2059. if (dotexture)
  2060. tex.FaceTextures[i].TextureID = textureID;
  2061. tex.FaceTextures[i].RepeatU = (float)scaleU;
  2062. tex.FaceTextures[i].RepeatV = (float)ScaleV;
  2063. tex.FaceTextures[i].OffsetU = (float)offsetU;
  2064. tex.FaceTextures[i].OffsetV = (float)offsetV;
  2065. tex.FaceTextures[i].Rotation = (float)rotation;
  2066. }
  2067. }
  2068. if (dotexture)
  2069. tex.DefaultTexture.TextureID = textureID;
  2070. tex.DefaultTexture.RepeatU = (float)scaleU;
  2071. tex.DefaultTexture.RepeatV = (float)ScaleV;
  2072. tex.DefaultTexture.OffsetU = (float)offsetU;
  2073. tex.DefaultTexture.OffsetV = (float)offsetV;
  2074. tex.DefaultTexture.Rotation = (float)rotation;
  2075. part.UpdateTextureEntry(tex);
  2076. return;
  2077. }
  2078. }
  2079. protected void SetTexture(SceneObjectPart part, string texture, int face)
  2080. {
  2081. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2082. return;
  2083. UUID textureID = new UUID();
  2084. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2085. if (textureID == UUID.Zero)
  2086. {
  2087. if (!UUID.TryParse(texture, out textureID))
  2088. return;
  2089. }
  2090. Primitive.TextureEntry tex = part.Shape.Textures;
  2091. int nsides = GetNumberOfSides(part);
  2092. if (face >= 0 && face < nsides)
  2093. {
  2094. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2095. texface.TextureID = textureID;
  2096. tex.FaceTextures[face] = texface;
  2097. part.UpdateTextureEntry(tex);
  2098. return;
  2099. }
  2100. else if (face == ScriptBaseClass.ALL_SIDES)
  2101. {
  2102. for (uint i = 0; i < nsides; i++)
  2103. {
  2104. if (tex.FaceTextures[i] != null)
  2105. {
  2106. tex.FaceTextures[i].TextureID = textureID;
  2107. }
  2108. }
  2109. tex.DefaultTexture.TextureID = textureID;
  2110. part.UpdateTextureEntry(tex);
  2111. return;
  2112. }
  2113. }
  2114. public void llScaleTexture(double u, double v, int face)
  2115. {
  2116. m_host.AddScriptLPS(1);
  2117. ScaleTexture(m_host, u, v, face);
  2118. ScriptSleep(m_sleepMsOnScaleTexture);
  2119. }
  2120. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  2121. {
  2122. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2123. return;
  2124. Primitive.TextureEntry tex = part.Shape.Textures;
  2125. int nsides = GetNumberOfSides(part);
  2126. if (face >= 0 && face < nsides)
  2127. {
  2128. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2129. texface.RepeatU = (float)u;
  2130. texface.RepeatV = (float)v;
  2131. tex.FaceTextures[face] = texface;
  2132. part.UpdateTextureEntry(tex);
  2133. return;
  2134. }
  2135. if (face == ScriptBaseClass.ALL_SIDES)
  2136. {
  2137. for (int i = 0; i < nsides; i++)
  2138. {
  2139. if (tex.FaceTextures[i] != null)
  2140. {
  2141. tex.FaceTextures[i].RepeatU = (float)u;
  2142. tex.FaceTextures[i].RepeatV = (float)v;
  2143. }
  2144. }
  2145. tex.DefaultTexture.RepeatU = (float)u;
  2146. tex.DefaultTexture.RepeatV = (float)v;
  2147. part.UpdateTextureEntry(tex);
  2148. return;
  2149. }
  2150. }
  2151. public void llOffsetTexture(double u, double v, int face)
  2152. {
  2153. m_host.AddScriptLPS(1);
  2154. OffsetTexture(m_host, u, v, face);
  2155. ScriptSleep(m_sleepMsOnOffsetTexture);
  2156. }
  2157. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  2158. {
  2159. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2160. return;
  2161. Primitive.TextureEntry tex = part.Shape.Textures;
  2162. int nsides = GetNumberOfSides(part);
  2163. if (face >= 0 && face < nsides)
  2164. {
  2165. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2166. texface.OffsetU = (float)u;
  2167. texface.OffsetV = (float)v;
  2168. tex.FaceTextures[face] = texface;
  2169. part.UpdateTextureEntry(tex);
  2170. return;
  2171. }
  2172. if (face == ScriptBaseClass.ALL_SIDES)
  2173. {
  2174. for (int i = 0; i < nsides; i++)
  2175. {
  2176. if (tex.FaceTextures[i] != null)
  2177. {
  2178. tex.FaceTextures[i].OffsetU = (float)u;
  2179. tex.FaceTextures[i].OffsetV = (float)v;
  2180. }
  2181. }
  2182. tex.DefaultTexture.OffsetU = (float)u;
  2183. tex.DefaultTexture.OffsetV = (float)v;
  2184. part.UpdateTextureEntry(tex);
  2185. return;
  2186. }
  2187. }
  2188. public void llRotateTexture(double rotation, int face)
  2189. {
  2190. m_host.AddScriptLPS(1);
  2191. RotateTexture(m_host, rotation, face);
  2192. ScriptSleep(m_sleepMsOnRotateTexture);
  2193. }
  2194. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  2195. {
  2196. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2197. return;
  2198. Primitive.TextureEntry tex = part.Shape.Textures;
  2199. int nsides = GetNumberOfSides(part);
  2200. if (face >= 0 && face < nsides)
  2201. {
  2202. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2203. texface.Rotation = (float)rotation;
  2204. tex.FaceTextures[face] = texface;
  2205. part.UpdateTextureEntry(tex);
  2206. return;
  2207. }
  2208. if (face == ScriptBaseClass.ALL_SIDES)
  2209. {
  2210. for (int i = 0; i < nsides; i++)
  2211. {
  2212. if (tex.FaceTextures[i] != null)
  2213. {
  2214. tex.FaceTextures[i].Rotation = (float)rotation;
  2215. }
  2216. }
  2217. tex.DefaultTexture.Rotation = (float)rotation;
  2218. part.UpdateTextureEntry(tex);
  2219. return;
  2220. }
  2221. }
  2222. public LSL_String llGetTexture(int face)
  2223. {
  2224. m_host.AddScriptLPS(1);
  2225. return GetTexture(m_host, face);
  2226. }
  2227. protected LSL_String GetTexture(SceneObjectPart part, int face)
  2228. {
  2229. Primitive.TextureEntry tex = part.Shape.Textures;
  2230. int nsides = GetNumberOfSides(part);
  2231. if (face == ScriptBaseClass.ALL_SIDES)
  2232. {
  2233. face = 0;
  2234. }
  2235. if (face >= 0 && face < nsides)
  2236. {
  2237. Primitive.TextureEntryFace texface;
  2238. texface = tex.GetFace((uint)face);
  2239. string texture = texface.TextureID.ToString();
  2240. lock (part.TaskInventory)
  2241. {
  2242. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  2243. {
  2244. if (inv.Value.AssetID == texface.TextureID)
  2245. {
  2246. texture = inv.Value.Name.ToString();
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. return texture;
  2252. }
  2253. else
  2254. {
  2255. return ScriptBaseClass.NULL_KEY;
  2256. }
  2257. }
  2258. public void llSetPos(LSL_Vector pos)
  2259. {
  2260. m_host.AddScriptLPS(1);
  2261. SetPos(m_host, pos, true);
  2262. ScriptSleep(m_sleepMsOnSetPos);
  2263. }
  2264. /// <summary>
  2265. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  2266. /// 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.
  2267. /// 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.
  2268. /// </summary>
  2269. /// <param name="pos"></param>
  2270. /// <returns>1 if successful, 0 otherwise.</returns>
  2271. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  2272. {
  2273. m_host.AddScriptLPS(1);
  2274. // BEGIN WORKAROUND
  2275. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  2276. //
  2277. // This workaround is to prevent silent failure of this function.
  2278. // According to the specification on the SL Wiki, providing a position outside of the
  2279. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  2280. {
  2281. return 0;
  2282. }
  2283. // END WORK AROUND
  2284. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  2285. IsPhysical() ||
  2286. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  2287. (
  2288. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  2289. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  2290. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  2291. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  2292. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  2293. )
  2294. )
  2295. {
  2296. return 0;
  2297. }
  2298. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  2299. // 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.
  2300. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  2301. LandData here = World.GetLandData(objectPos);
  2302. LandData there = World.GetLandData(pos);
  2303. // 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.
  2304. bool sameParcel = here.GlobalID == there.GlobalID;
  2305. if (!sameParcel && !World.Permissions.CanRezObject(
  2306. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  2307. {
  2308. return 0;
  2309. }
  2310. SetPos(m_host.ParentGroup.RootPart, pos, false);
  2311. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  2312. }
  2313. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2314. // note linked setpos is capped "differently"
  2315. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  2316. {
  2317. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  2318. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  2319. else
  2320. return end;
  2321. }
  2322. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
  2323. {
  2324. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2325. return fromPos;
  2326. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2327. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2328. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2329. if (part.ParentGroup.RootPart == part)
  2330. {
  2331. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2332. targetPos.z = ground;
  2333. }
  2334. if (adjust)
  2335. return SetPosAdjust(fromPos, targetPos);
  2336. return targetPos;
  2337. }
  2338. /// <summary>
  2339. /// set object position, optionally capping the distance.
  2340. /// </summary>
  2341. /// <param name="part"></param>
  2342. /// <param name="targetPos"></param>
  2343. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  2344. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  2345. {
  2346. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted || part.ParentGroup.inTransit)
  2347. return;
  2348. LSL_Vector currentPos = GetPartLocalPos(part);
  2349. LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
  2350. if (part.ParentGroup.RootPart == part)
  2351. {
  2352. SceneObjectGroup parent = part.ParentGroup;
  2353. if (!parent.IsAttachment && !World.Permissions.CanObjectEntry(parent, false, (Vector3)toPos))
  2354. return;
  2355. parent.UpdateGroupPosition((Vector3)toPos);
  2356. }
  2357. else
  2358. {
  2359. part.OffsetPosition = (Vector3)toPos;
  2360. // SceneObjectGroup parent = part.ParentGroup;
  2361. // parent.HasGroupChanged = true;
  2362. // parent.ScheduleGroupForTerseUpdate();
  2363. part.ScheduleTerseUpdate();
  2364. }
  2365. }
  2366. public LSL_Vector llGetPos()
  2367. {
  2368. m_host.AddScriptLPS(1);
  2369. return m_host.GetWorldPosition();
  2370. }
  2371. public LSL_Vector llGetLocalPos()
  2372. {
  2373. m_host.AddScriptLPS(1);
  2374. return GetPartLocalPos(m_host);
  2375. }
  2376. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  2377. {
  2378. m_host.AddScriptLPS(1);
  2379. Vector3 pos;
  2380. if (!part.IsRoot)
  2381. {
  2382. pos = part.OffsetPosition;
  2383. }
  2384. else
  2385. {
  2386. if (part.ParentGroup.IsAttachment)
  2387. pos = part.AttachedPos;
  2388. else
  2389. pos = part.AbsolutePosition;
  2390. }
  2391. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2392. return new LSL_Vector(pos);
  2393. }
  2394. public void llSetRot(LSL_Rotation rot)
  2395. {
  2396. m_host.AddScriptLPS(1);
  2397. // try to let this work as in SL...
  2398. if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
  2399. {
  2400. // special case: If we are root, rotate complete SOG to new rotation
  2401. SetRot(m_host, rot);
  2402. }
  2403. else
  2404. {
  2405. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2406. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2407. if (rootPart != null) // better safe than sorry
  2408. {
  2409. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2410. }
  2411. }
  2412. ScriptSleep(m_sleepMsOnSetRot);
  2413. }
  2414. public void llSetLocalRot(LSL_Rotation rot)
  2415. {
  2416. m_host.AddScriptLPS(1);
  2417. SetRot(m_host, rot);
  2418. ScriptSleep(m_sleepMsOnSetLocalRot);
  2419. }
  2420. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2421. {
  2422. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2423. return;
  2424. bool isroot = (part == part.ParentGroup.RootPart);
  2425. bool isphys;
  2426. PhysicsActor pa = part.PhysActor;
  2427. // keep using physactor ideia of isphysical
  2428. // it should be SOP ideia of that
  2429. // not much of a issue with ubOde
  2430. if (pa != null && pa.IsPhysical)
  2431. isphys = true;
  2432. else
  2433. isphys = false;
  2434. // SL doesn't let scripts rotate root of physical linksets
  2435. if (isroot && isphys)
  2436. return;
  2437. part.UpdateRotation(rot);
  2438. // Update rotation does not move the object in the physics engine if it's a non physical linkset
  2439. // so do a nasty update of parts positions if is a root part rotation
  2440. if (isroot && pa != null) // with if above implies non physical root part
  2441. {
  2442. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2443. }
  2444. else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
  2445. {
  2446. // List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
  2447. List<ScenePresence> sittingavas = part.ParentGroup.GetSittingAvatars();
  2448. if (sittingavas.Count > 0)
  2449. {
  2450. foreach (ScenePresence av in sittingavas)
  2451. {
  2452. if (isroot || part.LocalId == av.ParentID)
  2453. av.SendTerseUpdateToAllClients();
  2454. }
  2455. }
  2456. }
  2457. }
  2458. /// <summary>
  2459. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2460. /// </summary>
  2461. public LSL_Rotation llGetRot()
  2462. {
  2463. // unlinked or root prim then use llRootRotation
  2464. // see llRootRotaion for references.
  2465. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2466. {
  2467. return llGetRootRotation();
  2468. }
  2469. m_host.AddScriptLPS(1);
  2470. Quaternion q = m_host.GetWorldRotation();
  2471. if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
  2472. {
  2473. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2474. if (avatar != null)
  2475. {
  2476. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2477. q = avatar.CameraRotation * q; // Mouselook
  2478. else
  2479. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2480. }
  2481. }
  2482. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2483. }
  2484. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2485. {
  2486. Quaternion q;
  2487. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2488. {
  2489. if (part.ParentGroup.AttachmentPoint != 0)
  2490. {
  2491. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2492. if (avatar != null)
  2493. {
  2494. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2495. q = avatar.CameraRotation; // Mouselook
  2496. else
  2497. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2498. }
  2499. else
  2500. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2501. }
  2502. else
  2503. q = part.ParentGroup.GroupRotation; // just the group rotation
  2504. return new LSL_Rotation(q);
  2505. }
  2506. q = part.GetWorldRotation();
  2507. if (part.ParentGroup.AttachmentPoint != 0)
  2508. {
  2509. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2510. if (avatar != null)
  2511. {
  2512. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2513. q = avatar.CameraRotation * q; // Mouselook
  2514. else
  2515. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2516. }
  2517. }
  2518. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2519. }
  2520. public LSL_Rotation llGetLocalRot()
  2521. {
  2522. return GetPartLocalRot(m_host);
  2523. }
  2524. private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
  2525. {
  2526. m_host.AddScriptLPS(1);
  2527. Quaternion rot = part.RotationOffset;
  2528. return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
  2529. }
  2530. public void llSetForce(LSL_Vector force, int local)
  2531. {
  2532. m_host.AddScriptLPS(1);
  2533. if (!m_host.ParentGroup.IsDeleted)
  2534. {
  2535. if (local != 0)
  2536. force *= llGetRot();
  2537. m_host.ParentGroup.RootPart.SetForce(force);
  2538. }
  2539. }
  2540. public LSL_Vector llGetForce()
  2541. {
  2542. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2543. m_host.AddScriptLPS(1);
  2544. if (!m_host.ParentGroup.IsDeleted)
  2545. {
  2546. force = m_host.ParentGroup.RootPart.GetForce();
  2547. }
  2548. return force;
  2549. }
  2550. public void llSetVelocity(LSL_Vector vel, int local)
  2551. {
  2552. m_host.AddScriptLPS(1);
  2553. m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
  2554. }
  2555. public void llSetAngularVelocity(LSL_Vector avel, int local)
  2556. {
  2557. m_host.AddScriptLPS(1);
  2558. m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
  2559. }
  2560. public LSL_Integer llTarget(LSL_Vector position, double range)
  2561. {
  2562. m_host.AddScriptLPS(1);
  2563. return m_host.ParentGroup.RegisterTargetWaypoint(m_item.ItemID, position, (float)range);
  2564. }
  2565. public void llTargetRemove(int number)
  2566. {
  2567. m_host.AddScriptLPS(1);
  2568. m_host.ParentGroup.UnregisterTargetWaypoint(number);
  2569. }
  2570. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  2571. {
  2572. m_host.AddScriptLPS(1);
  2573. return m_host.ParentGroup.RegisterRotTargetWaypoint(m_item.ItemID, rot, (float)error);
  2574. }
  2575. public void llRotTargetRemove(int number)
  2576. {
  2577. m_host.AddScriptLPS(1);
  2578. m_host.ParentGroup.UnRegisterRotTargetWaypoint(number);
  2579. }
  2580. public void llMoveToTarget(LSL_Vector target, double tau)
  2581. {
  2582. m_host.AddScriptLPS(1);
  2583. m_host.ParentGroup.MoveToTarget(target, (float)tau);
  2584. }
  2585. public void llStopMoveToTarget()
  2586. {
  2587. m_host.AddScriptLPS(1);
  2588. m_host.ParentGroup.StopMoveToTarget();
  2589. }
  2590. public void llApplyImpulse(LSL_Vector force, LSL_Integer local)
  2591. {
  2592. m_host.AddScriptLPS(1);
  2593. //No energy force yet
  2594. Vector3 v = force;
  2595. if (v.Length() > 20000.0f)
  2596. {
  2597. v.Normalize();
  2598. v = v * 20000.0f;
  2599. }
  2600. m_host.ApplyImpulse(v, local != 0);
  2601. }
  2602. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  2603. {
  2604. m_host.AddScriptLPS(1);
  2605. m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
  2606. }
  2607. public void llSetTorque(LSL_Vector torque, int local)
  2608. {
  2609. m_host.AddScriptLPS(1);
  2610. m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
  2611. }
  2612. public LSL_Vector llGetTorque()
  2613. {
  2614. m_host.AddScriptLPS(1);
  2615. return new LSL_Vector(m_host.ParentGroup.GetTorque());
  2616. }
  2617. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  2618. {
  2619. m_host.AddScriptLPS(1);
  2620. llSetForce(force, local);
  2621. llSetTorque(torque, local);
  2622. }
  2623. public LSL_Vector llGetVel()
  2624. {
  2625. m_host.AddScriptLPS(1);
  2626. Vector3 vel = Vector3.Zero;
  2627. if (m_host.ParentGroup.IsAttachment)
  2628. {
  2629. ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2630. if (avatar != null)
  2631. vel = avatar.GetWorldVelocity();
  2632. }
  2633. else
  2634. {
  2635. vel = m_host.ParentGroup.RootPart.Velocity;
  2636. }
  2637. return new LSL_Vector(vel);
  2638. }
  2639. public LSL_Vector llGetAccel()
  2640. {
  2641. m_host.AddScriptLPS(1);
  2642. return new LSL_Vector(m_host.Acceleration);
  2643. }
  2644. public LSL_Vector llGetOmega()
  2645. {
  2646. m_host.AddScriptLPS(1);
  2647. Vector3 avel = m_host.AngularVelocity;
  2648. return new LSL_Vector(avel.X, avel.Y, avel.Z);
  2649. }
  2650. public LSL_Float llGetTimeOfDay()
  2651. {
  2652. m_host.AddScriptLPS(1);
  2653. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  2654. }
  2655. public LSL_Float llGetWallclock()
  2656. {
  2657. m_host.AddScriptLPS(1);
  2658. return DateTime.Now.TimeOfDay.TotalSeconds;
  2659. }
  2660. public LSL_Float llGetTime()
  2661. {
  2662. m_host.AddScriptLPS(1);
  2663. double ScriptTime = Util.GetTimeStampMS() - m_timer;
  2664. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2665. }
  2666. public void llResetTime()
  2667. {
  2668. m_host.AddScriptLPS(1);
  2669. m_timer = Util.GetTimeStampMS();
  2670. }
  2671. public LSL_Float llGetAndResetTime()
  2672. {
  2673. m_host.AddScriptLPS(1);
  2674. double now = Util.GetTimeStampMS();
  2675. double ScriptTime = now - m_timer;
  2676. m_timer = now;
  2677. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2678. }
  2679. public void llSound(string sound, double volume, int queue, int loop)
  2680. {
  2681. m_host.AddScriptLPS(1);
  2682. Deprecated("llSound", "Use llPlaySound instead");
  2683. }
  2684. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2685. // 20080530 Updated to remove code duplication
  2686. public void llPlaySound(string sound, double volume)
  2687. {
  2688. m_host.AddScriptLPS(1);
  2689. if (m_SoundModule == null)
  2690. return;
  2691. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2692. if(soundID == UUID.Zero)
  2693. return;
  2694. // send the sound, once, to all clients in range
  2695. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, false, false);
  2696. }
  2697. public void llLoopSound(string sound, double volume)
  2698. {
  2699. m_host.AddScriptLPS(1);
  2700. if (m_SoundModule == null)
  2701. return;
  2702. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2703. if(soundID == UUID.Zero)
  2704. return;
  2705. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false,false);
  2706. }
  2707. public void llLoopSoundMaster(string sound, double volume)
  2708. {
  2709. m_host.AddScriptLPS(1);
  2710. if (m_SoundModule == null)
  2711. return;
  2712. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2713. if(soundID == UUID.Zero)
  2714. return;
  2715. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, true, false);
  2716. }
  2717. public void llLoopSoundSlave(string sound, double volume)
  2718. {
  2719. m_host.AddScriptLPS(1);
  2720. if (m_SoundModule == null)
  2721. return;
  2722. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2723. if(soundID == UUID.Zero)
  2724. return;
  2725. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false, true);
  2726. }
  2727. public void llPlaySoundSlave(string sound, double volume)
  2728. {
  2729. m_host.AddScriptLPS(1);
  2730. if (m_SoundModule == null)
  2731. return;
  2732. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2733. if(soundID == UUID.Zero)
  2734. return;
  2735. // send the sound, once, to all clients in range
  2736. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, true, false);
  2737. }
  2738. public void llTriggerSound(string sound, double volume)
  2739. {
  2740. m_host.AddScriptLPS(1);
  2741. if (m_SoundModule == null)
  2742. return;
  2743. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2744. if(soundID == UUID.Zero)
  2745. return;
  2746. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2747. m_SoundModule.SendSound(m_host.UUID, soundID, volume, true, 0, false, false);
  2748. }
  2749. public void llStopSound()
  2750. {
  2751. m_host.AddScriptLPS(1);
  2752. if (m_SoundModule != null)
  2753. m_SoundModule.StopSound(m_host.UUID);
  2754. }
  2755. public void llPreloadSound(string sound)
  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. m_SoundModule.PreloadSound(m_host.UUID, soundID);
  2764. ScriptSleep(m_sleepMsOnPreloadSound);
  2765. }
  2766. /// <summary>
  2767. /// Return a portion of the designated string bounded by
  2768. /// inclusive indices (start and end). As usual, the negative
  2769. /// indices, and the tolerance for out-of-bound values, makes
  2770. /// this more complicated than it might otherwise seem.
  2771. /// </summary>
  2772. public LSL_String llGetSubString(string src, int start, int end)
  2773. {
  2774. m_host.AddScriptLPS(1);
  2775. // Normalize indices (if negative).
  2776. // After normlaization they may still be
  2777. // negative, but that is now relative to
  2778. // the start, rather than the end, of the
  2779. // sequence.
  2780. if (start < 0)
  2781. {
  2782. start = src.Length+start;
  2783. }
  2784. if (end < 0)
  2785. {
  2786. end = src.Length+end;
  2787. }
  2788. // Conventional substring
  2789. if (start <= end)
  2790. {
  2791. // Implies both bounds are out-of-range.
  2792. if (end < 0 || start >= src.Length)
  2793. {
  2794. return String.Empty;
  2795. }
  2796. // If end is positive, then it directly
  2797. // corresponds to the lengt of the substring
  2798. // needed (plus one of course). BUT, it
  2799. // must be within bounds.
  2800. if (end >= src.Length)
  2801. {
  2802. end = src.Length-1;
  2803. }
  2804. if (start < 0)
  2805. {
  2806. return src.Substring(0,end+1);
  2807. }
  2808. // Both indices are positive
  2809. return src.Substring(start, (end+1) - start);
  2810. }
  2811. // Inverted substring (end < start)
  2812. else
  2813. {
  2814. // Implies both indices are below the
  2815. // lower bound. In the inverted case, that
  2816. // means the entire string will be returned
  2817. // unchanged.
  2818. if (start < 0)
  2819. {
  2820. return src;
  2821. }
  2822. // If both indices are greater than the upper
  2823. // bound the result may seem initially counter
  2824. // intuitive.
  2825. if (end >= src.Length)
  2826. {
  2827. return src;
  2828. }
  2829. if (end < 0)
  2830. {
  2831. if (start < src.Length)
  2832. {
  2833. return src.Substring(start);
  2834. }
  2835. else
  2836. {
  2837. return String.Empty;
  2838. }
  2839. }
  2840. else
  2841. {
  2842. if (start < src.Length)
  2843. {
  2844. return src.Substring(0,end+1) + src.Substring(start);
  2845. }
  2846. else
  2847. {
  2848. return src.Substring(0,end+1);
  2849. }
  2850. }
  2851. }
  2852. }
  2853. /// <summary>
  2854. /// Delete substring removes the specified substring bounded
  2855. /// by the inclusive indices start and end. Indices may be
  2856. /// negative (indicating end-relative) and may be inverted,
  2857. /// i.e. end < start.
  2858. /// </summary>
  2859. public LSL_String llDeleteSubString(string src, int start, int end)
  2860. {
  2861. m_host.AddScriptLPS(1);
  2862. // Normalize indices (if negative).
  2863. // After normlaization they may still be
  2864. // negative, but that is now relative to
  2865. // the start, rather than the end, of the
  2866. // sequence.
  2867. if (start < 0)
  2868. {
  2869. start = src.Length+start;
  2870. }
  2871. if (end < 0)
  2872. {
  2873. end = src.Length+end;
  2874. }
  2875. // Conventionally delimited substring
  2876. if (start <= end)
  2877. {
  2878. // If both bounds are outside of the existing
  2879. // string, then return unchanges.
  2880. if (end < 0 || start >= src.Length)
  2881. {
  2882. return src;
  2883. }
  2884. // At least one bound is in-range, so we
  2885. // need to clip the out-of-bound argument.
  2886. if (start < 0)
  2887. {
  2888. start = 0;
  2889. }
  2890. if (end >= src.Length)
  2891. {
  2892. end = src.Length-1;
  2893. }
  2894. return src.Remove(start,end-start+1);
  2895. }
  2896. // Inverted substring
  2897. else
  2898. {
  2899. // In this case, out of bounds means that
  2900. // the existing string is part of the cut.
  2901. if (start < 0 || end >= src.Length)
  2902. {
  2903. return String.Empty;
  2904. }
  2905. if (end > 0)
  2906. {
  2907. if (start < src.Length)
  2908. {
  2909. return src.Remove(start).Remove(0,end+1);
  2910. }
  2911. else
  2912. {
  2913. return src.Remove(0,end+1);
  2914. }
  2915. }
  2916. else
  2917. {
  2918. if (start < src.Length)
  2919. {
  2920. return src.Remove(start);
  2921. }
  2922. else
  2923. {
  2924. return src;
  2925. }
  2926. }
  2927. }
  2928. }
  2929. /// <summary>
  2930. /// Insert string inserts the specified string identified by src
  2931. /// at the index indicated by index. Index may be negative, in
  2932. /// which case it is end-relative. The index may exceed either
  2933. /// string bound, with the result being a concatenation.
  2934. /// </summary>
  2935. public LSL_String llInsertString(string dest, int index, string src)
  2936. {
  2937. m_host.AddScriptLPS(1);
  2938. // Normalize indices (if negative).
  2939. // After normalization they may still be
  2940. // negative, but that is now relative to
  2941. // the start, rather than the end, of the
  2942. // sequence.
  2943. if (index < 0)
  2944. {
  2945. index = dest.Length+index;
  2946. // Negative now means it is less than the lower
  2947. // bound of the string.
  2948. if (index < 0)
  2949. {
  2950. return src+dest;
  2951. }
  2952. }
  2953. if (index >= dest.Length)
  2954. {
  2955. return dest+src;
  2956. }
  2957. // The index is in bounds.
  2958. // In this case the index refers to the index that will
  2959. // be assigned to the first character of the inserted string.
  2960. // So unlike the other string operations, we do not add one
  2961. // to get the correct string length.
  2962. return dest.Substring(0,index)+src+dest.Substring(index);
  2963. }
  2964. public LSL_String llToUpper(string src)
  2965. {
  2966. m_host.AddScriptLPS(1);
  2967. return src.ToUpper();
  2968. }
  2969. public LSL_String llToLower(string src)
  2970. {
  2971. m_host.AddScriptLPS(1);
  2972. return src.ToLower();
  2973. }
  2974. public LSL_Integer llGiveMoney(LSL_Key destination, LSL_Integer amount)
  2975. {
  2976. m_host.AddScriptLPS(1);
  2977. if (m_item.PermsGranter == UUID.Zero)
  2978. return 0;
  2979. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  2980. {
  2981. Error("llGiveMoney", "No permissions to give money");
  2982. return 0;
  2983. }
  2984. UUID toID = new UUID();
  2985. if (!UUID.TryParse(destination, out toID))
  2986. {
  2987. Error("llGiveMoney", "Bad key in llGiveMoney");
  2988. return 0;
  2989. }
  2990. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  2991. if (money == null)
  2992. {
  2993. NotImplemented("llGiveMoney");
  2994. return 0;
  2995. }
  2996. Action<string> act = dontcare =>
  2997. {
  2998. money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID,
  2999. toID, amount,UUID.Zero, out string reason);
  3000. };
  3001. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  3002. return 0;
  3003. }
  3004. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3005. {
  3006. m_host.AddScriptLPS(1);
  3007. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  3008. ScriptSleep(m_sleepMsOnMakeExplosion);
  3009. }
  3010. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  3011. {
  3012. m_host.AddScriptLPS(1);
  3013. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  3014. ScriptSleep(m_sleepMsOnMakeFountain);
  3015. }
  3016. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3017. {
  3018. m_host.AddScriptLPS(1);
  3019. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  3020. ScriptSleep(m_sleepMsOnMakeSmoke);
  3021. }
  3022. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3023. {
  3024. m_host.AddScriptLPS(1);
  3025. Deprecated("llMakeFire", "Use llParticleSystem instead");
  3026. ScriptSleep(m_sleepMsOnMakeFire);
  3027. }
  3028. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3029. {
  3030. doObjectRez(inventory, pos, vel, rot, param, true);
  3031. }
  3032. public void doObjectRez(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param, bool atRoot)
  3033. {
  3034. m_host.AddScriptLPS(1);
  3035. if (string.IsNullOrEmpty(inventory) || Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  3036. return;
  3037. float dist = (float)llVecDist(llGetPos(), pos);
  3038. if (dist > m_ScriptDistanceFactor * 10.0f)
  3039. return;
  3040. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3041. if (item == null)
  3042. {
  3043. Error("llRez(AtRoot/Object)", "Can't find object '" + inventory + "'");
  3044. return;
  3045. }
  3046. if (item.InvType != (int)InventoryType.Object)
  3047. {
  3048. Error("llRez(AtRoot/Object)", "Can't create requested object; object is missing from database");
  3049. return;
  3050. }
  3051. Util.FireAndForget(x =>
  3052. {
  3053. Quaternion wrot = rot;
  3054. wrot.Normalize();
  3055. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, wrot, vel, param, atRoot);
  3056. // If either of these are null, then there was an unknown error.
  3057. if (new_groups == null)
  3058. return;
  3059. bool notAttachment = !m_host.ParentGroup.IsAttachment;
  3060. foreach (SceneObjectGroup group in new_groups)
  3061. {
  3062. // objects rezzed with this method are die_at_edge by default.
  3063. group.RootPart.SetDieAtEdge(true);
  3064. group.ResumeScripts();
  3065. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  3066. "object_rez", new Object[] {
  3067. new LSL_String(
  3068. group.RootPart.UUID.ToString()) },
  3069. new DetectParams[0]));
  3070. if (notAttachment)
  3071. {
  3072. float groupmass = group.GetMass();
  3073. PhysicsActor pa = group.RootPart.PhysActor;
  3074. //Recoil.
  3075. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  3076. {
  3077. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  3078. if (recoil != Vector3.Zero)
  3079. {
  3080. llApplyImpulse(recoil, 0);
  3081. }
  3082. }
  3083. }
  3084. }
  3085. }, null, "LSL_Api.doObjectRez");
  3086. //ScriptSleep((int)((groupmass * velmag) / 10));
  3087. ScriptSleep(m_sleepMsOnRezAtRoot);
  3088. }
  3089. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3090. {
  3091. doObjectRez(inventory, pos, vel, rot, param, false);
  3092. }
  3093. public void llLookAt(LSL_Vector target, double strength, double damping)
  3094. {
  3095. m_host.AddScriptLPS(1);
  3096. // Get the normalized vector to the target
  3097. LSL_Vector from = llGetPos();
  3098. // normalized direction to target
  3099. LSL_Vector dir = llVecNorm(target - from);
  3100. // use vertical to help compute left axis
  3101. // LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
  3102. // find normalized left axis parallel to horizon
  3103. // LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
  3104. LSL_Vector left = new LSL_Vector(-dir.y, dir.x, 0.0f);
  3105. left = llVecNorm(left);
  3106. // make up orthogonal to left and dir
  3107. LSL_Vector up = LSL_Vector.Cross(dir, left);
  3108. // compute rotation based on orthogonal axes
  3109. // and rotate so Z points to target with X below horizont
  3110. LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);
  3111. SceneObjectGroup sog = m_host.ParentGroup;
  3112. if(sog == null || sog.IsDeleted)
  3113. return;
  3114. if (!sog.UsesPhysics || sog.IsAttachment)
  3115. {
  3116. // Do nothing if either value is 0 (this has been checked in SL)
  3117. if (strength <= 0.0 || damping <= 0.0)
  3118. return;
  3119. llSetLocalRot(rot);
  3120. }
  3121. else
  3122. {
  3123. if (strength == 0)
  3124. {
  3125. llSetLocalRot(rot);
  3126. return;
  3127. }
  3128. sog.StartLookAt(rot, (float)strength, (float)damping);
  3129. }
  3130. }
  3131. public void llStopLookAt()
  3132. {
  3133. m_host.AddScriptLPS(1);
  3134. m_host.StopLookAt();
  3135. }
  3136. public void llSetTimerEvent(double sec)
  3137. {
  3138. if (sec != 0.0 && sec < m_MinTimerInterval)
  3139. sec = m_MinTimerInterval;
  3140. m_host.AddScriptLPS(1);
  3141. // Setting timer repeat
  3142. m_AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  3143. }
  3144. public virtual void llSleep(double sec)
  3145. {
  3146. // m_log.Info("llSleep snoozing " + sec + "s.");
  3147. m_host.AddScriptLPS(1);
  3148. Sleep((int)(sec * 1000));
  3149. }
  3150. public LSL_Float llGetMass()
  3151. {
  3152. m_host.AddScriptLPS(1);
  3153. if (m_host.ParentGroup.IsAttachment)
  3154. {
  3155. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  3156. if (attachedAvatar != null)
  3157. {
  3158. return attachedAvatar.GetMass();
  3159. }
  3160. else
  3161. {
  3162. return 0;
  3163. }
  3164. }
  3165. else
  3166. {
  3167. // new SL always returns object mass
  3168. // if (m_host.IsRoot)
  3169. // {
  3170. return m_host.ParentGroup.GetMass();
  3171. // }
  3172. // else
  3173. // {
  3174. // return m_host.GetMass();
  3175. // }
  3176. }
  3177. }
  3178. public LSL_Float llGetMassMKS()
  3179. {
  3180. return 100f * llGetMass();
  3181. }
  3182. public void llCollisionFilter(LSL_String name, LSL_Key id, LSL_Integer accept)
  3183. {
  3184. m_host.AddScriptLPS(1);
  3185. m_host.CollisionFilter.Clear();
  3186. if (!UUID.TryParse(id, out UUID objectID))
  3187. return;
  3188. if (objectID == UUID.Zero && name == "")
  3189. return;
  3190. m_host.CollisionFilter.Add(accept, objectID.ToString() + name);
  3191. }
  3192. public void llTakeControls(int controls, int accept, int pass_on)
  3193. {
  3194. if (m_item.PermsGranter != UUID.Zero)
  3195. {
  3196. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3197. if (presence != null)
  3198. {
  3199. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3200. {
  3201. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  3202. }
  3203. }
  3204. }
  3205. m_host.AddScriptLPS(1);
  3206. }
  3207. public void llReleaseControls()
  3208. {
  3209. m_host.AddScriptLPS(1);
  3210. if (m_item.PermsGranter != UUID.Zero)
  3211. {
  3212. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3213. if (presence != null)
  3214. {
  3215. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3216. {
  3217. // Unregister controls from Presence
  3218. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  3219. // Remove Take Control permission.
  3220. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3221. }
  3222. }
  3223. }
  3224. }
  3225. public void llReleaseURL(string url)
  3226. {
  3227. m_host.AddScriptLPS(1);
  3228. if (m_UrlModule != null)
  3229. m_UrlModule.ReleaseURL(url);
  3230. }
  3231. /// <summary>
  3232. /// Attach the object containing this script to the avatar that owns it.
  3233. /// </summary>
  3234. /// <param name='attachmentPoint'>
  3235. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  3236. /// </param>
  3237. /// <returns>true if the attach suceeded, false if it did not</returns>
  3238. public bool AttachToAvatar(int attachmentPoint)
  3239. {
  3240. SceneObjectGroup grp = m_host.ParentGroup;
  3241. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  3242. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3243. if (attachmentsModule != null)
  3244. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  3245. else
  3246. return false;
  3247. }
  3248. /// <summary>
  3249. /// Detach the object containing this script from the avatar it is attached to.
  3250. /// </summary>
  3251. /// <remarks>
  3252. /// Nothing happens if the object is not attached.
  3253. /// </remarks>
  3254. public void DetachFromAvatar()
  3255. {
  3256. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  3257. }
  3258. private void DetachWrapper(object o)
  3259. {
  3260. if (World.AttachmentsModule != null)
  3261. {
  3262. SceneObjectPart host = (SceneObjectPart)o;
  3263. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  3264. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  3265. }
  3266. }
  3267. public void llAttachToAvatar(LSL_Integer attachmentPoint)
  3268. {
  3269. m_host.AddScriptLPS(1);
  3270. if (m_item.PermsGranter != m_host.OwnerID)
  3271. return;
  3272. SceneObjectGroup grp = m_host.ParentGroup;
  3273. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3274. return;
  3275. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3276. AttachToAvatar(attachmentPoint);
  3277. }
  3278. public void llAttachToAvatarTemp(LSL_Integer attachmentPoint)
  3279. {
  3280. IAttachmentsModule attachmentsModule = World.RequestModuleInterface<IAttachmentsModule>();
  3281. if (attachmentsModule == null)
  3282. return;
  3283. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) == 0)
  3284. return;
  3285. SceneObjectGroup grp = m_host.ParentGroup;
  3286. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3287. return;
  3288. if (!World.TryGetScenePresence(m_item.PermsGranter, out ScenePresence target))
  3289. return;
  3290. if (target.UUID != grp.OwnerID)
  3291. {
  3292. uint effectivePerms = grp.EffectiveOwnerPerms;
  3293. if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
  3294. return;
  3295. grp.SetOwner(target.UUID, target.ControllingClient.ActiveGroupId);
  3296. if (World.Permissions.PropagatePermissions())
  3297. {
  3298. foreach (SceneObjectPart child in grp.Parts)
  3299. {
  3300. child.Inventory.ChangeInventoryOwner(target.UUID);
  3301. child.TriggerScriptChangedEvent(Changed.OWNER);
  3302. child.ApplyNextOwnerPermissions();
  3303. }
  3304. grp.InvalidateEffectivePerms();
  3305. }
  3306. grp.RootPart.ObjectSaleType = 0;
  3307. grp.RootPart.SalePrice = 10;
  3308. grp.HasGroupChanged = true;
  3309. grp.RootPart.SendPropertiesToClient(target.ControllingClient);
  3310. grp.RootPart.ScheduleFullUpdate();
  3311. }
  3312. attachmentsModule.AttachObject(target, grp, (uint)attachmentPoint, false, false, true);
  3313. }
  3314. public void llDetachFromAvatar()
  3315. {
  3316. m_host.AddScriptLPS(1);
  3317. if (m_host.ParentGroup.AttachmentPoint == 0)
  3318. return;
  3319. if (m_item.PermsGranter != m_host.OwnerID)
  3320. return;
  3321. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3322. DetachFromAvatar();
  3323. }
  3324. public void llTakeCamera(string avatar)
  3325. {
  3326. m_host.AddScriptLPS(1);
  3327. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  3328. }
  3329. public void llReleaseCamera(string avatar)
  3330. {
  3331. m_host.AddScriptLPS(1);
  3332. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  3333. }
  3334. public LSL_Key llGetOwner()
  3335. {
  3336. m_host.AddScriptLPS(1);
  3337. return m_host.OwnerID.ToString();
  3338. }
  3339. public void llInstantMessage(string user, string message)
  3340. {
  3341. m_host.AddScriptLPS(1);
  3342. if (!UUID.TryParse(user, out UUID result) || result == UUID.Zero)
  3343. {
  3344. Error("llInstantMessage","An invalid key was passed to llInstantMessage");
  3345. ScriptSleep(2000);
  3346. return;
  3347. }
  3348. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  3349. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  3350. // but I don't think we have a list of scenes available from here.
  3351. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  3352. // user is a UUID
  3353. // TODO: figure out values for client, fromSession, and imSessionID
  3354. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  3355. UUID friendTransactionID = UUID.Random();
  3356. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  3357. GridInstantMessage msg = new GridInstantMessage
  3358. {
  3359. fromAgentID = new Guid(m_host.OwnerID.ToString()), // fromAgentID.Guid;
  3360. toAgentID = new Guid(user), // toAgentID.Guid;
  3361. imSessionID = new Guid(m_host.UUID.ToString()), // This is the item we're mucking with here
  3362. timestamp = (uint)Util.UnixTimeSinceEpoch(),
  3363. fromAgentName = m_host.Name//client.FirstName + " " + client.LastName;// fromAgentName;
  3364. };
  3365. if (message != null && message.Length > 1024)
  3366. msg.message = message.Substring(0, 1024);
  3367. else
  3368. msg.message = message;
  3369. msg.dialog = (byte)19; // MessageFromObject
  3370. msg.fromGroup = false;// fromGroup;
  3371. msg.offline = (byte)0; //offline;
  3372. msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
  3373. msg.Position = new Vector3(m_host.AbsolutePosition);
  3374. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  3375. Vector3 pos = m_host.AbsolutePosition;
  3376. msg.binaryBucket
  3377. = Util.StringToBytes256(
  3378. "{0}/{1}/{2}/{3}",
  3379. World.RegionInfo.RegionName,
  3380. (int)Math.Floor(pos.X),
  3381. (int)Math.Floor(pos.Y),
  3382. (int)Math.Floor(pos.Z));
  3383. if (m_TransferModule != null)
  3384. {
  3385. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3386. }
  3387. ScriptSleep(m_sleepMsOnInstantMessage);
  3388. }
  3389. public void llEmail(string address, string subject, string message)
  3390. {
  3391. m_host.AddScriptLPS(1);
  3392. if (m_emailModule == null)
  3393. {
  3394. Error("llEmail", "Email module not configured");
  3395. return;
  3396. }
  3397. // this is a fire and forget no event is sent to script
  3398. Action<string> act = eventID =>
  3399. {
  3400. //Restrict email destination to the avatars registered email address?
  3401. //The restriction only applies if the destination address is not local.
  3402. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  3403. {
  3404. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, m_host.OwnerID);
  3405. if (account == null)
  3406. return;
  3407. if (String.IsNullOrEmpty(account.Email))
  3408. return;
  3409. address = account.Email;
  3410. }
  3411. m_emailModule.SendEmail(m_host.UUID, address, subject, message);
  3412. // no dataserver event
  3413. };
  3414. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  3415. m_item.ItemID, act);
  3416. ScriptSleep(m_sleepMsOnEmail);
  3417. }
  3418. public void llGetNextEmail(string address, string subject)
  3419. {
  3420. m_host.AddScriptLPS(1);
  3421. if (m_emailModule == null)
  3422. {
  3423. Error("llGetNextEmail", "Email module not configured");
  3424. return;
  3425. }
  3426. Email email;
  3427. email = m_emailModule.GetNextEmail(m_host.UUID, address, subject);
  3428. if (email == null)
  3429. return;
  3430. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  3431. new EventParams("email",
  3432. new Object[] {
  3433. new LSL_String(email.time),
  3434. new LSL_String(email.sender),
  3435. new LSL_String(email.subject),
  3436. new LSL_String(email.message),
  3437. new LSL_Integer(email.numLeft)},
  3438. new DetectParams[0]));
  3439. }
  3440. public void llTargetedEmail(LSL_Integer target, LSL_String subject, LSL_String message)
  3441. {
  3442. m_host.AddScriptLPS(1);
  3443. SceneObjectGroup parent = m_host.ParentGroup;
  3444. if (parent == null || parent.IsDeleted)
  3445. return;
  3446. if (m_emailModule == null)
  3447. {
  3448. Error("llTargetedEmail", "Email module not configured");
  3449. return;
  3450. }
  3451. if (subject.Length + message.Length > 4096)
  3452. {
  3453. Error("llTargetedEmail", "Message is too large");
  3454. return;
  3455. }
  3456. // this is a fire and forget no event is sent to script
  3457. Action<string> act = eventID =>
  3458. {
  3459. UserAccount account = null;
  3460. if (target == ScriptBaseClass.TARGETED_EMAIL_OBJECT_OWNER)
  3461. {
  3462. if(parent.OwnerID == parent.GroupID)
  3463. return;
  3464. account = m_userAccountService.GetUserAccount(RegionScopeID, parent.OwnerID);
  3465. }
  3466. else if (target == ScriptBaseClass.TARGETED_EMAIL_ROOT_CREATOR)
  3467. {
  3468. // non standard avoid creator spam
  3469. if(m_item.CreatorID == parent.RootPart.CreatorID)
  3470. {
  3471. account = m_userAccountService.GetUserAccount(RegionScopeID, parent.RootPart.CreatorID);
  3472. }
  3473. else
  3474. return;
  3475. }
  3476. else
  3477. return;
  3478. if (account == null)
  3479. {
  3480. return;
  3481. }
  3482. string address = account.Email;
  3483. if (String.IsNullOrEmpty(address))
  3484. {
  3485. return;
  3486. }
  3487. m_emailModule.SendEmail(m_host.UUID, address, subject, message);
  3488. };
  3489. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  3490. m_item.ItemID, act);
  3491. ScriptSleep(m_sleepMsOnEmail);
  3492. }
  3493. public LSL_Key llGetKey()
  3494. {
  3495. m_host.AddScriptLPS(1);
  3496. return m_host.UUID.ToString();
  3497. }
  3498. public LSL_Key llGenerateKey()
  3499. {
  3500. m_host.AddScriptLPS(1);
  3501. return UUID.Random().ToString();
  3502. }
  3503. public void llSetBuoyancy(double buoyancy)
  3504. {
  3505. m_host.AddScriptLPS(1);
  3506. if (!m_host.ParentGroup.IsDeleted)
  3507. {
  3508. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  3509. }
  3510. }
  3511. /// <summary>
  3512. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  3513. /// </summary>
  3514. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  3515. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  3516. /// <param name="tau">Number of seconds over which to reach target</param>
  3517. public void llSetHoverHeight(double height, int water, double tau)
  3518. {
  3519. m_host.AddScriptLPS(1);
  3520. PIDHoverType hoverType = PIDHoverType.Ground;
  3521. if (water != 0)
  3522. {
  3523. hoverType = PIDHoverType.GroundAndWater;
  3524. }
  3525. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  3526. }
  3527. public void llStopHover()
  3528. {
  3529. m_host.AddScriptLPS(1);
  3530. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3531. }
  3532. public void llMinEventDelay(double delay)
  3533. {
  3534. m_host.AddScriptLPS(1);
  3535. try
  3536. {
  3537. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3538. }
  3539. catch (NotImplementedException)
  3540. {
  3541. // Currently not implemented in DotNetEngine only XEngine
  3542. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3543. }
  3544. }
  3545. public void llSoundPreload(string sound)
  3546. {
  3547. m_host.AddScriptLPS(1);
  3548. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3549. }
  3550. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3551. {
  3552. m_host.AddScriptLPS(1);
  3553. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3554. // set the rotation of the object, copy that behavior
  3555. SceneObjectGroup sog = m_host.ParentGroup;
  3556. if(sog == null || sog.IsDeleted)
  3557. return;
  3558. if (strength == 0 || !sog.UsesPhysics || sog.IsAttachment)
  3559. {
  3560. llSetLocalRot(target);
  3561. }
  3562. else
  3563. {
  3564. sog.RotLookAt(target, (float)strength, (float)damping);
  3565. }
  3566. }
  3567. public LSL_Integer llStringLength(string str)
  3568. {
  3569. m_host.AddScriptLPS(1);
  3570. if (str.Length > 0)
  3571. {
  3572. return str.Length;
  3573. }
  3574. else
  3575. {
  3576. return 0;
  3577. }
  3578. }
  3579. public void llStartAnimation(string anim)
  3580. {
  3581. m_host.AddScriptLPS(1);
  3582. if (m_item.PermsGranter == UUID.Zero)
  3583. return;
  3584. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3585. {
  3586. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3587. if (presence != null)
  3588. {
  3589. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3590. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3591. if (animID == UUID.Zero)
  3592. presence.Animator.AddAnimation(anim, m_host.UUID);
  3593. else
  3594. presence.Animator.AddAnimation(animID, m_host.UUID);
  3595. }
  3596. }
  3597. }
  3598. public void llStopAnimation(string anim)
  3599. {
  3600. m_host.AddScriptLPS(1);
  3601. if (m_item.PermsGranter == UUID.Zero)
  3602. return;
  3603. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3604. {
  3605. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3606. if (presence != null)
  3607. {
  3608. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3609. if (animID == UUID.Zero)
  3610. presence.Animator.RemoveAnimation(anim);
  3611. else
  3612. presence.Animator.RemoveAnimation(animID, true);
  3613. }
  3614. }
  3615. }
  3616. public void llStartObjectAnimation(string anim)
  3617. {
  3618. m_host.AddScriptLPS(1);
  3619. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3620. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3621. if (animID == UUID.Zero)
  3622. animID = DefaultAvatarAnimations.GetDefaultAnimation(anim);
  3623. if (animID != UUID.Zero)
  3624. m_host.AddAnimation(animID, anim);
  3625. }
  3626. public void llStopObjectAnimation(string anim)
  3627. {
  3628. m_host.AddScriptLPS(1);
  3629. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim, AssetType.Animation);
  3630. if (animID == UUID.Zero)
  3631. animID = DefaultAvatarAnimations.GetDefaultAnimation(anim);
  3632. if (animID != UUID.Zero)
  3633. m_host.RemoveAnimation(animID);
  3634. }
  3635. public LSL_List llGetObjectAnimationNames()
  3636. {
  3637. m_host.AddScriptLPS(1);
  3638. LSL_List ret = new LSL_List();
  3639. if(m_host.AnimationsNames == null || m_host.AnimationsNames.Count == 0)
  3640. return ret;
  3641. foreach (string name in m_host.AnimationsNames.Values)
  3642. ret.Add(new LSL_String(name));
  3643. return ret;
  3644. }
  3645. public void llPointAt(LSL_Vector pos)
  3646. {
  3647. m_host.AddScriptLPS(1);
  3648. }
  3649. public void llStopPointAt()
  3650. {
  3651. m_host.AddScriptLPS(1);
  3652. }
  3653. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3654. {
  3655. m_host.AddScriptLPS(1);
  3656. TargetOmega(m_host, axis, spinrate, gain);
  3657. }
  3658. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3659. {
  3660. PhysicsActor pa = part.PhysActor;
  3661. if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d )
  3662. spinrate = 0.0d;
  3663. part.UpdateAngularVelocity(axis * spinrate);
  3664. }
  3665. public LSL_Integer llGetStartParameter()
  3666. {
  3667. m_host.AddScriptLPS(1);
  3668. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3669. }
  3670. public void llRequestPermissions(string agent, int perm)
  3671. {
  3672. if (!UUID.TryParse(agent, out UUID agentID))
  3673. return;
  3674. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3675. {
  3676. llReleaseControls();
  3677. m_item.PermsGranter = UUID.Zero;
  3678. m_item.PermsMask = 0;
  3679. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3680. "run_time_permissions", new Object[] {
  3681. new LSL_Integer(0) },
  3682. new DetectParams[0]));
  3683. return;
  3684. }
  3685. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3686. llReleaseControls();
  3687. m_host.AddScriptLPS(1);
  3688. int implicitPerms = 0;
  3689. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3690. {
  3691. // When attached, certain permissions are implicit if requested from owner
  3692. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3693. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3694. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3695. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3696. ScriptBaseClass.PERMISSION_ATTACH |
  3697. ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS;
  3698. }
  3699. else
  3700. {
  3701. if (m_host.ParentGroup.HasSittingAvatar(agentID))
  3702. {
  3703. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3704. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3705. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3706. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3707. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3708. }
  3709. else
  3710. {
  3711. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3712. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3713. }
  3714. if (World.GetExtraSetting("auto_grant_all_perms") == "true")
  3715. {
  3716. implicitPerms = perm;
  3717. }
  3718. }
  3719. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3720. {
  3721. m_host.TaskInventory.LockItemsForWrite(true);
  3722. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3723. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3724. m_host.TaskInventory.LockItemsForWrite(false);
  3725. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3726. "run_time_permissions", new Object[] {
  3727. new LSL_Integer(perm) },
  3728. new DetectParams[0]));
  3729. return;
  3730. }
  3731. ScenePresence presence = World.GetScenePresence(agentID);
  3732. if (presence != null)
  3733. {
  3734. // If permissions are being requested from an NPC and were not implicitly granted above then
  3735. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3736. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3737. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3738. {
  3739. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3740. {
  3741. lock (m_host.TaskInventory)
  3742. {
  3743. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3744. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3745. }
  3746. m_ScriptEngine.PostScriptEvent(
  3747. m_item.ItemID,
  3748. new EventParams(
  3749. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3750. }
  3751. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3752. // the question!
  3753. return;
  3754. }
  3755. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3756. if (ownerName == String.Empty)
  3757. ownerName = "(hippos)";
  3758. if (!m_waitingForScriptAnswer)
  3759. {
  3760. m_host.TaskInventory.LockItemsForWrite(true);
  3761. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3762. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3763. m_host.TaskInventory.LockItemsForWrite(false);
  3764. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3765. m_waitingForScriptAnswer=true;
  3766. }
  3767. presence.ControllingClient.SendScriptQuestion(
  3768. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3769. return;
  3770. }
  3771. // Requested agent is not in range, refuse perms
  3772. m_ScriptEngine.PostScriptEvent(
  3773. m_item.ItemID,
  3774. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3775. }
  3776. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3777. {
  3778. if (taskID != m_host.UUID)
  3779. return;
  3780. client.OnScriptAnswer -= handleScriptAnswer;
  3781. m_waitingForScriptAnswer = false;
  3782. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3783. llReleaseControls();
  3784. m_host.TaskInventory.LockItemsForWrite(true);
  3785. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3786. m_host.TaskInventory.LockItemsForWrite(false);
  3787. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3788. "run_time_permissions", new Object[] {
  3789. new LSL_Integer(answer) },
  3790. new DetectParams[0]));
  3791. }
  3792. public LSL_Key llGetPermissionsKey()
  3793. {
  3794. m_host.AddScriptLPS(1);
  3795. return m_item.PermsGranter.ToString();
  3796. }
  3797. public LSL_Integer llGetPermissions()
  3798. {
  3799. m_host.AddScriptLPS(1);
  3800. int perms = m_item.PermsMask;
  3801. if (m_automaticLinkPermission)
  3802. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3803. return perms;
  3804. }
  3805. public LSL_Integer llGetLinkNumber()
  3806. {
  3807. m_host.AddScriptLPS(1);
  3808. if (m_host.ParentGroup.PrimCount > 1)
  3809. {
  3810. return m_host.LinkNum;
  3811. }
  3812. else
  3813. {
  3814. return 0;
  3815. }
  3816. }
  3817. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3818. {
  3819. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3820. if (parts.Count > 0)
  3821. {
  3822. try
  3823. {
  3824. foreach (SceneObjectPart part in parts)
  3825. part.SetFaceColorAlpha(face, color, null);
  3826. }
  3827. finally { }
  3828. }
  3829. }
  3830. public void llCreateLink(LSL_Key target, LSL_Integer parent)
  3831. {
  3832. m_host.AddScriptLPS(1);
  3833. if (!UUID.TryParse(target, out UUID targetID))
  3834. return;
  3835. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3836. && !m_automaticLinkPermission)
  3837. {
  3838. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3839. return;
  3840. }
  3841. CreateLink(target, parent);
  3842. }
  3843. public void CreateLink(string target, int parent)
  3844. {
  3845. if (!UUID.TryParse(target, out UUID targetID))
  3846. return;
  3847. SceneObjectPart targetPart = World.GetSceneObjectPart(targetID);
  3848. if (targetPart == null)
  3849. return;
  3850. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3851. return; // Fail silently if attached
  3852. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3853. return;
  3854. SceneObjectGroup parentPrim = null, childPrim = null;
  3855. if (parent != 0)
  3856. {
  3857. parentPrim = m_host.ParentGroup;
  3858. childPrim = targetPart.ParentGroup;
  3859. }
  3860. else
  3861. {
  3862. parentPrim = targetPart.ParentGroup;
  3863. childPrim = m_host.ParentGroup;
  3864. }
  3865. // Required for linking
  3866. childPrim.RootPart.ClearUpdateSchedule();
  3867. parentPrim.LinkToGroup(childPrim, true);
  3868. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3869. parentPrim.RootPart.CreateSelected = false;
  3870. parentPrim.HasGroupChanged = true;
  3871. parentPrim.ScheduleGroupForFullUpdate();
  3872. IClientAPI client = null;
  3873. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3874. if (sp != null)
  3875. client = sp.ControllingClient;
  3876. if (client != null)
  3877. parentPrim.SendPropertiesToClient(client);
  3878. ScriptSleep(m_sleepMsOnCreateLink);
  3879. }
  3880. public void llBreakLink(int linknum)
  3881. {
  3882. m_host.AddScriptLPS(1);
  3883. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3884. && !m_automaticLinkPermission)
  3885. {
  3886. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3887. return;
  3888. }
  3889. BreakLink(linknum);
  3890. }
  3891. public void BreakLink(int linknum)
  3892. {
  3893. if (linknum < ScriptBaseClass.LINK_THIS)
  3894. return;
  3895. SceneObjectGroup parentSOG = m_host.ParentGroup;
  3896. if (parentSOG.AttachmentPoint != 0)
  3897. return; // Fail silently if attached
  3898. SceneObjectPart childPrim = null;
  3899. switch (linknum)
  3900. {
  3901. case ScriptBaseClass.LINK_ROOT:
  3902. case ScriptBaseClass.LINK_SET:
  3903. case ScriptBaseClass.LINK_ALL_OTHERS:
  3904. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3905. break;
  3906. case ScriptBaseClass.LINK_THIS: // not as spec
  3907. childPrim = m_host;
  3908. break;
  3909. default:
  3910. childPrim = parentSOG.GetLinkNumPart(linknum);
  3911. break;
  3912. }
  3913. if (linknum == ScriptBaseClass.LINK_ROOT)
  3914. {
  3915. List<ScenePresence> avs = parentSOG.GetSittingAvatars();
  3916. foreach (ScenePresence av in avs)
  3917. av.StandUp();
  3918. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentSOG.Parts);
  3919. parts.Remove(parentSOG.RootPart);
  3920. if (parts.Count > 0)
  3921. {
  3922. try
  3923. {
  3924. foreach (SceneObjectPart part in parts)
  3925. {
  3926. parentSOG.DelinkFromGroup(part.LocalId, true);
  3927. }
  3928. }
  3929. finally { }
  3930. }
  3931. parentSOG.HasGroupChanged = true;
  3932. parentSOG.ScheduleGroupForFullUpdate();
  3933. parentSOG.TriggerScriptChangedEvent(Changed.LINK);
  3934. if (parts.Count > 0)
  3935. {
  3936. SceneObjectPart newRoot = parts[0];
  3937. parts.Remove(newRoot);
  3938. try
  3939. {
  3940. foreach (SceneObjectPart part in parts)
  3941. {
  3942. part.ClearUpdateSchedule();
  3943. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3944. }
  3945. }
  3946. finally { }
  3947. newRoot.ParentGroup.HasGroupChanged = true;
  3948. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3949. }
  3950. }
  3951. else
  3952. {
  3953. if (childPrim == null)
  3954. return;
  3955. List<ScenePresence> avs = parentSOG.GetSittingAvatars();
  3956. foreach (ScenePresence av in avs)
  3957. av.StandUp();
  3958. parentSOG.DelinkFromGroup(childPrim.LocalId, true);
  3959. }
  3960. }
  3961. public void llBreakAllLinks()
  3962. {
  3963. m_host.AddScriptLPS(1);
  3964. TaskInventoryItem item = m_item;
  3965. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3966. && !m_automaticLinkPermission)
  3967. {
  3968. Error("llBreakAllLinks","Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3969. return;
  3970. }
  3971. BreakAllLinks();
  3972. }
  3973. public void BreakAllLinks()
  3974. {
  3975. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3976. if (parentPrim.AttachmentPoint != 0)
  3977. return; // Fail silently if attached
  3978. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3979. parts.Remove(parentPrim.RootPart);
  3980. foreach (SceneObjectPart part in parts)
  3981. {
  3982. parentPrim.DelinkFromGroup(part.LocalId, true);
  3983. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3984. }
  3985. parentPrim.HasGroupChanged = true;
  3986. parentPrim.ScheduleGroupForFullUpdate();
  3987. }
  3988. public LSL_Key llGetLinkKey(int linknum)
  3989. {
  3990. m_host.AddScriptLPS(1);
  3991. if(linknum < 0)
  3992. {
  3993. if (linknum == ScriptBaseClass.LINK_ROOT)
  3994. return m_host.ParentGroup.RootPart.UUID.ToString();
  3995. if (linknum == ScriptBaseClass.LINK_THIS)
  3996. return m_host.UUID.ToString();
  3997. return ScriptBaseClass.NULL_KEY;
  3998. }
  3999. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  4000. if (part != null)
  4001. {
  4002. return part.UUID.ToString();
  4003. }
  4004. else
  4005. {
  4006. if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
  4007. {
  4008. linknum -= (m_host.ParentGroup.PrimCount) + 1;
  4009. List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
  4010. if (avatars.Count > linknum)
  4011. {
  4012. return avatars[linknum].UUID.ToString();
  4013. }
  4014. }
  4015. return ScriptBaseClass.NULL_KEY;
  4016. }
  4017. }
  4018. /// <summary>
  4019. /// Returns the name of the child prim or seated avatar matching the
  4020. /// specified link number.
  4021. /// </summary>
  4022. /// <param name="linknum">
  4023. /// The number of a link in the linkset or a link-related constant.
  4024. /// </param>
  4025. /// <returns>
  4026. /// The name determined to match the specified link number.
  4027. /// </returns>
  4028. /// <remarks>
  4029. /// The rules governing the returned name are not simple. The only
  4030. /// time a blank name is returned is if the target prim has a blank
  4031. /// name. If no prim with the given link number can be found then
  4032. /// usually NULL_KEY is returned but there are exceptions.
  4033. ///
  4034. /// In a single unlinked prim, A call with 0 returns the name, all
  4035. /// other values for link number return NULL_KEY
  4036. ///
  4037. /// In link sets it is more complicated.
  4038. ///
  4039. /// If the script is in the root prim:-
  4040. /// A zero link number returns NULL_KEY.
  4041. /// Positive link numbers return the name of the prim, or NULL_KEY
  4042. /// if a prim does not exist at that position.
  4043. /// Negative link numbers return the name of the first child prim.
  4044. ///
  4045. /// If the script is in a child prim:-
  4046. /// Link numbers 0 or 1 return the name of the root prim.
  4047. /// Positive link numbers return the name of the prim or NULL_KEY
  4048. /// if a prim does not exist at that position.
  4049. /// Negative numbers return the name of the root prim.
  4050. ///
  4051. /// References
  4052. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  4053. /// Mentions NULL_KEY being returned
  4054. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  4055. /// Mentions using the LINK_* constants, some of which are negative
  4056. /// </remarks>
  4057. public LSL_String llGetLinkName(int linknum)
  4058. {
  4059. m_host.AddScriptLPS(1);
  4060. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  4061. if (entity != null)
  4062. return entity.Name;
  4063. else
  4064. return ScriptBaseClass.NULL_KEY;
  4065. }
  4066. public LSL_Integer llGetInventoryNumber(int type)
  4067. {
  4068. m_host.AddScriptLPS(1);
  4069. int count = 0;
  4070. m_host.TaskInventory.LockItemsForRead(true);
  4071. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4072. {
  4073. if (inv.Value.Type == type || type == -1)
  4074. {
  4075. count = count + 1;
  4076. }
  4077. }
  4078. m_host.TaskInventory.LockItemsForRead(false);
  4079. return count;
  4080. }
  4081. public LSL_String llGetInventoryName(int type, int number)
  4082. {
  4083. m_host.AddScriptLPS(1);
  4084. ArrayList keys = new ArrayList();
  4085. m_host.TaskInventory.LockItemsForRead(true);
  4086. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4087. {
  4088. if (inv.Value.Type == type || type == -1)
  4089. {
  4090. keys.Add(inv.Value.Name);
  4091. }
  4092. }
  4093. m_host.TaskInventory.LockItemsForRead(false);
  4094. if (keys.Count == 0)
  4095. {
  4096. return String.Empty;
  4097. }
  4098. keys.Sort();
  4099. if (keys.Count > number)
  4100. {
  4101. return (string)keys[number];
  4102. }
  4103. return String.Empty;
  4104. }
  4105. public LSL_Float llGetEnergy()
  4106. {
  4107. m_host.AddScriptLPS(1);
  4108. // TODO: figure out real energy value
  4109. return 1.0f;
  4110. }
  4111. public void llGiveInventory(LSL_Key destination, LSL_String inventory)
  4112. {
  4113. m_host.AddScriptLPS(1);
  4114. UUID destId = UUID.Zero;
  4115. if (!UUID.TryParse(destination, out destId))
  4116. {
  4117. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  4118. return;
  4119. }
  4120. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  4121. if (item == null)
  4122. {
  4123. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  4124. return;
  4125. }
  4126. UUID objId = item.ItemID;
  4127. // check if destination is an object
  4128. if (World.GetSceneObjectPart(destId) != null)
  4129. {
  4130. // destination is an object
  4131. World.MoveTaskInventoryItem(destId, m_host, objId);
  4132. }
  4133. else
  4134. {
  4135. ScenePresence presence = World.GetScenePresence(destId);
  4136. if (presence == null)
  4137. {
  4138. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, destId);
  4139. if (account == null)
  4140. {
  4141. GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
  4142. if(info == null || info.Online == false)
  4143. {
  4144. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  4145. return;
  4146. }
  4147. }
  4148. }
  4149. // destination is an avatar
  4150. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out string message);
  4151. if (agentItem == null)
  4152. {
  4153. llSay(0, message);
  4154. return;
  4155. }
  4156. byte[] bucket = new byte[1];
  4157. bucket[0] = (byte)item.Type;
  4158. GridInstantMessage msg = new GridInstantMessage(World,
  4159. m_host.OwnerID, m_host.Name, destId,
  4160. (byte)InstantMessageDialog.TaskInventoryOffered,
  4161. m_host.OwnerID == m_host.GroupID, "'"+item.Name+"'. ("+m_host.Name+" is located at "+
  4162. World.RegionInfo.RegionName+" "+ m_host.AbsolutePosition.ToString() + ")",
  4163. agentItem.ID, true, m_host.AbsolutePosition,
  4164. bucket, true);
  4165. if (World.TryGetScenePresence(destId, out ScenePresence sp))
  4166. {
  4167. sp.ControllingClient.SendInstantMessage(msg);
  4168. }
  4169. else
  4170. {
  4171. if (m_TransferModule != null)
  4172. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  4173. }
  4174. //This delay should only occur when giving inventory to avatars.
  4175. ScriptSleep(m_sleepMsOnGiveInventory);
  4176. }
  4177. }
  4178. [DebuggerNonUserCode]
  4179. public void llRemoveInventory(string name)
  4180. {
  4181. m_host.AddScriptLPS(1);
  4182. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4183. if (item == null)
  4184. return;
  4185. if (item.ItemID == m_item.ItemID)
  4186. throw new ScriptDeleteException();
  4187. else
  4188. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  4189. }
  4190. public void llSetText(string text, LSL_Vector color, double alpha)
  4191. {
  4192. m_host.AddScriptLPS(1);
  4193. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  4194. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  4195. }
  4196. public LSL_Float llWater(LSL_Vector offset)
  4197. {
  4198. m_host.AddScriptLPS(1);
  4199. return World.RegionInfo.RegionSettings.WaterHeight;
  4200. }
  4201. public void llPassTouches(int pass)
  4202. {
  4203. m_host.AddScriptLPS(1);
  4204. if (pass != 0)
  4205. m_host.PassTouches = true;
  4206. else
  4207. m_host.PassTouches = false;
  4208. }
  4209. public LSL_Key llRequestAgentData(string id, int data)
  4210. {
  4211. m_host.AddScriptLPS(1);
  4212. if (UUID.TryParse(id, out UUID uuid) && uuid != UUID.Zero)
  4213. {
  4214. if (uuid == UUID.Zero)
  4215. return string.Empty;
  4216. //pre process fast local avatars
  4217. switch(data)
  4218. {
  4219. case ScriptBaseClass.DATA_ONLINE:
  4220. World.TryGetScenePresence(uuid, out ScenePresence sp);
  4221. if (sp != null)
  4222. {
  4223. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  4224. m_item.ItemID, "1");
  4225. ScriptSleep(m_sleepMsOnRequestAgentData);
  4226. return ftid;
  4227. }
  4228. break;
  4229. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4230. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4231. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4232. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4233. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4234. break;
  4235. default:
  4236. return string.Empty; // Raise no event
  4237. }
  4238. Action<string> act = eventID =>
  4239. {
  4240. UserAccount account = null;
  4241. string reply;
  4242. if (data == ScriptBaseClass.DATA_ONLINE)
  4243. {
  4244. World.TryGetScenePresence(uuid, out ScenePresence sp);
  4245. if(sp != null)
  4246. reply = "1";
  4247. else
  4248. {
  4249. account = m_userAccountService.GetUserAccount(RegionScopeID, uuid);
  4250. if (account == null)
  4251. reply = "0";
  4252. else
  4253. {
  4254. PresenceInfo pinfo = null;
  4255. if (!m_PresenceInfoCache.TryGetValue(uuid, out pinfo))
  4256. {
  4257. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4258. if (pinfos != null && pinfos.Length > 0)
  4259. {
  4260. foreach (PresenceInfo p in pinfos)
  4261. {
  4262. if (p.RegionID != UUID.Zero)
  4263. {
  4264. pinfo = p;
  4265. }
  4266. }
  4267. }
  4268. }
  4269. m_PresenceInfoCache.AddOrUpdate(uuid, pinfo, m_llRequestAgentDataCacheTimeout);
  4270. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  4271. reply = "1";
  4272. else
  4273. reply = "0";
  4274. }
  4275. }
  4276. }
  4277. else
  4278. {
  4279. if (account == null)
  4280. account = m_userAccountService.GetUserAccount(RegionScopeID, uuid);
  4281. if (account == null)
  4282. reply = "0";
  4283. else
  4284. switch (data)
  4285. {
  4286. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4287. reply = account.FirstName + " " + account.LastName;
  4288. break;
  4289. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4290. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  4291. born = born.AddSeconds(account.Created);
  4292. reply = born.ToString("yyyy-MM-dd");
  4293. break;
  4294. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4295. reply = "0,0,0,0,0,0";
  4296. break;
  4297. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4298. reply = account.UserLevel.ToString();
  4299. break;
  4300. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4301. reply = "0";
  4302. break;
  4303. default:
  4304. reply = "0"; // Raise no event
  4305. break;
  4306. }
  4307. }
  4308. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  4309. };
  4310. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  4311. m_item.ItemID, act);
  4312. ScriptSleep(m_sleepMsOnRequestAgentData);
  4313. return tid.ToString();
  4314. }
  4315. else
  4316. {
  4317. Error("llRequestAgentData","Invalid UUID passed to llRequestAgentData.");
  4318. }
  4319. return "";
  4320. }
  4321. //bad if lm is HG
  4322. public LSL_Key llRequestInventoryData(LSL_String name)
  4323. {
  4324. m_host.AddScriptLPS(1);
  4325. Action<string> act = eventID =>
  4326. {
  4327. string reply = String.Empty;
  4328. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  4329. {
  4330. if (item.Type == 3 && item.Name == name)
  4331. {
  4332. AssetBase a = World.AssetService.Get(item.AssetID.ToString());
  4333. if(a != null)
  4334. {
  4335. AssetLandmark lm = new AssetLandmark(a);
  4336. if(lm != null)
  4337. {
  4338. float rx = (uint)(lm.RegionHandle >> 32);
  4339. float ry = (uint)lm.RegionHandle;
  4340. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4341. region = lm.Position + new Vector3(rx, ry, 0) - region;
  4342. reply = region.ToString();
  4343. }
  4344. }
  4345. break;
  4346. }
  4347. }
  4348. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  4349. };
  4350. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  4351. m_item.ItemID, act);
  4352. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4353. return tid.ToString();
  4354. }
  4355. public void llSetDamage(double damage)
  4356. {
  4357. m_host.AddScriptLPS(1);
  4358. m_host.ParentGroup.Damage = (float)damage;
  4359. }
  4360. public void llTeleportAgentHome(string agent)
  4361. {
  4362. m_host.AddScriptLPS(1);
  4363. UUID agentId = new UUID();
  4364. if (UUID.TryParse(agent, out agentId))
  4365. {
  4366. ScenePresence presence = World.GetScenePresence(agentId);
  4367. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4368. {
  4369. // agent must not be a god
  4370. if (presence.GodController.UserLevel >= 200) return;
  4371. // agent must be over the owners land
  4372. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  4373. {
  4374. if (!World.TeleportClientHome(agentId, presence.ControllingClient))
  4375. {
  4376. // They can't be teleported home for some reason
  4377. GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
  4378. if (regionInfo != null)
  4379. {
  4380. World.RequestTeleportLocation(
  4381. presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
  4382. (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
  4383. }
  4384. }
  4385. }
  4386. }
  4387. }
  4388. ScriptSleep(m_sleepMsOnSetDamage);
  4389. }
  4390. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4391. {
  4392. m_host.AddScriptLPS(1);
  4393. UUID agentId = new UUID();
  4394. if (UUID.TryParse(agent, out agentId))
  4395. {
  4396. ScenePresence presence = World.GetScenePresence(agentId);
  4397. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4398. {
  4399. if (destination == String.Empty)
  4400. destination = World.RegionInfo.RegionName;
  4401. if (m_item.PermsGranter == agentId)
  4402. {
  4403. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4404. {
  4405. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4406. }
  4407. }
  4408. // agent must be wearing the object
  4409. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  4410. {
  4411. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4412. }
  4413. else
  4414. {
  4415. // agent must not be a god
  4416. if (presence.IsViewerUIGod) return;
  4417. // agent must be over the owners land
  4418. ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  4419. ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  4420. if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
  4421. {
  4422. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4423. }
  4424. }
  4425. }
  4426. }
  4427. }
  4428. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4429. {
  4430. m_host.AddScriptLPS(1);
  4431. UUID agentId = new UUID();
  4432. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  4433. if (UUID.TryParse(agent, out agentId))
  4434. {
  4435. // This function is owner only!
  4436. if (m_host.OwnerID != agentId)
  4437. return;
  4438. ScenePresence presence = World.GetScenePresence(agentId);
  4439. if (presence == null || presence.PresenceType == PresenceType.Npc)
  4440. return;
  4441. // Can't TP sitting avatars
  4442. if (presence.ParentID != 0) // Sitting
  4443. return;
  4444. if (m_item.PermsGranter == agentId)
  4445. {
  4446. // If attached using llAttachToAvatarTemp, cowardly refuse
  4447. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
  4448. return;
  4449. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4450. {
  4451. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4452. }
  4453. }
  4454. }
  4455. }
  4456. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  4457. {
  4458. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  4459. // The destinaion is not an asset ID and also doesn't name a landmark.
  4460. // Use it as a sim name
  4461. if (assetID == UUID.Zero)
  4462. {
  4463. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4464. return;
  4465. }
  4466. AssetBase lma = World.AssetService.Get(assetID.ToString());
  4467. if (lma == null)
  4468. return;
  4469. if (lma.Type != (sbyte)AssetType.Landmark)
  4470. return;
  4471. AssetLandmark lm = new AssetLandmark(lma);
  4472. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4473. }
  4474. public void llTextBox(string agent, string message, int chatChannel)
  4475. {
  4476. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  4477. if (dm == null)
  4478. return;
  4479. m_host.AddScriptLPS(1);
  4480. UUID av = new UUID();
  4481. if (!UUID.TryParse(agent,out av))
  4482. {
  4483. Error("llTextBox", "First parameter must be a key");
  4484. return;
  4485. }
  4486. if (message == string.Empty)
  4487. {
  4488. Error("llTextBox", "Empty message");
  4489. }
  4490. else if (Encoding.UTF8.GetByteCount(message) > 512)
  4491. {
  4492. Error("llTextBox", "Message longer than 512 bytes");
  4493. }
  4494. else
  4495. {
  4496. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  4497. ScriptSleep(m_sleepMsOnTextBox);
  4498. }
  4499. }
  4500. public void llModifyLand(int action, int brush)
  4501. {
  4502. m_host.AddScriptLPS(1);
  4503. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  4504. if (tm != null)
  4505. {
  4506. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action);
  4507. }
  4508. }
  4509. public void llCollisionSound(LSL_String impact_sound, LSL_Float impact_volume)
  4510. {
  4511. m_host.AddScriptLPS(1);
  4512. if(impact_sound == "")
  4513. {
  4514. m_host.CollisionSoundVolume = (float)impact_volume;
  4515. m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
  4516. m_host.CollisionSoundType = -1; // disable all sounds
  4517. m_host.aggregateScriptEvents();
  4518. return;
  4519. }
  4520. // TODO: Parameter check logic required.
  4521. UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  4522. if(soundId != UUID.Zero)
  4523. {
  4524. m_host.CollisionSound = soundId;
  4525. m_host.CollisionSoundVolume = (float)impact_volume;
  4526. m_host.CollisionSoundType = 1;
  4527. }
  4528. else
  4529. m_host.CollisionSoundType = -1;
  4530. m_host.aggregateScriptEvents();
  4531. }
  4532. public LSL_String llGetAnimation(LSL_Key id)
  4533. {
  4534. // This should only return a value if the avatar is in the same region
  4535. m_host.AddScriptLPS(1);
  4536. if(!UUID.TryParse(id, out UUID avatar))
  4537. return "";
  4538. ScenePresence presence = World.GetScenePresence(avatar);
  4539. if (presence == null)
  4540. return "";
  4541. if (m_host.RegionHandle == presence.RegionHandle)
  4542. {
  4543. if (presence != null)
  4544. {
  4545. // if (presence.SitGround)
  4546. // return "Sitting on Ground";
  4547. // if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
  4548. // return "Sitting";
  4549. string movementAnimation = presence.Animator.CurrentMovementAnimation;
  4550. if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out string lslMovementAnimation))
  4551. return lslMovementAnimation;
  4552. }
  4553. }
  4554. return String.Empty;
  4555. }
  4556. public void llMessageLinked(int linknumber, int num, string msg, string id)
  4557. {
  4558. m_host.AddScriptLPS(1);
  4559. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4560. UUID partItemID;
  4561. foreach (SceneObjectPart part in parts)
  4562. {
  4563. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  4564. {
  4565. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  4566. {
  4567. partItemID = item.ItemID;
  4568. int linkNumber = m_host.LinkNum;
  4569. if (m_host.ParentGroup.PrimCount == 1)
  4570. linkNumber = 0;
  4571. object[] resobj = new object[]
  4572. {
  4573. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  4574. };
  4575. m_ScriptEngine.PostScriptEvent(partItemID,
  4576. new EventParams("link_message",
  4577. resobj, new DetectParams[0]));
  4578. }
  4579. }
  4580. }
  4581. }
  4582. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  4583. {
  4584. m_host.AddScriptLPS(1);
  4585. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  4586. bool pushAllowed = false;
  4587. bool pusheeIsAvatar = false;
  4588. UUID targetID = UUID.Zero;
  4589. if (!UUID.TryParse(target,out targetID))
  4590. return;
  4591. ScenePresence pusheeav = null;
  4592. Vector3 PusheePos = Vector3.Zero;
  4593. SceneObjectPart pusheeob = null;
  4594. ScenePresence avatar = World.GetScenePresence(targetID);
  4595. if (avatar != null)
  4596. {
  4597. pusheeIsAvatar = true;
  4598. // Pushee doesn't have a physics actor
  4599. if (avatar.PhysicsActor == null)
  4600. return;
  4601. // Pushee is in GodMode this pushing object isn't owned by them
  4602. if (avatar.IsViewerUIGod && m_host.OwnerID != targetID)
  4603. return;
  4604. pusheeav = avatar;
  4605. // Find pushee position
  4606. // Pushee Linked?
  4607. SceneObjectPart sitPart = pusheeav.ParentPart;
  4608. if (sitPart != null)
  4609. PusheePos = sitPart.AbsolutePosition;
  4610. else
  4611. PusheePos = pusheeav.AbsolutePosition;
  4612. }
  4613. if (!pusheeIsAvatar)
  4614. {
  4615. // not an avatar so push is not affected by parcel flags
  4616. pusheeob = World.GetSceneObjectPart((UUID)target);
  4617. // We can't find object
  4618. if (pusheeob == null)
  4619. return;
  4620. // Object not pushable. Not an attachment and has no physics component
  4621. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  4622. return;
  4623. PusheePos = pusheeob.AbsolutePosition;
  4624. pushAllowed = true;
  4625. }
  4626. else
  4627. {
  4628. if (pushrestricted)
  4629. {
  4630. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4631. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  4632. if (targetlandObj == null)
  4633. return;
  4634. // Need provisions for Group Owned here
  4635. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4636. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  4637. {
  4638. pushAllowed = true;
  4639. }
  4640. }
  4641. else
  4642. {
  4643. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4644. if (targetlandObj == null)
  4645. {
  4646. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4647. pushAllowed = true;
  4648. }
  4649. else
  4650. {
  4651. // Parcel push restriction
  4652. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4653. {
  4654. // Need provisions for Group Owned here
  4655. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4656. targetlandObj.LandData.IsGroupOwned ||
  4657. m_host.OwnerID == targetID)
  4658. {
  4659. pushAllowed = true;
  4660. }
  4661. //ParcelFlags.RestrictPushObject
  4662. //pushAllowed = true;
  4663. }
  4664. else
  4665. {
  4666. // Parcel isn't push restricted
  4667. pushAllowed = true;
  4668. }
  4669. }
  4670. }
  4671. }
  4672. if (pushAllowed)
  4673. {
  4674. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4675. float distance_term = distance * distance * distance; // Script Energy
  4676. // use total object mass and not part
  4677. float pusher_mass = m_host.ParentGroup.GetMass();
  4678. float PUSH_ATTENUATION_DISTANCE = 17f;
  4679. float PUSH_ATTENUATION_SCALE = 5f;
  4680. float distance_attenuation = 1f;
  4681. if (distance > PUSH_ATTENUATION_DISTANCE)
  4682. {
  4683. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4684. distance_attenuation = 1f / normalized_units;
  4685. }
  4686. Vector3 applied_linear_impulse = impulse;
  4687. {
  4688. float impulse_length = applied_linear_impulse.Length();
  4689. float desired_energy = impulse_length * pusher_mass;
  4690. if (desired_energy > 0f)
  4691. desired_energy += distance_term;
  4692. float scaling_factor = 1f;
  4693. scaling_factor *= distance_attenuation;
  4694. applied_linear_impulse *= scaling_factor;
  4695. }
  4696. if (pusheeIsAvatar)
  4697. {
  4698. if (pusheeav != null)
  4699. {
  4700. PhysicsActor pa = pusheeav.PhysicsActor;
  4701. if (pa != null)
  4702. {
  4703. if (local != 0)
  4704. {
  4705. // applied_linear_impulse *= m_host.GetWorldRotation();
  4706. applied_linear_impulse *= pusheeav.GetWorldRotation();
  4707. }
  4708. pa.AddForce(applied_linear_impulse, true);
  4709. }
  4710. }
  4711. }
  4712. else
  4713. {
  4714. if (pusheeob != null)
  4715. {
  4716. if (pusheeob.PhysActor != null)
  4717. {
  4718. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4719. }
  4720. }
  4721. }
  4722. }
  4723. }
  4724. public void llPassCollisions(int pass)
  4725. {
  4726. m_host.AddScriptLPS(1);
  4727. if (pass == 1)
  4728. {
  4729. m_host.PassCollisions = true;
  4730. }
  4731. else
  4732. {
  4733. m_host.PassCollisions = false;
  4734. }
  4735. }
  4736. public LSL_String llGetScriptName()
  4737. {
  4738. m_host.AddScriptLPS(1);
  4739. return m_item.Name ?? String.Empty;
  4740. }
  4741. public LSL_Integer llGetLinkNumberOfSides(int link)
  4742. {
  4743. m_host.AddScriptLPS(1);
  4744. SceneObjectPart linkedPart;
  4745. if (link == ScriptBaseClass.LINK_ROOT)
  4746. linkedPart = m_host.ParentGroup.RootPart;
  4747. else if (link == ScriptBaseClass.LINK_THIS)
  4748. linkedPart = m_host;
  4749. else
  4750. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4751. return GetNumberOfSides(linkedPart);
  4752. }
  4753. public LSL_Integer llGetNumberOfSides()
  4754. {
  4755. m_host.AddScriptLPS(1);
  4756. return m_host.GetNumberOfSides();
  4757. }
  4758. protected int GetNumberOfSides(SceneObjectPart part)
  4759. {
  4760. return part.GetNumberOfSides();
  4761. }
  4762. /* The new / changed functions were tested with the following LSL script:
  4763. default
  4764. {
  4765. state_entry()
  4766. {
  4767. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4768. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4769. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4770. // convert back and forth between quaternion <-> vector and angle
  4771. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4772. llOwnerSay("Old rotation was: "+(string) rot);
  4773. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4774. llSetRot(rot); // to check the parameters in the prim
  4775. }
  4776. }
  4777. */
  4778. // Xantor 29/apr/2008
  4779. // Returns rotation described by rotating angle radians about axis.
  4780. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4781. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4782. {
  4783. m_host.AddScriptLPS(1);
  4784. double x, y, z, s, t;
  4785. s = Math.Cos(angle * 0.5);
  4786. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4787. axis = LSL_Vector.Norm(axis);
  4788. x = axis.x * t;
  4789. y = axis.y * t;
  4790. z = axis.z * t;
  4791. return new LSL_Rotation(x,y,z,s);
  4792. }
  4793. /// <summary>
  4794. /// Returns the axis of rotation for a quaternion
  4795. /// </summary>
  4796. /// <returns></returns>
  4797. /// <param name='rot'></param>
  4798. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4799. {
  4800. m_host.AddScriptLPS(1);
  4801. rot.Normalize();
  4802. double s = Math.Sqrt(1 - rot.s * rot.s);
  4803. if (s < 1e-8)
  4804. return new LSL_Vector(0, 0, 0);
  4805. double invS = 1.0 / s;
  4806. if (rot.s < 0)
  4807. invS = -invS;
  4808. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4809. }
  4810. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4811. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4812. {
  4813. m_host.AddScriptLPS(1);
  4814. rot.Normalize();
  4815. double angle = 2 * Math.Acos(rot.s);
  4816. if (angle > Math.PI)
  4817. angle = 2 * Math.PI - angle;
  4818. return angle;
  4819. }
  4820. public LSL_Float llAcos(LSL_Float val)
  4821. {
  4822. m_host.AddScriptLPS(1);
  4823. return (double)Math.Acos(val);
  4824. }
  4825. public LSL_Float llAsin(LSL_Float val)
  4826. {
  4827. m_host.AddScriptLPS(1);
  4828. return (double)Math.Asin(val);
  4829. }
  4830. // jcochran 5/jan/2012
  4831. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4832. {
  4833. m_host.AddScriptLPS(1);
  4834. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4835. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4836. double aa_bb = aa * bb;
  4837. if (aa_bb == 0) return 0.0;
  4838. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4839. double quotient = (ab * ab) / aa_bb;
  4840. if (quotient >= 1.0) return 0.0;
  4841. return Math.Acos(2 * quotient - 1);
  4842. }
  4843. public LSL_Key llGetInventoryKey(string name)
  4844. {
  4845. m_host.AddScriptLPS(1);
  4846. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4847. if (item == null)
  4848. return ScriptBaseClass.NULL_KEY;
  4849. if ((item.CurrentPermissions
  4850. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4851. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4852. {
  4853. return item.AssetID.ToString();
  4854. }
  4855. return ScriptBaseClass.NULL_KEY;
  4856. }
  4857. public void llAllowInventoryDrop(LSL_Integer add)
  4858. {
  4859. m_host.AddScriptLPS(1);
  4860. if (add != 0)
  4861. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4862. else
  4863. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4864. // Update the object flags
  4865. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4866. }
  4867. public LSL_Vector llGetTextureOffset(int face)
  4868. {
  4869. m_host.AddScriptLPS(1);
  4870. return GetTextureOffset(m_host, face);
  4871. }
  4872. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4873. {
  4874. Primitive.TextureEntry tex = part.Shape.Textures;
  4875. LSL_Vector offset = new LSL_Vector();
  4876. if (face == ScriptBaseClass.ALL_SIDES)
  4877. {
  4878. face = 0;
  4879. }
  4880. if (face >= 0 && face < GetNumberOfSides(part))
  4881. {
  4882. offset.x = tex.GetFace((uint)face).OffsetU;
  4883. offset.y = tex.GetFace((uint)face).OffsetV;
  4884. offset.z = 0.0;
  4885. return offset;
  4886. }
  4887. else
  4888. {
  4889. return offset;
  4890. }
  4891. }
  4892. public LSL_Vector llGetTextureScale(int side)
  4893. {
  4894. m_host.AddScriptLPS(1);
  4895. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4896. LSL_Vector scale;
  4897. if (side == -1)
  4898. {
  4899. side = 0;
  4900. }
  4901. scale.x = tex.GetFace((uint)side).RepeatU;
  4902. scale.y = tex.GetFace((uint)side).RepeatV;
  4903. scale.z = 0.0;
  4904. return scale;
  4905. }
  4906. public LSL_Float llGetTextureRot(int face)
  4907. {
  4908. m_host.AddScriptLPS(1);
  4909. return GetTextureRot(m_host, face);
  4910. }
  4911. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4912. {
  4913. Primitive.TextureEntry tex = part.Shape.Textures;
  4914. if (face == -1)
  4915. {
  4916. face = 0;
  4917. }
  4918. if (face >= 0 && face < GetNumberOfSides(part))
  4919. {
  4920. return tex.GetFace((uint)face).Rotation;
  4921. }
  4922. else
  4923. {
  4924. return 0.0;
  4925. }
  4926. }
  4927. public LSL_Integer llSubStringIndex(string source, string pattern)
  4928. {
  4929. m_host.AddScriptLPS(1);
  4930. if (string.IsNullOrEmpty(source))
  4931. return -1;
  4932. if (string.IsNullOrEmpty(pattern))
  4933. return 0;
  4934. return source.IndexOf(pattern);
  4935. }
  4936. public LSL_Key llGetOwnerKey(string id)
  4937. {
  4938. m_host.AddScriptLPS(1);
  4939. UUID key = new UUID();
  4940. if (UUID.TryParse(id, out key))
  4941. {
  4942. try
  4943. {
  4944. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4945. if (obj == null)
  4946. return id; // the key is for an agent so just return the key
  4947. else
  4948. return obj.OwnerID.ToString();
  4949. }
  4950. catch (KeyNotFoundException)
  4951. {
  4952. return id; // The Object/Agent not in the region so just return the key
  4953. }
  4954. }
  4955. else
  4956. {
  4957. return ScriptBaseClass.NULL_KEY;
  4958. }
  4959. }
  4960. public LSL_Vector llGetCenterOfMass()
  4961. {
  4962. m_host.AddScriptLPS(1);
  4963. return new LSL_Vector(m_host.GetCenterOfMass());
  4964. }
  4965. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4966. {
  4967. m_host.AddScriptLPS(1);
  4968. if (stride <= 0)
  4969. {
  4970. stride = 1;
  4971. }
  4972. return src.Sort(stride, ascending);
  4973. }
  4974. public LSL_Integer llGetListLength(LSL_List src)
  4975. {
  4976. m_host.AddScriptLPS(1);
  4977. return src.Length;
  4978. }
  4979. public LSL_Integer llList2Integer(LSL_List src, int index)
  4980. {
  4981. m_host.AddScriptLPS(1);
  4982. if (index < 0)
  4983. index = src.Length + index;
  4984. if (index >= src.Length || index < 0)
  4985. return 0;
  4986. object item = src.Data[index];
  4987. // Vectors & Rotations always return zero in SL, but
  4988. // keys don't always return zero, it seems to be a bit complex.
  4989. if (item is LSL_Vector || item is LSL_Rotation)
  4990. return 0;
  4991. try
  4992. {
  4993. if (item is LSL_Integer)
  4994. return (LSL_Integer)item;
  4995. else if (item is LSL_Float)
  4996. return Convert.ToInt32(((LSL_Float)item).value);;
  4997. return new LSL_Integer(item.ToString());
  4998. }
  4999. catch (FormatException)
  5000. {
  5001. return 0;
  5002. }
  5003. }
  5004. public LSL_Float llList2Float(LSL_List src, int index)
  5005. {
  5006. m_host.AddScriptLPS(1);
  5007. if (index < 0)
  5008. index = src.Length + index;
  5009. if (index >= src.Length || index < 0)
  5010. return 0;
  5011. object item = src.Data[index];
  5012. // Vectors & Rotations always return zero in SL
  5013. if(item is LSL_Vector || item is LSL_Rotation)
  5014. return 0;
  5015. // valid keys seem to get parsed as integers then converted to floats
  5016. if (item is LSL_Key)
  5017. {
  5018. string s = item.ToString();
  5019. if(UUID.TryParse(s, out UUID uuidt))
  5020. return Convert.ToDouble(new LSL_Integer(s).value);
  5021. // we can't do this because a string is also a LSL_Key for now :(
  5022. // else
  5023. // return 0;
  5024. }
  5025. try
  5026. {
  5027. if (item is LSL_Integer)
  5028. return Convert.ToDouble(((LSL_Integer)item).value);
  5029. else if (item is LSL_Float)
  5030. return Convert.ToDouble(((LSL_Float)item).value);
  5031. else if (item is LSL_String)
  5032. {
  5033. string str = ((LSL_String)item).m_string;
  5034. Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
  5035. if (m != Match.Empty)
  5036. {
  5037. str = m.Value;
  5038. if (!Double.TryParse(str, out double d))
  5039. return 0.0;
  5040. return d;
  5041. }
  5042. return 0.0;
  5043. }
  5044. return Convert.ToDouble(item);
  5045. }
  5046. catch (FormatException)
  5047. {
  5048. return 0.0;
  5049. }
  5050. }
  5051. public LSL_String llList2String(LSL_List src, int index)
  5052. {
  5053. m_host.AddScriptLPS(1);
  5054. if (index < 0)
  5055. index = src.Length + index;
  5056. if (index >= src.Length || index < 0)
  5057. return String.Empty;
  5058. return src.Data[index].ToString();
  5059. }
  5060. public LSL_Key llList2Key(LSL_List src, int index)
  5061. {
  5062. m_host.AddScriptLPS(1);
  5063. if (index < 0)
  5064. index = src.Length + index;
  5065. if (index >= src.Length || index < 0)
  5066. return String.Empty;
  5067. object item = src.Data[index];
  5068. // SL spits out an empty string for types other than key & string
  5069. // At the time of patching, LSL_Key is currently LSL_String,
  5070. // so the OR check may be a little redundant, but it's being done
  5071. // for completion and should LSL_Key ever be implemented
  5072. // as it's own struct
  5073. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  5074. // type 'obj' and wrongly returns ""
  5075. if (!(item is LSL_String ||
  5076. item is LSL_Key ||
  5077. item.ToString() == "00000000-0000-0000-0000-000000000000"))
  5078. {
  5079. return String.Empty;
  5080. }
  5081. return item.ToString();
  5082. }
  5083. public LSL_Vector llList2Vector(LSL_List src, int index)
  5084. {
  5085. m_host.AddScriptLPS(1);
  5086. if (index < 0)
  5087. index = src.Length + index;
  5088. if (index >= src.Length || index < 0)
  5089. return new LSL_Vector(0, 0, 0);
  5090. object item = src.Data[index];
  5091. if (item.GetType() == typeof(LSL_Vector))
  5092. return (LSL_Vector)item;
  5093. // SL spits always out ZERO_VECTOR for anything other than
  5094. // strings or vectors. Although keys always return ZERO_VECTOR,
  5095. // it is currently difficult to make the distinction between
  5096. // a string, a key as string and a string that by coincidence
  5097. // is a string, so we're going to leave that up to the
  5098. // LSL_Vector constructor.
  5099. if(item is LSL_Vector)
  5100. return (LSL_Vector) item;
  5101. if (item is LSL_String || item is string) // xengine sees string
  5102. return new LSL_Vector(item.ToString());
  5103. return new LSL_Vector(0, 0, 0);
  5104. }
  5105. public LSL_Rotation llList2Rot(LSL_List src, int index)
  5106. {
  5107. m_host.AddScriptLPS(1);
  5108. if (index < 0)
  5109. index = src.Length + index;
  5110. if (index >= src.Length || index < 0)
  5111. return new LSL_Rotation(0, 0, 0, 1);
  5112. object item = src.Data[index];
  5113. // SL spits always out ZERO_ROTATION for anything other than
  5114. // strings or vectors. Although keys always return ZERO_ROTATION,
  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_Rotation constructor.
  5119. if (item.GetType() == typeof(LSL_Rotation))
  5120. return (LSL_Rotation)item;
  5121. if (item is LSL_String || item is string) // xengine sees string)
  5122. return new LSL_Rotation(src.Data[index].ToString());
  5123. return new LSL_Rotation(0, 0, 0, 1);
  5124. }
  5125. public LSL_List llList2List(LSL_List src, int start, int end)
  5126. {
  5127. m_host.AddScriptLPS(1);
  5128. return src.GetSublist(start, end);
  5129. }
  5130. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  5131. {
  5132. return src.DeleteSublist(start, end);
  5133. }
  5134. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  5135. {
  5136. m_host.AddScriptLPS(1);
  5137. if (index < 0)
  5138. {
  5139. index = src.Length + index;
  5140. }
  5141. if (index >= src.Length)
  5142. {
  5143. return 0;
  5144. }
  5145. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  5146. return 1;
  5147. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  5148. return 2;
  5149. if (src.Data[index] is LSL_String || src.Data[index] is String)
  5150. {
  5151. if (UUID.TryParse(src.Data[index].ToString(), out UUID tuuid))
  5152. {
  5153. return 4;
  5154. }
  5155. else
  5156. {
  5157. return 3;
  5158. }
  5159. }
  5160. if (src.Data[index] is LSL_Vector)
  5161. return 5;
  5162. if (src.Data[index] is LSL_Rotation)
  5163. return 6;
  5164. if (src.Data[index] is LSL_List)
  5165. return 7;
  5166. return 0;
  5167. }
  5168. /// <summary>
  5169. /// Process the supplied list and return the
  5170. /// content of the list formatted as a comma
  5171. /// separated list. There is a space after
  5172. /// each comma.
  5173. /// </summary>
  5174. public LSL_String llList2CSV(LSL_List src)
  5175. {
  5176. m_host.AddScriptLPS(1);
  5177. return string.Join(", ",
  5178. (new List<object>(src.Data)).ConvertAll<string>(o =>
  5179. {
  5180. return o.ToString();
  5181. }).ToArray());
  5182. }
  5183. /// <summary>
  5184. /// The supplied string is scanned for commas
  5185. /// and converted into a list. Commas are only
  5186. /// effective if they are encountered outside
  5187. /// of '<' '>' delimiters. Any whitespace
  5188. /// before or after an element is trimmed.
  5189. /// </summary>
  5190. public LSL_List llCSV2List(string src)
  5191. {
  5192. LSL_List result = new LSL_List();
  5193. int parens = 0;
  5194. int start = 0;
  5195. int length = 0;
  5196. m_host.AddScriptLPS(1);
  5197. for (int i = 0; i < src.Length; i++)
  5198. {
  5199. switch (src[i])
  5200. {
  5201. case '<':
  5202. parens++;
  5203. length++;
  5204. break;
  5205. case '>':
  5206. if (parens > 0)
  5207. parens--;
  5208. length++;
  5209. break;
  5210. case ',':
  5211. if (parens == 0)
  5212. {
  5213. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5214. start += length+1;
  5215. length = 0;
  5216. }
  5217. else
  5218. {
  5219. length++;
  5220. }
  5221. break;
  5222. default:
  5223. length++;
  5224. break;
  5225. }
  5226. }
  5227. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5228. return result;
  5229. }
  5230. /// <summary>
  5231. /// Randomizes the list, be arbitrarily reordering
  5232. /// sublists of stride elements. As the stride approaches
  5233. /// the size of the list, the options become very
  5234. /// limited.
  5235. /// </summary>
  5236. /// <remarks>
  5237. /// This could take a while for very large list
  5238. /// sizes.
  5239. /// </remarks>
  5240. public LSL_List llListRandomize(LSL_List src, int stride)
  5241. {
  5242. LSL_List result;
  5243. BetterRandom rand = new BetterRandom();
  5244. int chunkk;
  5245. int[] chunks;
  5246. m_host.AddScriptLPS(1);
  5247. if (stride <= 0)
  5248. {
  5249. stride = 1;
  5250. }
  5251. // Stride MUST be a factor of the list length
  5252. // If not, then return the src list. This also
  5253. // traps those cases where stride > length.
  5254. if (src.Length != stride && src.Length % stride == 0)
  5255. {
  5256. chunkk = src.Length/stride;
  5257. chunks = new int[chunkk];
  5258. for (int i = 0; i < chunkk; i++)
  5259. {
  5260. chunks[i] = i;
  5261. }
  5262. // Knuth shuffle the chunkk index
  5263. for (int i = chunkk - 1; i > 0; i--)
  5264. {
  5265. // Elect an unrandomized chunk to swap
  5266. int index = rand.Next(i + 1);
  5267. // and swap position with first unrandomized chunk
  5268. int tmp = chunks[i];
  5269. chunks[i] = chunks[index];
  5270. chunks[index] = tmp;
  5271. }
  5272. // Construct the randomized list
  5273. result = new LSL_List();
  5274. for (int i = 0; i < chunkk; i++)
  5275. {
  5276. for (int j = 0; j < stride; j++)
  5277. {
  5278. result.Add(src.Data[chunks[i] * stride + j]);
  5279. }
  5280. }
  5281. }
  5282. else
  5283. {
  5284. object[] array = new object[src.Length];
  5285. Array.Copy(src.Data, 0, array, 0, src.Length);
  5286. result = new LSL_List(array);
  5287. }
  5288. return result;
  5289. }
  5290. /// <summary>
  5291. /// Elements in the source list starting with 0 and then
  5292. /// every i+stride. If the stride is negative then the scan
  5293. /// is backwards producing an inverted result.
  5294. /// Only those elements that are also in the specified
  5295. /// range are included in the result.
  5296. /// </summary>
  5297. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  5298. {
  5299. LSL_List result = new LSL_List();
  5300. int[] si = new int[2];
  5301. int[] ei = new int[2];
  5302. bool twopass = false;
  5303. m_host.AddScriptLPS(1);
  5304. // First step is always to deal with negative indices
  5305. if (start < 0)
  5306. start = src.Length+start;
  5307. if (end < 0)
  5308. end = src.Length+end;
  5309. // Out of bounds indices are OK, just trim them
  5310. // accordingly
  5311. if (start > src.Length)
  5312. start = src.Length;
  5313. if (end > src.Length)
  5314. end = src.Length;
  5315. if (stride == 0)
  5316. stride = 1;
  5317. // There may be one or two ranges to be considered
  5318. if (start != end)
  5319. {
  5320. if (start <= end)
  5321. {
  5322. si[0] = start;
  5323. ei[0] = end;
  5324. }
  5325. else
  5326. {
  5327. si[1] = start;
  5328. ei[1] = src.Length;
  5329. si[0] = 0;
  5330. ei[0] = end;
  5331. twopass = true;
  5332. }
  5333. // The scan always starts from the beginning of the
  5334. // source list, but members are only selected if they
  5335. // fall within the specified sub-range. The specified
  5336. // range values are inclusive.
  5337. // A negative stride reverses the direction of the
  5338. // scan producing an inverted list as a result.
  5339. if (stride > 0)
  5340. {
  5341. for (int i = 0; i < src.Length; i += stride)
  5342. {
  5343. if (i<=ei[0] && i>=si[0])
  5344. result.Add(src.Data[i]);
  5345. if (twopass && i>=si[1] && i<=ei[1])
  5346. result.Add(src.Data[i]);
  5347. }
  5348. }
  5349. else if (stride < 0)
  5350. {
  5351. for (int i = src.Length - 1; i >= 0; i += stride)
  5352. {
  5353. if (i <= ei[0] && i >= si[0])
  5354. result.Add(src.Data[i]);
  5355. if (twopass && i >= si[1] && i <= ei[1])
  5356. result.Add(src.Data[i]);
  5357. }
  5358. }
  5359. }
  5360. else
  5361. {
  5362. if (start%stride == 0)
  5363. {
  5364. result.Add(src.Data[start]);
  5365. }
  5366. }
  5367. return result;
  5368. }
  5369. public LSL_Integer llGetRegionAgentCount()
  5370. {
  5371. m_host.AddScriptLPS(1);
  5372. int count = 0;
  5373. World.ForEachRootScenePresence(delegate(ScenePresence sp) {
  5374. count++;
  5375. });
  5376. return new LSL_Integer(count);
  5377. }
  5378. public LSL_Vector llGetRegionCorner()
  5379. {
  5380. m_host.AddScriptLPS(1);
  5381. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  5382. }
  5383. public LSL_String llGetEnv(LSL_String name)
  5384. {
  5385. m_host.AddScriptLPS(1);
  5386. switch(name)
  5387. {
  5388. case "agent_limit":
  5389. return World.RegionInfo.RegionSettings.AgentLimit.ToString();
  5390. case "dynamic_pathfinding":
  5391. return "0";
  5392. case "estate_id":
  5393. return World.RegionInfo.EstateSettings.EstateID.ToString();
  5394. case "estate_name":
  5395. return World.RegionInfo.EstateSettings.EstateName;
  5396. case "frame_number":
  5397. return World.Frame.ToString();
  5398. case "region_cpu_ratio":
  5399. return "1";
  5400. case "region_idle":
  5401. return "0";
  5402. case "region_product_name":
  5403. if (World.RegionInfo.RegionType != String.Empty)
  5404. return World.RegionInfo.RegionType;
  5405. else
  5406. return "";
  5407. case "region_product_sku":
  5408. return "OpenSim";
  5409. case "region_start_time":
  5410. return World.UnixStartTime.ToString();
  5411. case "region_up_time":
  5412. int time = Util.UnixTimeSinceEpoch() - World.UnixStartTime;
  5413. return time.ToString();
  5414. case "sim_channel":
  5415. return "OpenSim";
  5416. case "sim_version":
  5417. return World.GetSimulatorVersion();
  5418. case "simulator_hostname":
  5419. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  5420. return UrlModule.ExternalHostNameForLSL;
  5421. case "region_max_prims":
  5422. return World.RegionInfo.ObjectCapacity.ToString();
  5423. case "region_object_bonus":
  5424. return World.RegionInfo.RegionSettings.ObjectBonus.ToString();
  5425. default:
  5426. return "";
  5427. }
  5428. }
  5429. /// <summary>
  5430. /// Insert the list identified by <paramref name="src"/> into the
  5431. /// list designated by <paramref name="dest"/> such that the first
  5432. /// new element has the index specified by <paramref name="index"/>
  5433. /// </summary>
  5434. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  5435. {
  5436. LSL_List pref;
  5437. LSL_List suff;
  5438. m_host.AddScriptLPS(1);
  5439. if (index < 0)
  5440. {
  5441. index = index+dest.Length;
  5442. if (index < 0)
  5443. {
  5444. index = 0;
  5445. }
  5446. }
  5447. if (index != 0)
  5448. {
  5449. pref = dest.GetSublist(0,index-1);
  5450. if (index < dest.Length)
  5451. {
  5452. suff = dest.GetSublist(index,-1);
  5453. return pref + src + suff;
  5454. }
  5455. else
  5456. {
  5457. return pref + src;
  5458. }
  5459. }
  5460. else
  5461. {
  5462. if (index < dest.Length)
  5463. {
  5464. suff = dest.GetSublist(index,-1);
  5465. return src + suff;
  5466. }
  5467. else
  5468. {
  5469. return src;
  5470. }
  5471. }
  5472. }
  5473. /// <summary>
  5474. /// Returns the index of the first occurrence of test
  5475. /// in src.
  5476. /// </summary>
  5477. /// <param name="src">Source list</param>
  5478. /// <param name="test">List to search for</param>
  5479. /// <returns>
  5480. /// The index number of the point in src where test was found if it was found.
  5481. /// Otherwise returns -1
  5482. /// </returns>
  5483. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  5484. {
  5485. int index = -1;
  5486. int length = src.Length - test.Length + 1;
  5487. m_host.AddScriptLPS(1);
  5488. // If either list is empty, do not match
  5489. if (src.Length != 0 && test.Length != 0)
  5490. {
  5491. for (int i = 0; i < length; i++)
  5492. {
  5493. int needle = llGetListEntryType(test, 0).value;
  5494. int haystack = llGetListEntryType(src, i).value;
  5495. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  5496. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  5497. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  5498. // Therefore, here we test Equals on both the source and destination objects.
  5499. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  5500. if ((needle == haystack) && (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])))
  5501. {
  5502. int j;
  5503. for (j = 1; j < test.Length; j++)
  5504. {
  5505. needle = llGetListEntryType(test, j).value;
  5506. haystack = llGetListEntryType(src, i+j).value;
  5507. if ((needle != haystack) || (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))))
  5508. break;
  5509. }
  5510. if (j == test.Length)
  5511. {
  5512. index = i;
  5513. break;
  5514. }
  5515. }
  5516. }
  5517. }
  5518. return index;
  5519. }
  5520. public LSL_String llGetObjectName()
  5521. {
  5522. m_host.AddScriptLPS(1);
  5523. return m_host.Name ?? string.Empty;
  5524. }
  5525. public void llSetObjectName(string name)
  5526. {
  5527. m_host.AddScriptLPS(1);
  5528. m_host.Name = name ?? String.Empty;
  5529. }
  5530. public LSL_String llGetDate()
  5531. {
  5532. m_host.AddScriptLPS(1);
  5533. DateTime date = DateTime.Now.ToUniversalTime();
  5534. string result = date.ToString("yyyy-MM-dd");
  5535. return result;
  5536. }
  5537. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  5538. {
  5539. m_host.AddScriptLPS(1);
  5540. if(dir.x == 0 && dir.y == 0)
  5541. return 1; // SL wiki
  5542. float rsx = World.RegionInfo.RegionSizeX;
  5543. float rsy = World.RegionInfo.RegionSizeY;
  5544. // can understand what sl does if position is not in region, so do something :)
  5545. float px = (float)Util.Clamp(pos.x, 0.5, rsx - 0.5);
  5546. float py = (float)Util.Clamp(pos.y, 0.5, rsy - 0.5);
  5547. float ex, ey;
  5548. if (dir.x == 0)
  5549. {
  5550. ex = px;
  5551. ey = dir.y > 0 ? rsy + 1.0f : -1.0f;
  5552. }
  5553. else if(dir.y == 0)
  5554. {
  5555. ex = dir.x > 0 ? rsx + 1.0f : -1.0f;
  5556. ey = py;
  5557. }
  5558. else
  5559. {
  5560. float dx = (float) dir.x;
  5561. float dy = (float) dir.y;
  5562. float t1 = dx * dx + dy * dy;
  5563. t1 = (float)Math.Sqrt(t1);
  5564. dx /= t1;
  5565. dy /= t1;
  5566. if(dx > 0)
  5567. t1 = (rsx + 1f - px)/dx;
  5568. else
  5569. t1 = -(px + 1f)/dx;
  5570. float t2;
  5571. if(dy > 0)
  5572. t2 = (rsy + 1f - py)/dy;
  5573. else
  5574. t2 = -(py + 1f)/dy;
  5575. if(t1 > t2)
  5576. t1 = t2;
  5577. ex = px + t1 * dx;
  5578. ey = py + t1 * dy;
  5579. }
  5580. ex += World.RegionInfo.WorldLocX;
  5581. ey += World.RegionInfo.WorldLocY;
  5582. if(World.GridService.GetRegionByPosition(RegionScopeID, (int)ex, (int)ey) != null)
  5583. return 0;
  5584. return 1;
  5585. }
  5586. /// <summary>
  5587. /// Not fully implemented yet. Still to do:-
  5588. /// AGENT_BUSY
  5589. /// Remove as they are done
  5590. /// </summary>
  5591. public LSL_Integer llGetAgentInfo(LSL_Key id)
  5592. {
  5593. m_host.AddScriptLPS(1);
  5594. UUID key = new UUID();
  5595. if (!UUID.TryParse(id, out key))
  5596. {
  5597. return 0;
  5598. }
  5599. int flags = 0;
  5600. ScenePresence agent = World.GetScenePresence(key);
  5601. if (agent == null)
  5602. {
  5603. return 0;
  5604. }
  5605. if (agent.IsChildAgent || agent.IsDeleted)
  5606. return 0; // Fail if they are not in the same region
  5607. try
  5608. {
  5609. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  5610. if (agent.SetAlwaysRun)
  5611. {
  5612. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  5613. }
  5614. if (agent.HasAttachments())
  5615. {
  5616. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  5617. if (agent.HasScriptedAttachments())
  5618. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  5619. }
  5620. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  5621. {
  5622. flags |= ScriptBaseClass.AGENT_FLYING;
  5623. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  5624. }
  5625. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  5626. {
  5627. flags |= ScriptBaseClass.AGENT_AWAY;
  5628. }
  5629. UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
  5630. UUID[] anims = agent.Animator.GetAnimationArray();
  5631. if (Array.Exists<UUID>(anims, a => { return a == busy; }))
  5632. {
  5633. flags |= ScriptBaseClass.AGENT_BUSY;
  5634. }
  5635. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  5636. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  5637. {
  5638. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  5639. }
  5640. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  5641. {
  5642. flags |= ScriptBaseClass.AGENT_TYPING;
  5643. }
  5644. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5645. if (agentMovementAnimation == "CROUCH")
  5646. {
  5647. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5648. }
  5649. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5650. {
  5651. flags |= ScriptBaseClass.AGENT_WALKING;
  5652. }
  5653. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5654. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5655. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5656. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5657. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5658. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5659. {
  5660. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5661. }
  5662. if (agent.ParentPart != null)
  5663. {
  5664. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5665. flags |= ScriptBaseClass.AGENT_SITTING;
  5666. }
  5667. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5668. == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  5669. {
  5670. flags |= ScriptBaseClass.AGENT_SITTING;
  5671. }
  5672. if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
  5673. {
  5674. flags |= ScriptBaseClass.AGENT_MALE;
  5675. }
  5676. }
  5677. catch
  5678. {
  5679. return 0;
  5680. }
  5681. return flags;
  5682. }
  5683. public LSL_String llGetAgentLanguage(LSL_Key id)
  5684. {
  5685. // This should only return a value if the avatar is in the same region, but eh. idc.
  5686. m_host.AddScriptLPS(1);
  5687. if (World.AgentPreferencesService == null)
  5688. {
  5689. Error("llGetAgentLanguage", "No AgentPreferencesService present");
  5690. }
  5691. else
  5692. {
  5693. UUID key = new UUID();
  5694. if (UUID.TryParse(id, out key))
  5695. {
  5696. return new LSL_String(World.AgentPreferencesService.GetLang(key));
  5697. }
  5698. }
  5699. return new LSL_String("en-us");
  5700. }
  5701. /// <summary>
  5702. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5703. /// The list of options is currently not used in SL
  5704. /// scope is one of:-
  5705. /// AGENT_LIST_REGION - all in the region
  5706. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5707. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5708. /// current parcel.
  5709. /// AGENT_LIST_EXCLUDENPC ignore NPCs (bit mask)
  5710. /// </summary>
  5711. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5712. {
  5713. m_host.AddScriptLPS(1);
  5714. // do our bit masks part
  5715. bool noNPC = (scope & ScriptBaseClass.AGENT_LIST_EXCLUDENPC) !=0;
  5716. // remove bit masks part
  5717. scope &= ~ ScriptBaseClass.AGENT_LIST_EXCLUDENPC;
  5718. // the constants are 1, 2 and 4 so bits are being set, but you
  5719. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5720. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5721. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5722. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5723. LSL_List result = new LSL_List();
  5724. if (!regionWide && !parcelOwned && !parcel)
  5725. {
  5726. result.Add("INVALID_SCOPE");
  5727. return result;
  5728. }
  5729. ILandObject land;
  5730. UUID id = UUID.Zero;
  5731. if (parcel || parcelOwned)
  5732. {
  5733. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5734. if (land == null)
  5735. {
  5736. id = UUID.Zero;
  5737. }
  5738. else
  5739. {
  5740. if (parcelOwned)
  5741. {
  5742. id = land.LandData.OwnerID;
  5743. }
  5744. else
  5745. {
  5746. id = land.LandData.GlobalID;
  5747. }
  5748. }
  5749. }
  5750. World.ForEachRootScenePresence(
  5751. delegate (ScenePresence ssp)
  5752. {
  5753. if(noNPC && ssp.IsNPC)
  5754. return;
  5755. // Gods are not listed in SL
  5756. if (!ssp.IsDeleted && !ssp.IsViewerUIGod && !ssp.IsChildAgent)
  5757. {
  5758. if (!regionWide)
  5759. {
  5760. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5761. if (land != null)
  5762. {
  5763. if (parcelOwned && land.LandData.OwnerID == id ||
  5764. parcel && land.LandData.GlobalID == id)
  5765. {
  5766. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5767. }
  5768. }
  5769. }
  5770. else
  5771. {
  5772. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5773. }
  5774. }
  5775. // Maximum of 100 results
  5776. if (result.Length > 99)
  5777. {
  5778. return;
  5779. }
  5780. }
  5781. );
  5782. return result;
  5783. }
  5784. public void llAdjustSoundVolume(LSL_Float volume)
  5785. {
  5786. m_host.AddScriptLPS(1);
  5787. m_host.AdjustSoundGain(volume);
  5788. ScriptSleep(m_sleepMsOnAdjustSoundVolume);
  5789. }
  5790. public void llSetSoundRadius(double radius)
  5791. {
  5792. m_host.AddScriptLPS(1);
  5793. m_host.SoundRadius = radius;
  5794. }
  5795. public LSL_String llKey2Name(LSL_Key id)
  5796. {
  5797. m_host.AddScriptLPS(1);
  5798. UUID key = new UUID();
  5799. if (UUID.TryParse(id,out key))
  5800. {
  5801. ScenePresence presence = World.GetScenePresence(key);
  5802. if (presence != null)
  5803. {
  5804. return presence.Name;
  5805. //return presence.Name;
  5806. }
  5807. if (World.GetSceneObjectPart(key) != null)
  5808. {
  5809. return World.GetSceneObjectPart(key).Name;
  5810. }
  5811. }
  5812. return String.Empty;
  5813. }
  5814. public LSL_Key llName2Key(LSL_String name)
  5815. {
  5816. m_host.AddScriptLPS(1);
  5817. if(string.IsNullOrWhiteSpace(name))
  5818. return ScriptBaseClass.NULL_KEY;
  5819. int nc = Util.ParseAvatarName(name, out string firstName, out string lastName, out string server);
  5820. if (nc < 2)
  5821. return ScriptBaseClass.NULL_KEY;
  5822. string sname;
  5823. if (nc == 2)
  5824. sname = firstName + " " + lastName;
  5825. else
  5826. sname = firstName + "." + lastName + " @" + server;
  5827. foreach (ScenePresence sp in World.GetScenePresences())
  5828. {
  5829. if (sp.IsDeleted || sp.IsChildAgent)
  5830. continue;
  5831. if (String.Compare(sname, sp.Name, true) == 0)
  5832. return sp.UUID.ToString();
  5833. }
  5834. return ScriptBaseClass.NULL_KEY;
  5835. }
  5836. public LSL_Key llRequestUserKey(LSL_String username)
  5837. {
  5838. m_host.AddScriptLPS(1);
  5839. if (string.IsNullOrWhiteSpace(username))
  5840. return ScriptBaseClass.NULL_KEY;
  5841. int nc = Util.ParseAvatarName(username, out string firstName, out string lastName, out string server);
  5842. if (nc < 2)
  5843. return ScriptBaseClass.NULL_KEY;
  5844. string sname;
  5845. if (nc == 2)
  5846. sname = firstName + " " + lastName;
  5847. else
  5848. sname = firstName + "." + lastName + " @" + server;
  5849. foreach (ScenePresence sp in World.GetScenePresences())
  5850. {
  5851. if (sp.IsDeleted || sp.IsChildAgent)
  5852. continue;
  5853. if (String.Compare(sname, sp.Name, true) == 0)
  5854. {
  5855. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  5856. m_item.ItemID, sp.UUID.ToString());
  5857. return ftid;
  5858. }
  5859. }
  5860. Action<string> act = eventID =>
  5861. {
  5862. string reply = ScriptBaseClass.NULL_KEY;
  5863. UUID userID = UUID.Zero;
  5864. IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
  5865. if (nc == 2)
  5866. {
  5867. if (userManager != null)
  5868. {
  5869. userID = userManager.GetUserIdByName(firstName, lastName);
  5870. if (userID != UUID.Zero)
  5871. reply = userID.ToString();
  5872. }
  5873. }
  5874. else
  5875. {
  5876. string url = "http://" + server;
  5877. if (Uri.TryCreate(url, UriKind.Absolute, out Uri dummy))
  5878. {
  5879. bool notfound = true;
  5880. if (userManager != null)
  5881. {
  5882. string hgfirst = firstName + "." + lastName;
  5883. string hglast = "@" + server;
  5884. userID = userManager.GetUserIdByName(hgfirst, hglast);
  5885. if (userID != UUID.Zero)
  5886. {
  5887. notfound = false;
  5888. reply = userID.ToString();
  5889. }
  5890. }
  5891. if(notfound)
  5892. {
  5893. try
  5894. {
  5895. UserAgentServiceConnector userConnection = new UserAgentServiceConnector(url);
  5896. if (userConnection != null)
  5897. {
  5898. userID = userConnection.GetUUID(firstName, lastName);
  5899. if (userID != UUID.Zero)
  5900. {
  5901. if (userManager != null)
  5902. userManager.AddUser(userID, firstName, lastName, url);
  5903. reply = userID.ToString();
  5904. }
  5905. }
  5906. }
  5907. catch
  5908. {
  5909. reply = ScriptBaseClass.NULL_KEY;
  5910. }
  5911. }
  5912. }
  5913. }
  5914. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  5915. };
  5916. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  5917. ScriptSleep(m_sleepMsOnRequestAgentData);
  5918. return tid.ToString();
  5919. }
  5920. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5921. {
  5922. m_host.AddScriptLPS(1);
  5923. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5924. }
  5925. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5926. {
  5927. m_host.AddScriptLPS(1);
  5928. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5929. try
  5930. {
  5931. foreach (SceneObjectPart part in parts)
  5932. {
  5933. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5934. }
  5935. }
  5936. finally
  5937. {
  5938. }
  5939. }
  5940. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5941. {
  5942. //ALL_SIDES
  5943. if (face == ScriptBaseClass.ALL_SIDES)
  5944. face = 255;
  5945. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation
  5946. {
  5947. Flags = (Primitive.TextureAnimMode)mode,
  5948. Face = (uint)face,
  5949. Length = (float)length,
  5950. Rate = (float)rate,
  5951. SizeX = (uint)sizex,
  5952. SizeY = (uint)sizey,
  5953. Start = (float)start
  5954. };
  5955. part.AddTextureAnimation(pTexAnim);
  5956. part.SendFullUpdateToAllClients();
  5957. part.ParentGroup.HasGroupChanged = true;
  5958. }
  5959. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5960. LSL_Vector bottom_south_west)
  5961. {
  5962. m_host.AddScriptLPS(1);
  5963. if (m_SoundModule != null)
  5964. {
  5965. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5966. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5967. bottom_south_west, top_north_east);
  5968. }
  5969. }
  5970. public void llEjectFromLand(LSL_Key pest)
  5971. {
  5972. m_host.AddScriptLPS(1);
  5973. UUID agentID = new UUID();
  5974. if (UUID.TryParse(pest, out agentID))
  5975. {
  5976. ScenePresence presence = World.GetScenePresence(agentID);
  5977. if (presence != null)
  5978. {
  5979. // agent must be over the owners land
  5980. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  5981. if (land == null)
  5982. return;
  5983. if (m_host.OwnerID == land.LandData.OwnerID)
  5984. {
  5985. Vector3 p = World.GetNearestAllowedPosition(presence, land);
  5986. presence.TeleportOnEject(p);
  5987. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  5988. }
  5989. }
  5990. }
  5991. ScriptSleep(m_sleepMsOnEjectFromLand);
  5992. }
  5993. public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
  5994. {
  5995. return ParseString2List(str, separators, in_spacers, false);
  5996. }
  5997. public LSL_Integer llOverMyLand(string id)
  5998. {
  5999. m_host.AddScriptLPS(1);
  6000. UUID key = new UUID();
  6001. if (UUID.TryParse(id, out key))
  6002. {
  6003. try
  6004. {
  6005. ScenePresence presence = World.GetScenePresence(key);
  6006. if (presence != null) // object is an avatar
  6007. {
  6008. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  6009. return 1;
  6010. }
  6011. else // object is not an avatar
  6012. {
  6013. SceneObjectPart obj = World.GetSceneObjectPart(key);
  6014. if (obj != null &&
  6015. m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  6016. return 1;
  6017. }
  6018. }
  6019. catch { }
  6020. }
  6021. return 0;
  6022. }
  6023. public LSL_Key llGetLandOwnerAt(LSL_Vector pos)
  6024. {
  6025. m_host.AddScriptLPS(1);
  6026. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  6027. if (land == null)
  6028. return ScriptBaseClass.NULL_KEY;
  6029. return land.LandData.OwnerID.ToString();
  6030. }
  6031. /// <summary>
  6032. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  6033. /// only the height of avatars vary and that says:
  6034. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  6035. /// </summary>
  6036. public LSL_Vector llGetAgentSize(LSL_Key id)
  6037. {
  6038. m_host.AddScriptLPS(1);
  6039. if(!UUID.TryParse(id, out UUID avID))
  6040. return ScriptBaseClass.ZERO_VECTOR;
  6041. ScenePresence avatar = World.GetScenePresence(avID);
  6042. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  6043. return ScriptBaseClass.ZERO_VECTOR;
  6044. // agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
  6045. Vector3 s = avatar.Appearance.AvatarSize;
  6046. return new LSL_Vector(s.X, s.Y, s.Z);
  6047. }
  6048. public LSL_Integer llSameGroup(string id)
  6049. {
  6050. m_host.AddScriptLPS(1);
  6051. UUID uuid;
  6052. if (!UUID.TryParse(id, out uuid))
  6053. return 0;
  6054. // Check if it's a group key
  6055. if (uuid == m_host.ParentGroup.RootPart.GroupID)
  6056. return 1;
  6057. // Handle object case
  6058. SceneObjectPart part = World.GetSceneObjectPart(uuid);
  6059. if (part != null)
  6060. {
  6061. if(part.ParentGroup.IsAttachment)
  6062. {
  6063. uuid = part.ParentGroup.AttachedAvatar;
  6064. }
  6065. else
  6066. {
  6067. // This will handle both deed and non-deed and also the no
  6068. // group case
  6069. if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
  6070. return 1;
  6071. return 0;
  6072. }
  6073. }
  6074. // Handle the case where id names an avatar
  6075. ScenePresence presence = World.GetScenePresence(uuid);
  6076. if (presence != null)
  6077. {
  6078. if (presence.IsChildAgent)
  6079. return 0;
  6080. IClientAPI client = presence.ControllingClient;
  6081. if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
  6082. return 1;
  6083. return 0;
  6084. }
  6085. return 0;
  6086. }
  6087. public void llUnSit(string id)
  6088. {
  6089. m_host.AddScriptLPS(1);
  6090. UUID key = new UUID();
  6091. if (UUID.TryParse(id, out key))
  6092. {
  6093. ScenePresence av = World.GetScenePresence(key);
  6094. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  6095. if (av != null)
  6096. {
  6097. if (sittingAvatars.Contains(av))
  6098. {
  6099. // if the avatar is sitting on this object, then
  6100. // we can unsit them. We don't want random scripts unsitting random people
  6101. // Lets avoid the popcorn avatar scenario.
  6102. av.StandUp();
  6103. }
  6104. else
  6105. {
  6106. // If the object owner also owns the parcel
  6107. // or
  6108. // if the land is group owned and the object is group owned by the same group
  6109. // or
  6110. // if the object is owned by a person with estate access.
  6111. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  6112. if (parcel != null)
  6113. {
  6114. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  6115. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  6116. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  6117. {
  6118. av.StandUp();
  6119. }
  6120. }
  6121. }
  6122. }
  6123. }
  6124. }
  6125. public LSL_Vector llGroundSlope(LSL_Vector offset)
  6126. {
  6127. m_host.AddScriptLPS(1);
  6128. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  6129. LSL_Vector vsn = llGroundNormal(offset);
  6130. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  6131. //the height of that point on the plane. The resulting vector gives the slope.
  6132. Vector3 vsl = vsn;
  6133. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  6134. vsl.Normalize();
  6135. //Normalization might be overkill here
  6136. vsn.x = vsl.X;
  6137. vsn.y = vsl.Y;
  6138. vsn.z = vsl.Z;
  6139. return vsn;
  6140. }
  6141. public LSL_Vector llGroundNormal(LSL_Vector offset)
  6142. {
  6143. m_host.AddScriptLPS(1);
  6144. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  6145. // Clamp to valid position
  6146. if (pos.X < 0)
  6147. pos.X = 0;
  6148. else if (pos.X >= World.Heightmap.Width)
  6149. pos.X = World.Heightmap.Width - 1;
  6150. if (pos.Y < 0)
  6151. pos.Y = 0;
  6152. else if (pos.Y >= World.Heightmap.Height)
  6153. pos.Y = World.Heightmap.Height - 1;
  6154. //Find two points in addition to the position to define a plane
  6155. Vector3 p0 = new Vector3(pos.X, pos.Y,
  6156. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6157. Vector3 p1 = new Vector3();
  6158. Vector3 p2 = new Vector3();
  6159. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  6160. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6161. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6162. else
  6163. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6164. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  6165. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  6166. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6167. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6168. else
  6169. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6170. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  6171. //Find normalized vectors from p0 to p1 and p0 to p2
  6172. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  6173. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  6174. v0.Normalize();
  6175. v1.Normalize();
  6176. //Find the cross product of the vectors (the slope normal).
  6177. Vector3 vsn = new Vector3
  6178. {
  6179. X = (v0.Y * v1.Z) - (v0.Z * v1.Y),
  6180. Y = (v0.Z * v1.X) - (v0.X * v1.Z),
  6181. Z = (v0.X * v1.Y) - (v0.Y * v1.X)
  6182. };
  6183. vsn.Normalize();
  6184. //I believe the crossproduct of two normalized vectors is a normalized vector so
  6185. //this normalization may be overkill
  6186. return new LSL_Vector(vsn);
  6187. }
  6188. public LSL_Vector llGroundContour(LSL_Vector offset)
  6189. {
  6190. m_host.AddScriptLPS(1);
  6191. LSL_Vector x = llGroundSlope(offset);
  6192. return new LSL_Vector(-x.y, x.x, 0.0);
  6193. }
  6194. public LSL_Integer llGetAttached()
  6195. {
  6196. m_host.AddScriptLPS(1);
  6197. return m_host.ParentGroup.AttachmentPoint;
  6198. }
  6199. public LSL_List llGetAttachedList(LSL_Key id)
  6200. {
  6201. m_host.AddScriptLPS(1);
  6202. if(!UUID.TryParse(id, out UUID avID))
  6203. return new LSL_List("NOT_FOUND");
  6204. ScenePresence av = World.GetScenePresence(avID);
  6205. if (av == null || av.IsDeleted)
  6206. return new LSL_List("NOT_FOUND");
  6207. if (av.IsChildAgent || av.IsInTransit)
  6208. return new LSL_List("NOT_ON_REGION");
  6209. LSL_List AttachmentsList = new LSL_List();
  6210. List<SceneObjectGroup> Attachments;
  6211. Attachments = av.GetAttachments();
  6212. foreach (SceneObjectGroup Attachment in Attachments)
  6213. {
  6214. if(Attachment.HasPrivateAttachmentPoint)
  6215. continue;
  6216. AttachmentsList.Add(new LSL_Key(Attachment.UUID.ToString()));
  6217. }
  6218. return AttachmentsList;
  6219. }
  6220. public virtual LSL_Integer llGetFreeMemory()
  6221. {
  6222. m_host.AddScriptLPS(1);
  6223. // Make scripts designed for Mono happy
  6224. return 65536;
  6225. }
  6226. public LSL_Integer llGetFreeURLs()
  6227. {
  6228. m_host.AddScriptLPS(1);
  6229. if (m_UrlModule != null)
  6230. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  6231. return new LSL_Integer(0);
  6232. }
  6233. public LSL_String llGetRegionName()
  6234. {
  6235. m_host.AddScriptLPS(1);
  6236. return World.RegionInfo.RegionName;
  6237. }
  6238. public LSL_Float llGetRegionTimeDilation()
  6239. {
  6240. m_host.AddScriptLPS(1);
  6241. return (double)World.TimeDilation;
  6242. }
  6243. /// <summary>
  6244. /// Returns the value reported in the client Statistics window
  6245. /// </summary>
  6246. public LSL_Float llGetRegionFPS()
  6247. {
  6248. m_host.AddScriptLPS(1);
  6249. return World.StatsReporter.LastReportedSimFPS;
  6250. }
  6251. /* particle system rules should be coming into this routine as doubles, that is
  6252. rule[0] should be an integer from this list and rule[1] should be the arg
  6253. for the same integer. wiki.secondlife.com has most of this mapping, but some
  6254. came from http://www.caligari-designs.com/p4u2
  6255. We iterate through the list for 'Count' elements, incrementing by two for each
  6256. iteration and set the members of Primitive.ParticleSystem, one at a time.
  6257. */
  6258. public enum PrimitiveRule : int
  6259. {
  6260. PSYS_PART_FLAGS = 0,
  6261. PSYS_PART_START_COLOR = 1,
  6262. PSYS_PART_START_ALPHA = 2,
  6263. PSYS_PART_END_COLOR = 3,
  6264. PSYS_PART_END_ALPHA = 4,
  6265. PSYS_PART_START_SCALE = 5,
  6266. PSYS_PART_END_SCALE = 6,
  6267. PSYS_PART_MAX_AGE = 7,
  6268. PSYS_SRC_ACCEL = 8,
  6269. PSYS_SRC_PATTERN = 9,
  6270. PSYS_SRC_INNERANGLE = 10,
  6271. PSYS_SRC_OUTERANGLE = 11,
  6272. PSYS_SRC_TEXTURE = 12,
  6273. PSYS_SRC_BURST_RATE = 13,
  6274. PSYS_SRC_BURST_PART_COUNT = 15,
  6275. PSYS_SRC_BURST_RADIUS = 16,
  6276. PSYS_SRC_BURST_SPEED_MIN = 17,
  6277. PSYS_SRC_BURST_SPEED_MAX = 18,
  6278. PSYS_SRC_MAX_AGE = 19,
  6279. PSYS_SRC_TARGET_KEY = 20,
  6280. PSYS_SRC_OMEGA = 21,
  6281. PSYS_SRC_ANGLE_BEGIN = 22,
  6282. PSYS_SRC_ANGLE_END = 23,
  6283. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  6284. PSYS_PART_BLEND_FUNC_DEST = 25,
  6285. PSYS_PART_START_GLOW = 26,
  6286. PSYS_PART_END_GLOW = 27
  6287. }
  6288. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  6289. {
  6290. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  6291. return returnval;
  6292. }
  6293. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  6294. {
  6295. Primitive.ParticleSystem ps = new Primitive.ParticleSystem
  6296. {
  6297. PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f),
  6298. PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f),
  6299. PartStartScaleX = 1.0f,
  6300. PartStartScaleY = 1.0f,
  6301. PartEndScaleX = 1.0f,
  6302. PartEndScaleY = 1.0f,
  6303. BurstSpeedMin = 1.0f,
  6304. BurstSpeedMax = 1.0f,
  6305. BurstRate = 0.1f,
  6306. PartMaxAge = 10.0f,
  6307. BurstPartCount = 1,
  6308. BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA,
  6309. BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA,
  6310. PartStartGlow = 0.0f,
  6311. PartEndGlow = 0.0f
  6312. };
  6313. return ps;
  6314. }
  6315. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  6316. {
  6317. m_host.AddScriptLPS(1);
  6318. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6319. foreach (SceneObjectPart part in parts)
  6320. {
  6321. SetParticleSystem(part, rules, "llLinkParticleSystem");
  6322. }
  6323. }
  6324. public void llParticleSystem(LSL_List rules)
  6325. {
  6326. m_host.AddScriptLPS(1);
  6327. SetParticleSystem(m_host, rules, "llParticleSystem");
  6328. }
  6329. private void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc)
  6330. {
  6331. if (rules.Length == 0)
  6332. {
  6333. part.RemoveParticleSystem();
  6334. part.ParentGroup.HasGroupChanged = true;
  6335. }
  6336. else
  6337. {
  6338. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  6339. LSL_Vector tempv = new LSL_Vector();
  6340. float tempf = 0;
  6341. int tmpi = 0;
  6342. for (int i = 0; i < rules.Length; i += 2)
  6343. {
  6344. int psystype;
  6345. try
  6346. {
  6347. psystype = rules.GetLSLIntegerItem(i);
  6348. }
  6349. catch (InvalidCastException)
  6350. {
  6351. Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i));
  6352. return;
  6353. }
  6354. switch (psystype)
  6355. {
  6356. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  6357. try
  6358. {
  6359. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  6360. }
  6361. catch(InvalidCastException)
  6362. {
  6363. Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1));
  6364. return;
  6365. }
  6366. break;
  6367. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  6368. try
  6369. {
  6370. tempv = rules.GetVector3Item(i + 1);
  6371. }
  6372. catch(InvalidCastException)
  6373. {
  6374. Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6375. return;
  6376. }
  6377. prules.PartStartColor.R = (float)tempv.x;
  6378. prules.PartStartColor.G = (float)tempv.y;
  6379. prules.PartStartColor.B = (float)tempv.z;
  6380. break;
  6381. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  6382. try
  6383. {
  6384. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6385. }
  6386. catch(InvalidCastException)
  6387. {
  6388. Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6389. return;
  6390. }
  6391. prules.PartStartColor.A = tempf;
  6392. break;
  6393. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  6394. try
  6395. {
  6396. tempv = rules.GetVector3Item(i + 1);
  6397. }
  6398. catch(InvalidCastException)
  6399. {
  6400. Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6401. return;
  6402. }
  6403. prules.PartEndColor.R = (float)tempv.x;
  6404. prules.PartEndColor.G = (float)tempv.y;
  6405. prules.PartEndColor.B = (float)tempv.z;
  6406. break;
  6407. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  6408. try
  6409. {
  6410. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6411. }
  6412. catch(InvalidCastException)
  6413. {
  6414. Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6415. return;
  6416. }
  6417. prules.PartEndColor.A = tempf;
  6418. break;
  6419. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  6420. try
  6421. {
  6422. tempv = rules.GetVector3Item(i + 1);
  6423. }
  6424. catch(InvalidCastException)
  6425. {
  6426. Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6427. return;
  6428. }
  6429. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  6430. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  6431. break;
  6432. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  6433. try
  6434. {
  6435. tempv = rules.GetVector3Item(i + 1);
  6436. }
  6437. catch(InvalidCastException)
  6438. {
  6439. Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6440. return;
  6441. }
  6442. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  6443. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  6444. break;
  6445. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  6446. try
  6447. {
  6448. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6449. }
  6450. catch(InvalidCastException)
  6451. {
  6452. Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6453. return;
  6454. }
  6455. prules.PartMaxAge = tempf;
  6456. break;
  6457. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  6458. try
  6459. {
  6460. tempv = rules.GetVector3Item(i + 1);
  6461. }
  6462. catch(InvalidCastException)
  6463. {
  6464. Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1));
  6465. return;
  6466. }
  6467. prules.PartAcceleration.X = (float)tempv.x;
  6468. prules.PartAcceleration.Y = (float)tempv.y;
  6469. prules.PartAcceleration.Z = (float)tempv.z;
  6470. break;
  6471. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  6472. try
  6473. {
  6474. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6475. }
  6476. catch(InvalidCastException)
  6477. {
  6478. Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1));
  6479. return;
  6480. }
  6481. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  6482. break;
  6483. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  6484. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  6485. // client tells the difference between the two by looking at the 0x02 bit in
  6486. // the PartFlags variable.
  6487. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  6488. try
  6489. {
  6490. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6491. }
  6492. catch(InvalidCastException)
  6493. {
  6494. Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6495. return;
  6496. }
  6497. prules.InnerAngle = (float)tempf;
  6498. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6499. break;
  6500. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  6501. try
  6502. {
  6503. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6504. }
  6505. catch(InvalidCastException)
  6506. {
  6507. Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6508. return;
  6509. }
  6510. prules.OuterAngle = (float)tempf;
  6511. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6512. break;
  6513. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  6514. try
  6515. {
  6516. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6517. }
  6518. catch(InvalidCastException)
  6519. {
  6520. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1));
  6521. return;
  6522. }
  6523. prules.BlendFuncSource = (byte)tmpi;
  6524. break;
  6525. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  6526. try
  6527. {
  6528. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6529. }
  6530. catch(InvalidCastException)
  6531. {
  6532. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1));
  6533. return;
  6534. }
  6535. prules.BlendFuncDest = (byte)tmpi;
  6536. break;
  6537. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  6538. try
  6539. {
  6540. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6541. }
  6542. catch(InvalidCastException)
  6543. {
  6544. Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6545. return;
  6546. }
  6547. prules.PartStartGlow = (float)tempf;
  6548. break;
  6549. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  6550. try
  6551. {
  6552. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6553. }
  6554. catch(InvalidCastException)
  6555. {
  6556. Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6557. return;
  6558. }
  6559. prules.PartEndGlow = (float)tempf;
  6560. break;
  6561. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  6562. try
  6563. {
  6564. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  6565. }
  6566. catch(InvalidCastException)
  6567. {
  6568. Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1));
  6569. return;
  6570. }
  6571. break;
  6572. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  6573. try
  6574. {
  6575. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6576. }
  6577. catch(InvalidCastException)
  6578. {
  6579. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1));
  6580. return;
  6581. }
  6582. prules.BurstRate = (float)tempf;
  6583. break;
  6584. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  6585. try
  6586. {
  6587. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  6588. }
  6589. catch(InvalidCastException)
  6590. {
  6591. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1));
  6592. return;
  6593. }
  6594. break;
  6595. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  6596. try
  6597. {
  6598. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6599. }
  6600. catch(InvalidCastException)
  6601. {
  6602. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1));
  6603. return;
  6604. }
  6605. prules.BurstRadius = (float)tempf;
  6606. break;
  6607. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  6608. try
  6609. {
  6610. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6611. }
  6612. catch(InvalidCastException)
  6613. {
  6614. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1));
  6615. return;
  6616. }
  6617. prules.BurstSpeedMin = (float)tempf;
  6618. break;
  6619. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  6620. try
  6621. {
  6622. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6623. }
  6624. catch(InvalidCastException)
  6625. {
  6626. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1));
  6627. return;
  6628. }
  6629. prules.BurstSpeedMax = (float)tempf;
  6630. break;
  6631. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  6632. try
  6633. {
  6634. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6635. }
  6636. catch(InvalidCastException)
  6637. {
  6638. Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6639. return;
  6640. }
  6641. prules.MaxAge = (float)tempf;
  6642. break;
  6643. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  6644. UUID key = UUID.Zero;
  6645. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  6646. {
  6647. prules.Target = key;
  6648. }
  6649. else
  6650. {
  6651. prules.Target = part.UUID;
  6652. }
  6653. break;
  6654. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  6655. // AL: This is an assumption, since it is the only thing that would match.
  6656. try
  6657. {
  6658. tempv = rules.GetVector3Item(i + 1);
  6659. }
  6660. catch(InvalidCastException)
  6661. {
  6662. Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1));
  6663. return;
  6664. }
  6665. prules.AngularVelocity.X = (float)tempv.x;
  6666. prules.AngularVelocity.Y = (float)tempv.y;
  6667. prules.AngularVelocity.Z = (float)tempv.z;
  6668. break;
  6669. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  6670. try
  6671. {
  6672. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6673. }
  6674. catch(InvalidCastException)
  6675. {
  6676. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1));
  6677. return;
  6678. }
  6679. prules.InnerAngle = (float)tempf;
  6680. prules.PartFlags |= 0x02; // Set new angle format.
  6681. break;
  6682. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  6683. try
  6684. {
  6685. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6686. }
  6687. catch (InvalidCastException)
  6688. {
  6689. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1));
  6690. return;
  6691. }
  6692. prules.OuterAngle = (float)tempf;
  6693. prules.PartFlags |= 0x02; // Set new angle format.
  6694. break;
  6695. }
  6696. }
  6697. prules.CRC = 1;
  6698. part.AddNewParticleSystem(prules);
  6699. part.ParentGroup.HasGroupChanged = true;
  6700. }
  6701. part.SendFullUpdateToAllClients();
  6702. }
  6703. private float validParticleScale(float value)
  6704. {
  6705. if (value > 7.96f) return 7.96f;
  6706. return value;
  6707. }
  6708. public void llGroundRepel(double height, int water, double tau)
  6709. {
  6710. m_host.AddScriptLPS(1);
  6711. if (m_host.PhysActor != null)
  6712. {
  6713. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  6714. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  6715. PIDHoverType hoverType = PIDHoverType.Ground;
  6716. if (water != 0)
  6717. {
  6718. hoverType = PIDHoverType.GroundAndWater;
  6719. if (ground < waterLevel)
  6720. height += waterLevel;
  6721. else
  6722. height += ground;
  6723. }
  6724. else
  6725. {
  6726. height += ground;
  6727. }
  6728. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  6729. }
  6730. }
  6731. public void llGiveInventoryList(LSL_Key destination, LSL_String category, LSL_List inventory)
  6732. {
  6733. m_host.AddScriptLPS(1);
  6734. if (!UUID.TryParse(destination, out UUID destID))
  6735. return;
  6736. ScenePresence sp = null;
  6737. bool isNotOwner = true;
  6738. if (!World.TryGetSceneObjectPart(destID, out SceneObjectPart destSop))
  6739. {
  6740. if (!World.TryGetScenePresence(destID, out sp))
  6741. {
  6742. // we could check if it is a grid user and allow the transfer as in older code
  6743. // but that increases security risk
  6744. Error("llGiveInventoryList", "Unable to give list, destination not found");
  6745. ScriptSleep(100);
  6746. return;
  6747. }
  6748. isNotOwner = sp.UUID != m_host.OwnerID;
  6749. }
  6750. List<UUID> itemList = new List<UUID>();
  6751. foreach (Object item in inventory.Data)
  6752. {
  6753. string rawItemString = item.ToString();
  6754. TaskInventoryItem taskItem = null;
  6755. if (UUID.TryParse(rawItemString, out UUID itemID))
  6756. taskItem = m_host.Inventory.GetInventoryItem(itemID);
  6757. else
  6758. taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  6759. if(taskItem == null)
  6760. continue;
  6761. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  6762. continue;
  6763. if (destSop != null)
  6764. {
  6765. if(!World.Permissions.CanDoObjectInvToObjectInv(taskItem, m_host, destSop))
  6766. continue;
  6767. }
  6768. else
  6769. {
  6770. if(isNotOwner)
  6771. {
  6772. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  6773. continue;
  6774. }
  6775. }
  6776. itemList.Add(taskItem.ItemID);
  6777. }
  6778. if (itemList.Count == 0)
  6779. {
  6780. Error("llGiveInventoryList", "Unable to give list, no items found");
  6781. ScriptSleep(100);
  6782. return;
  6783. }
  6784. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList, false);
  6785. if (folderID == UUID.Zero)
  6786. {
  6787. Error("llGiveInventoryList", "Unable to give list");
  6788. ScriptSleep(100);
  6789. return;
  6790. }
  6791. if (destSop != null)
  6792. return;
  6793. if (m_TransferModule != null)
  6794. {
  6795. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  6796. Vector3 pos = m_host.AbsolutePosition;
  6797. GridInstantMessage msg = new GridInstantMessage(World,
  6798. m_host.OwnerID, m_host.Name, destID,
  6799. (byte)InstantMessageDialog.TaskInventoryOffered,
  6800. m_host.OwnerID == m_host.GroupID,
  6801. string.Format("'{0}'", category),
  6802. //string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  6803. folderID, false, pos,
  6804. bucket, false);
  6805. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  6806. }
  6807. ScriptSleep(destSop == null ? 3000 : 100);
  6808. }
  6809. public void llSetVehicleType(int type)
  6810. {
  6811. m_host.AddScriptLPS(1);
  6812. if (!m_host.ParentGroup.IsDeleted)
  6813. {
  6814. m_host.ParentGroup.RootPart.SetVehicleType(type);
  6815. }
  6816. }
  6817. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6818. //CFK 9/28: so these are not complete yet.
  6819. public void llSetVehicleFloatParam(int param, LSL_Float value)
  6820. {
  6821. m_host.AddScriptLPS(1);
  6822. if (!m_host.ParentGroup.IsDeleted)
  6823. {
  6824. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  6825. }
  6826. }
  6827. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6828. //CFK 9/28: so these are not complete yet.
  6829. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  6830. {
  6831. m_host.AddScriptLPS(1);
  6832. if (!m_host.ParentGroup.IsDeleted)
  6833. {
  6834. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  6835. }
  6836. }
  6837. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6838. //CFK 9/28: so these are not complete yet.
  6839. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  6840. {
  6841. m_host.AddScriptLPS(1);
  6842. if (!m_host.ParentGroup.IsDeleted)
  6843. {
  6844. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  6845. }
  6846. }
  6847. public void llSetVehicleFlags(int flags)
  6848. {
  6849. m_host.AddScriptLPS(1);
  6850. if (!m_host.ParentGroup.IsDeleted)
  6851. {
  6852. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  6853. }
  6854. }
  6855. public void llRemoveVehicleFlags(int flags)
  6856. {
  6857. m_host.AddScriptLPS(1);
  6858. if (!m_host.ParentGroup.IsDeleted)
  6859. {
  6860. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  6861. }
  6862. }
  6863. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  6864. {
  6865. // LSL quaternions can normalize to 0, normal Quaternions can't.
  6866. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  6867. rot.s = 1; // ZERO_ROTATION = 0,0,0,1
  6868. part.SitTargetPosition = offset;
  6869. part.SitTargetOrientation = rot;
  6870. part.ParentGroup.HasGroupChanged = true;
  6871. }
  6872. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  6873. {
  6874. m_host.AddScriptLPS(1);
  6875. SitTarget(m_host, offset, rot);
  6876. }
  6877. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  6878. {
  6879. m_host.AddScriptLPS(1);
  6880. if (link == ScriptBaseClass.LINK_ROOT)
  6881. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  6882. else if (link == ScriptBaseClass.LINK_THIS)
  6883. SitTarget(m_host, offset, rot);
  6884. else
  6885. {
  6886. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  6887. if (null != part)
  6888. {
  6889. SitTarget(part, offset, rot);
  6890. }
  6891. }
  6892. }
  6893. public LSL_Key llAvatarOnSitTarget()
  6894. {
  6895. m_host.AddScriptLPS(1);
  6896. return m_host.SitTargetAvatar.ToString();
  6897. }
  6898. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  6899. public LSL_Key llAvatarOnLinkSitTarget(LSL_Integer linknum)
  6900. {
  6901. m_host.AddScriptLPS(1);
  6902. if(linknum == ScriptBaseClass.LINK_SET ||
  6903. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6904. linknum == ScriptBaseClass.LINK_ALL_OTHERS ||
  6905. linknum == 0)
  6906. return ScriptBaseClass.NULL_KEY;
  6907. List<SceneObjectPart> parts = GetLinkParts(linknum);
  6908. if (parts.Count == 0)
  6909. return ScriptBaseClass.NULL_KEY;
  6910. return parts[0].SitTargetAvatar.ToString();
  6911. }
  6912. public void llAddToLandPassList(LSL_Key avatar, LSL_Float hours)
  6913. {
  6914. m_host.AddScriptLPS(1);
  6915. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6916. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  6917. {
  6918. int expires = 0;
  6919. if (hours != 0)
  6920. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  6921. if (UUID.TryParse(avatar, out UUID key))
  6922. {
  6923. int idx = land.LandData.ParcelAccessList.FindIndex(
  6924. delegate(LandAccessEntry e)
  6925. {
  6926. if (e.AgentID == key && e.Flags == AccessList.Access)
  6927. return true;
  6928. return false;
  6929. });
  6930. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  6931. return;
  6932. if (idx != -1)
  6933. land.LandData.ParcelAccessList.RemoveAt(idx);
  6934. LandAccessEntry entry = new LandAccessEntry
  6935. {
  6936. AgentID = key,
  6937. Flags = AccessList.Access,
  6938. Expires = expires
  6939. };
  6940. land.LandData.ParcelAccessList.Add(entry);
  6941. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  6942. }
  6943. }
  6944. ScriptSleep(m_sleepMsOnAddToLandPassList);
  6945. }
  6946. public void llSetTouchText(string text)
  6947. {
  6948. m_host.AddScriptLPS(1);
  6949. if(text.Length <= 9)
  6950. m_host.TouchName = text;
  6951. else
  6952. m_host.TouchName = text.Substring(0, 9);
  6953. }
  6954. public void llSetSitText(string text)
  6955. {
  6956. m_host.AddScriptLPS(1);
  6957. if (text.Length <= 9)
  6958. m_host.SitName = text;
  6959. else
  6960. m_host.SitName = text.Substring(0, 9);
  6961. }
  6962. public void llSetCameraEyeOffset(LSL_Vector offset)
  6963. {
  6964. m_host.AddScriptLPS(1);
  6965. m_host.SetCameraEyeOffset(offset);
  6966. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  6967. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  6968. }
  6969. public void llSetCameraAtOffset(LSL_Vector offset)
  6970. {
  6971. m_host.AddScriptLPS(1);
  6972. m_host.SetCameraAtOffset(offset);
  6973. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  6974. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  6975. }
  6976. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  6977. {
  6978. m_host.AddScriptLPS(1);
  6979. if (link == ScriptBaseClass.LINK_SET ||
  6980. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6981. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  6982. SceneObjectPart part = null;
  6983. switch (link)
  6984. {
  6985. case ScriptBaseClass.LINK_ROOT:
  6986. part = m_host.ParentGroup.RootPart;
  6987. break;
  6988. case ScriptBaseClass.LINK_THIS:
  6989. part = m_host;
  6990. break;
  6991. default:
  6992. part = m_host.ParentGroup.GetLinkNumPart(link);
  6993. break;
  6994. }
  6995. if (null != part)
  6996. {
  6997. part.SetCameraEyeOffset(eye);
  6998. part.SetCameraAtOffset(at);
  6999. }
  7000. }
  7001. public LSL_String llDumpList2String(LSL_List src, string seperator)
  7002. {
  7003. m_host.AddScriptLPS(1);
  7004. if (src.Length == 0)
  7005. {
  7006. return String.Empty;
  7007. }
  7008. string ret = String.Empty;
  7009. foreach (object o in src.Data)
  7010. {
  7011. ret = ret + o.ToString() + seperator;
  7012. }
  7013. ret = ret.Substring(0, ret.Length - seperator.Length);
  7014. return ret;
  7015. }
  7016. public LSL_Integer llScriptDanger(LSL_Vector pos)
  7017. {
  7018. m_host.AddScriptLPS(1);
  7019. bool result = World.LSLScriptDanger(m_host, pos);
  7020. if (result)
  7021. {
  7022. return 1;
  7023. }
  7024. else
  7025. {
  7026. return 0;
  7027. }
  7028. }
  7029. public void llDialog(LSL_Key avatar, LSL_String message, LSL_List buttons, int chat_channel)
  7030. {
  7031. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  7032. if (dm == null)
  7033. return;
  7034. m_host.AddScriptLPS(1);
  7035. UUID av = new UUID();
  7036. if (!UUID.TryParse(avatar,out av))
  7037. {
  7038. Error("llDialog", "First parameter must be a key");
  7039. return;
  7040. }
  7041. int length = buttons.Length;
  7042. if (length < 1)
  7043. {
  7044. buttons.Add(new LSL_String("Ok"));
  7045. length = 1;
  7046. }
  7047. else if (length > 12)
  7048. {
  7049. Error("llDialog", "No more than 12 buttons can be shown");
  7050. return;
  7051. }
  7052. if (message == string.Empty)
  7053. {
  7054. Error("llDialog", "Empty message");
  7055. }
  7056. else if (Encoding.UTF8.GetByteCount(message) > 512)
  7057. {
  7058. Error("llDialog", "Message longer than 512 bytes");
  7059. }
  7060. string[] buts = new string[length];
  7061. for (int i = 0; i < length; i++)
  7062. {
  7063. if (buttons.Data[i].ToString() == String.Empty)
  7064. {
  7065. Error("llDialog", "Button label cannot be blank");
  7066. return;
  7067. }
  7068. /*
  7069. if (buttons.Data[i].ToString().Length > 24)
  7070. {
  7071. Error("llDialog", "Button label cannot be longer than 24 characters");
  7072. return;
  7073. }
  7074. */
  7075. buts[i] = buttons.Data[i].ToString();
  7076. }
  7077. dm.SendDialogToUser(
  7078. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  7079. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  7080. ScriptSleep(m_sleepMsOnDialog);
  7081. }
  7082. public void llVolumeDetect(int detect)
  7083. {
  7084. m_host.AddScriptLPS(1);
  7085. if (!m_host.ParentGroup.IsDeleted)
  7086. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  7087. }
  7088. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  7089. {
  7090. m_host.AddScriptLPS(1);
  7091. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  7092. ScriptSleep(m_sleepMsOnRemoteLoadScript);
  7093. }
  7094. public void llSetRemoteScriptAccessPin(int pin)
  7095. {
  7096. m_host.AddScriptLPS(1);
  7097. m_host.ScriptAccessPin = pin;
  7098. }
  7099. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  7100. {
  7101. m_host.AddScriptLPS(1);
  7102. UUID destId = UUID.Zero;
  7103. if (!UUID.TryParse(target, out destId))
  7104. {
  7105. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  7106. return;
  7107. }
  7108. // target must be a different prim than the one containing the script
  7109. if (m_host.UUID == destId)
  7110. {
  7111. return;
  7112. }
  7113. // copy the first script found with this inventory name
  7114. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  7115. // make sure the object is a script
  7116. if (item == null || item.Type != 10)
  7117. {
  7118. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  7119. return;
  7120. }
  7121. SceneObjectPart dest = World.GetSceneObjectPart(destId);
  7122. if (dest != null)
  7123. {
  7124. if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
  7125. {
  7126. // the rest of the permission checks are done in RezScript, so check the pin there as well
  7127. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  7128. if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
  7129. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  7130. }
  7131. }
  7132. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  7133. ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
  7134. }
  7135. public void llOpenRemoteDataChannel()
  7136. {
  7137. m_host.AddScriptLPS(1);
  7138. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7139. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  7140. {
  7141. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  7142. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7143. if (xmlRpcRouter != null)
  7144. {
  7145. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  7146. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  7147. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  7148. xmlrpcMod.Port.ToString()));
  7149. }
  7150. object[] resobj = new object[]
  7151. {
  7152. new LSL_Integer(1),
  7153. new LSL_String(channelID.ToString()),
  7154. new LSL_String(ScriptBaseClass.NULL_KEY),
  7155. new LSL_String(String.Empty),
  7156. new LSL_Integer(0),
  7157. new LSL_String(String.Empty)
  7158. };
  7159. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  7160. new DetectParams[0]));
  7161. }
  7162. ScriptSleep(m_sleepMsOnOpenRemoteDataChannel);
  7163. }
  7164. public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
  7165. {
  7166. m_host.AddScriptLPS(1);
  7167. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7168. ScriptSleep(m_sleepMsOnSendRemoteData);
  7169. if (xmlrpcMod == null)
  7170. return "";
  7171. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  7172. }
  7173. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  7174. {
  7175. m_host.AddScriptLPS(1);
  7176. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7177. if (xmlrpcMod != null)
  7178. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  7179. ScriptSleep(m_sleepMsOnRemoteDataReply);
  7180. }
  7181. public void llCloseRemoteDataChannel(string channel)
  7182. {
  7183. m_host.AddScriptLPS(1);
  7184. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7185. if (xmlRpcRouter != null)
  7186. {
  7187. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  7188. }
  7189. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7190. if (xmlrpcMod != null)
  7191. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  7192. ScriptSleep(m_sleepMsOnCloseRemoteDataChannel);
  7193. }
  7194. public LSL_String llMD5String(string src, int nonce)
  7195. {
  7196. m_host.AddScriptLPS(1);
  7197. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
  7198. }
  7199. public LSL_String llSHA1String(string src)
  7200. {
  7201. m_host.AddScriptLPS(1);
  7202. return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
  7203. }
  7204. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  7205. {
  7206. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7207. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7208. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7209. return shapeBlock;
  7210. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  7211. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  7212. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  7213. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  7214. {
  7215. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  7216. }
  7217. shapeBlock.PathCurve = pathcurve;
  7218. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  7219. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  7220. if (cut.x < 0f)
  7221. {
  7222. cut.x = 0f;
  7223. }
  7224. else if (cut.x > 1f)
  7225. {
  7226. cut.x = 1f;
  7227. }
  7228. if (cut.y < 0f)
  7229. {
  7230. cut.y = 0f;
  7231. }
  7232. else if (cut.y > 1f)
  7233. {
  7234. cut.y = 1f;
  7235. }
  7236. if (cut.y - cut.x < 0.02f)
  7237. {
  7238. cut.x = cut.y - 0.02f;
  7239. if (cut.x < 0.0f)
  7240. {
  7241. cut.x = 0.0f;
  7242. cut.y = 0.02f;
  7243. }
  7244. }
  7245. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  7246. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  7247. if (hollow < 0f)
  7248. {
  7249. hollow = 0f;
  7250. }
  7251. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  7252. // Box or Tube) and the hole shape is a square, hollow is limited to
  7253. // a max of 70%. The viewer performs its own check on this value but
  7254. // we need to do it here also so llGetPrimitiveParams can have access
  7255. // to the correct value.
  7256. if (profileshape != (byte)ProfileCurve.Square &&
  7257. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  7258. {
  7259. if (hollow > 0.70f)
  7260. {
  7261. hollow = 0.70f;
  7262. }
  7263. }
  7264. // Otherwise, hollow is limited to 99%.
  7265. else
  7266. {
  7267. if (hollow > 0.99f)
  7268. {
  7269. hollow = 0.99f;
  7270. }
  7271. }
  7272. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  7273. if (twist.x < -1.0f)
  7274. {
  7275. twist.x = -1.0f;
  7276. }
  7277. else if (twist.x > 1.0f)
  7278. {
  7279. twist.x = 1.0f;
  7280. }
  7281. if (twist.y < -1.0f)
  7282. {
  7283. twist.y = -1.0f;
  7284. }
  7285. else if (twist.y > 1.0f)
  7286. {
  7287. twist.y = 1.0f;
  7288. }
  7289. tempFloat = 100.0f * (float)twist.x;
  7290. if (tempFloat >= 0)
  7291. tempFloat += 0.5f;
  7292. else
  7293. tempFloat -= 0.5f;
  7294. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  7295. tempFloat = 100.0f * (float)twist.y;
  7296. if (tempFloat >= 0)
  7297. tempFloat += 0.5f;
  7298. else
  7299. tempFloat -= 0.5f;
  7300. shapeBlock.PathTwist = (sbyte)tempFloat;
  7301. shapeBlock.ObjectLocalID = part.LocalId;
  7302. part.Shape.SculptEntry = false;
  7303. return shapeBlock;
  7304. }
  7305. // Prim type box, cylinder and prism.
  7306. 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)
  7307. {
  7308. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7309. return;
  7310. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7311. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7312. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7313. if (taper_b.x < 0f)
  7314. {
  7315. taper_b.x = 0f;
  7316. }
  7317. else if (taper_b.x > 2f)
  7318. {
  7319. taper_b.x = 2f;
  7320. }
  7321. if (taper_b.y < 0f)
  7322. {
  7323. taper_b.y = 0f;
  7324. }
  7325. else if (taper_b.y > 2f)
  7326. {
  7327. taper_b.y = 2f;
  7328. }
  7329. tempFloat = 100.0f * (2.0f - (float)taper_b.x);
  7330. if (tempFloat >= 0)
  7331. tempFloat += 0.5f;
  7332. else
  7333. tempFloat -= 0.5f;
  7334. shapeBlock.PathScaleX = (byte)tempFloat;
  7335. tempFloat = 100.0f * (2.0f - (float)taper_b.y);
  7336. if (tempFloat >= 0)
  7337. tempFloat += 0.5f;
  7338. else
  7339. tempFloat -= 0.5f;
  7340. shapeBlock.PathScaleY = (byte)tempFloat;
  7341. if (topshear.x < -0.5f)
  7342. {
  7343. topshear.x = -0.5f;
  7344. }
  7345. else if (topshear.x > 0.5f)
  7346. {
  7347. topshear.x = 0.5f;
  7348. }
  7349. if (topshear.y < -0.5f)
  7350. {
  7351. topshear.y = -0.5f;
  7352. }
  7353. else if (topshear.y > 0.5f)
  7354. {
  7355. topshear.y = 0.5f;
  7356. }
  7357. tempFloat = 100.0f * (float)topshear.x;
  7358. if (tempFloat >= 0)
  7359. tempFloat += 0.5f;
  7360. else
  7361. tempFloat -= 0.5f;
  7362. shapeBlock.PathShearX = (byte)tempFloat;
  7363. tempFloat = 100.0f * (float)topshear.y;
  7364. if (tempFloat >= 0)
  7365. tempFloat += 0.5f;
  7366. else
  7367. tempFloat -= 0.5f;
  7368. shapeBlock.PathShearY = (byte)tempFloat;
  7369. part.Shape.SculptEntry = false;
  7370. part.UpdateShape(shapeBlock);
  7371. }
  7372. // Prim type sphere.
  7373. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  7374. {
  7375. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7376. return;
  7377. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7378. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7379. // profile/path swapped for a sphere
  7380. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7381. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7382. shapeBlock.PathScaleX = 100;
  7383. shapeBlock.PathScaleY = 100;
  7384. if (dimple.x < 0f)
  7385. {
  7386. dimple.x = 0f;
  7387. }
  7388. else if (dimple.x > 1f)
  7389. {
  7390. dimple.x = 1f;
  7391. }
  7392. if (dimple.y < 0f)
  7393. {
  7394. dimple.y = 0f;
  7395. }
  7396. else if (dimple.y > 1f)
  7397. {
  7398. dimple.y = 1f;
  7399. }
  7400. if (dimple.y - dimple.x < 0.02f)
  7401. {
  7402. dimple.x = dimple.y - 0.02f;
  7403. if (dimple.x < 0.0f)
  7404. {
  7405. dimple.x = 0.0f;
  7406. dimple.y = 0.02f;
  7407. }
  7408. }
  7409. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  7410. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  7411. part.Shape.SculptEntry = false;
  7412. part.UpdateShape(shapeBlock);
  7413. }
  7414. // Prim type torus, tube and ring.
  7415. 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)
  7416. {
  7417. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7418. return;
  7419. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7420. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7421. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7422. // profile/path swapped for a torrus, tube, ring
  7423. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7424. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7425. if (holesize.x < 0.01f)
  7426. {
  7427. holesize.x = 0.01f;
  7428. }
  7429. else if (holesize.x > 1f)
  7430. {
  7431. holesize.x = 1f;
  7432. }
  7433. tempFloat = 100.0f * (2.0f - (float)holesize.x) + 0.5f;
  7434. shapeBlock.PathScaleX = (byte)tempFloat;
  7435. if (holesize.y < 0.01f)
  7436. {
  7437. holesize.y = 0.01f;
  7438. }
  7439. else if (holesize.y > 0.5f)
  7440. {
  7441. holesize.y = 0.5f;
  7442. }
  7443. tempFloat = 100.0f * (2.0f - (float)holesize.y) + 0.5f;
  7444. shapeBlock.PathScaleY = (byte)tempFloat;
  7445. if (topshear.x < -0.5f)
  7446. {
  7447. topshear.x = -0.5f;
  7448. }
  7449. else if (topshear.x > 0.5f)
  7450. {
  7451. topshear.x = 0.5f;
  7452. }
  7453. tempFloat = (float)(100.0d * topshear.x);
  7454. if (tempFloat >= 0)
  7455. tempFloat += 0.5f;
  7456. else
  7457. tempFloat -= 0.5f;
  7458. shapeBlock.PathShearX = (byte)tempFloat;
  7459. if (topshear.y < -0.5f)
  7460. {
  7461. topshear.y = -0.5f;
  7462. }
  7463. else if (topshear.y > 0.5f)
  7464. {
  7465. topshear.y = 0.5f;
  7466. }
  7467. tempFloat = (float)(100.0d * topshear.y);
  7468. if (tempFloat >= 0)
  7469. tempFloat += 0.5f;
  7470. else
  7471. tempFloat -= 0.5f;
  7472. shapeBlock.PathShearY = (byte)tempFloat;
  7473. if (profilecut.x < 0f)
  7474. {
  7475. profilecut.x = 0f;
  7476. }
  7477. else if (profilecut.x > 1f)
  7478. {
  7479. profilecut.x = 1f;
  7480. }
  7481. if (profilecut.y < 0f)
  7482. {
  7483. profilecut.y = 0f;
  7484. }
  7485. else if (profilecut.y > 1f)
  7486. {
  7487. profilecut.y = 1f;
  7488. }
  7489. if (profilecut.y - profilecut.x < 0.02f)
  7490. {
  7491. profilecut.x = profilecut.y - 0.02f;
  7492. if (profilecut.x < 0.0f)
  7493. {
  7494. profilecut.x = 0.0f;
  7495. profilecut.y = 0.02f;
  7496. }
  7497. }
  7498. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  7499. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  7500. if (taper_a.x < -1f)
  7501. {
  7502. taper_a.x = -1f;
  7503. }
  7504. if (taper_a.x > 1f)
  7505. {
  7506. taper_a.x = 1f;
  7507. }
  7508. tempFloat = 100.0f * (float)taper_a.x;
  7509. if (tempFloat >= 0)
  7510. tempFloat += 0.5f;
  7511. else
  7512. tempFloat -= 0.5f;
  7513. shapeBlock.PathTaperX = (sbyte)tempFloat;
  7514. if (taper_a.y < -1f)
  7515. {
  7516. taper_a.y = -1f;
  7517. }
  7518. else if (taper_a.y > 1f)
  7519. {
  7520. taper_a.y = 1f;
  7521. }
  7522. tempFloat = 100.0f * (float)taper_a.y;
  7523. if (tempFloat >= 0)
  7524. tempFloat += 0.5f;
  7525. else
  7526. tempFloat -= 0.5f;
  7527. shapeBlock.PathTaperY = (sbyte)tempFloat;
  7528. if (revolutions < 1f)
  7529. {
  7530. revolutions = 1f;
  7531. }
  7532. if (revolutions > 4f)
  7533. {
  7534. revolutions = 4f;
  7535. }
  7536. tempFloat = 66.66667f * (revolutions - 1.0f) + 0.5f;
  7537. shapeBlock.PathRevolutions = (byte)tempFloat;
  7538. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  7539. if (radiusoffset < 0f)
  7540. {
  7541. radiusoffset = 0f;
  7542. }
  7543. if (radiusoffset > 1f)
  7544. {
  7545. radiusoffset = 1f;
  7546. }
  7547. tempFloat = 100.0f * radiusoffset + 0.5f;
  7548. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  7549. if (skew < -0.95f)
  7550. {
  7551. skew = -0.95f;
  7552. }
  7553. if (skew > 0.95f)
  7554. {
  7555. skew = 0.95f;
  7556. }
  7557. tempFloat = 100.0f * skew;
  7558. if (tempFloat >= 0)
  7559. tempFloat += 0.5f;
  7560. else
  7561. tempFloat -= 0.5f;
  7562. shapeBlock.PathSkew = (sbyte)tempFloat;
  7563. part.Shape.SculptEntry = false;
  7564. part.UpdateShape(shapeBlock);
  7565. }
  7566. // Prim type sculpt.
  7567. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  7568. {
  7569. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7570. return;
  7571. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7572. if (!UUID.TryParse(map, out UUID sculptId))
  7573. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  7574. if (sculptId == UUID.Zero)
  7575. return;
  7576. shapeBlock.PathCurve = pathcurve;
  7577. shapeBlock.ObjectLocalID = part.LocalId;
  7578. shapeBlock.PathScaleX = 100;
  7579. shapeBlock.PathScaleY = 150;
  7580. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  7581. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  7582. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  7583. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  7584. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  7585. {
  7586. // default
  7587. type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  7588. }
  7589. part.Shape.SetSculptProperties((byte)type, sculptId);
  7590. part.Shape.SculptEntry = true;
  7591. part.UpdateShape(shapeBlock);
  7592. }
  7593. public void llSetPrimitiveParams(LSL_List rules)
  7594. {
  7595. m_host.AddScriptLPS(1);
  7596. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  7597. ScriptSleep(m_sleepMsOnSetPrimitiveParams);
  7598. }
  7599. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7600. {
  7601. m_host.AddScriptLPS(1);
  7602. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  7603. ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
  7604. }
  7605. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  7606. {
  7607. m_host.AddScriptLPS(1);
  7608. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  7609. }
  7610. private void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  7611. {
  7612. List<object> parts = new List<object>();
  7613. List<SceneObjectPart> prims = GetLinkParts(linknumber);
  7614. List<ScenePresence> avatars = GetLinkAvatars(linknumber);
  7615. foreach (SceneObjectPart p in prims)
  7616. parts.Add(p);
  7617. foreach (ScenePresence p in avatars)
  7618. parts.Add(p);
  7619. LSL_List remaining = new LSL_List();
  7620. uint rulesParsed = 0;
  7621. if (parts.Count > 0)
  7622. {
  7623. foreach (object part in parts)
  7624. {
  7625. if (part is SceneObjectPart)
  7626. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7627. else
  7628. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7629. }
  7630. while (remaining.Length > 2)
  7631. {
  7632. linknumber = remaining.GetLSLIntegerItem(0);
  7633. rules = remaining.GetSublist(1, -1);
  7634. parts.Clear();
  7635. prims = GetLinkParts(linknumber);
  7636. avatars = GetLinkAvatars(linknumber);
  7637. foreach (SceneObjectPart p in prims)
  7638. parts.Add(p);
  7639. foreach (ScenePresence p in avatars)
  7640. parts.Add(p);
  7641. remaining = new LSL_List();
  7642. foreach (object part in parts)
  7643. {
  7644. if (part is SceneObjectPart)
  7645. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7646. else
  7647. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7648. }
  7649. }
  7650. }
  7651. }
  7652. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  7653. {
  7654. SceneObjectGroup group = m_host.ParentGroup;
  7655. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  7656. return;
  7657. if (group.IsAttachment)
  7658. return;
  7659. if (frames.Data.Length > 0) // We are getting a new motion
  7660. {
  7661. if (group.RootPart.KeyframeMotion != null)
  7662. group.RootPart.KeyframeMotion.Delete();
  7663. group.RootPart.KeyframeMotion = null;
  7664. int idx = 0;
  7665. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  7666. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  7667. while (idx < options.Data.Length)
  7668. {
  7669. int option = (int)options.GetLSLIntegerItem(idx++);
  7670. int remain = options.Data.Length - idx;
  7671. switch (option)
  7672. {
  7673. case ScriptBaseClass.KFM_MODE:
  7674. if (remain < 1)
  7675. break;
  7676. int modeval = (int)options.GetLSLIntegerItem(idx++);
  7677. switch(modeval)
  7678. {
  7679. case ScriptBaseClass.KFM_FORWARD:
  7680. mode = KeyframeMotion.PlayMode.Forward;
  7681. break;
  7682. case ScriptBaseClass.KFM_REVERSE:
  7683. mode = KeyframeMotion.PlayMode.Reverse;
  7684. break;
  7685. case ScriptBaseClass.KFM_LOOP:
  7686. mode = KeyframeMotion.PlayMode.Loop;
  7687. break;
  7688. case ScriptBaseClass.KFM_PING_PONG:
  7689. mode = KeyframeMotion.PlayMode.PingPong;
  7690. break;
  7691. }
  7692. break;
  7693. case ScriptBaseClass.KFM_DATA:
  7694. if (remain < 1)
  7695. break;
  7696. int dataval = (int)options.GetLSLIntegerItem(idx++);
  7697. data = (KeyframeMotion.DataFormat)dataval;
  7698. break;
  7699. }
  7700. }
  7701. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  7702. idx = 0;
  7703. int elemLength = 2;
  7704. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  7705. elemLength = 3;
  7706. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  7707. bool hasTranslation = (data & KeyframeMotion.DataFormat.Translation) != 0;
  7708. bool hasRotation = (data & KeyframeMotion.DataFormat.Rotation) != 0;
  7709. while (idx < frames.Data.Length)
  7710. {
  7711. int remain = frames.Data.Length - idx;
  7712. if (remain < elemLength)
  7713. break;
  7714. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe
  7715. {
  7716. Position = null,
  7717. Rotation = null
  7718. };
  7719. if (hasTranslation)
  7720. {
  7721. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  7722. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  7723. }
  7724. if (hasRotation)
  7725. {
  7726. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  7727. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  7728. frame.Rotation = q;
  7729. }
  7730. float tempf = (float)frames.GetLSLFloatItem(idx++);
  7731. frame.TimeMS = (int)(tempf * 1000.0f);
  7732. keyframes.Add(frame);
  7733. }
  7734. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  7735. group.RootPart.KeyframeMotion.Start();
  7736. }
  7737. else
  7738. {
  7739. if (group.RootPart.KeyframeMotion == null)
  7740. return;
  7741. if (options.Data.Length == 0)
  7742. {
  7743. group.RootPart.KeyframeMotion.Stop();
  7744. return;
  7745. }
  7746. int idx = 0;
  7747. while (idx < options.Data.Length)
  7748. {
  7749. int option = (int)options.GetLSLIntegerItem(idx++);
  7750. switch (option)
  7751. {
  7752. case ScriptBaseClass.KFM_COMMAND:
  7753. int cmd = (int)options.GetLSLIntegerItem(idx++);
  7754. switch (cmd)
  7755. {
  7756. case ScriptBaseClass.KFM_CMD_PLAY:
  7757. group.RootPart.KeyframeMotion.Start();
  7758. break;
  7759. case ScriptBaseClass.KFM_CMD_STOP:
  7760. group.RootPart.KeyframeMotion.Stop();
  7761. break;
  7762. case ScriptBaseClass.KFM_CMD_PAUSE:
  7763. group.RootPart.KeyframeMotion.Pause();
  7764. break;
  7765. }
  7766. break;
  7767. }
  7768. }
  7769. }
  7770. }
  7771. public LSL_List llGetPhysicsMaterial()
  7772. {
  7773. LSL_List result = new LSL_List();
  7774. result.Add(new LSL_Float(m_host.GravityModifier));
  7775. result.Add(new LSL_Float(m_host.Restitution));
  7776. result.Add(new LSL_Float(m_host.Friction));
  7777. result.Add(new LSL_Float(m_host.Density));
  7778. return result;
  7779. }
  7780. private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
  7781. float material_density, float material_friction,
  7782. float material_restitution, float material_gravity_modifier)
  7783. {
  7784. ExtraPhysicsData physdata = new ExtraPhysicsData
  7785. {
  7786. PhysShapeType = (PhysShapeType)part.PhysicsShapeType,
  7787. Density = part.Density,
  7788. Friction = part.Friction,
  7789. Bounce = part.Restitution,
  7790. GravitationModifier = part.GravityModifier
  7791. };
  7792. if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
  7793. physdata.Density = material_density;
  7794. if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
  7795. physdata.Friction = material_friction;
  7796. if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
  7797. physdata.Bounce = material_restitution;
  7798. if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
  7799. physdata.GravitationModifier = material_gravity_modifier;
  7800. part.UpdateExtraPhysics(physdata);
  7801. }
  7802. public void llSetPhysicsMaterial(int material_bits,
  7803. LSL_Float material_gravity_modifier, LSL_Float material_restitution,
  7804. LSL_Float material_friction, LSL_Float material_density)
  7805. {
  7806. SetPhysicsMaterial(m_host, material_bits, (float)material_density, (float)material_friction, (float)material_restitution, (float)material_gravity_modifier);
  7807. }
  7808. // vector up using libomv (c&p from sop )
  7809. // vector up rotated by r
  7810. private Vector3 Zrot(Quaternion r)
  7811. {
  7812. double x, y, z, m;
  7813. m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7814. if (Math.Abs(1.0 - m) > 0.000001)
  7815. {
  7816. m = 1.0 / Math.Sqrt(m);
  7817. r.X *= (float)m;
  7818. r.Y *= (float)m;
  7819. r.Z *= (float)m;
  7820. r.W *= (float)m;
  7821. }
  7822. x = 2 * (r.X * r.Z + r.Y * r.W);
  7823. y = 2 * (-r.X * r.W + r.Y * r.Z);
  7824. z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7825. return new Vector3((float)x, (float)y, (float)z);
  7826. }
  7827. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  7828. {
  7829. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7830. return new LSL_List();
  7831. int idx = 0;
  7832. int idxStart = 0;
  7833. SceneObjectGroup parentgrp = part.ParentGroup;
  7834. bool positionChanged = false;
  7835. bool materialChanged = false;
  7836. LSL_Vector currentPosition = GetPartLocalPos(part);
  7837. try
  7838. {
  7839. while (idx < rules.Length)
  7840. {
  7841. ++rulesParsed;
  7842. int code = rules.GetLSLIntegerItem(idx++);
  7843. int remain = rules.Length - idx;
  7844. idxStart = idx;
  7845. int face;
  7846. LSL_Vector v;
  7847. switch (code)
  7848. {
  7849. case ScriptBaseClass.PRIM_POSITION:
  7850. case ScriptBaseClass.PRIM_POS_LOCAL:
  7851. if (remain < 1)
  7852. return new LSL_List();
  7853. try
  7854. {
  7855. v = rules.GetVector3Item(idx++);
  7856. }
  7857. catch(InvalidCastException)
  7858. {
  7859. if(code == ScriptBaseClass.PRIM_POSITION)
  7860. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7861. else
  7862. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7863. return new LSL_List();
  7864. }
  7865. if (part.IsRoot && !part.ParentGroup.IsAttachment)
  7866. currentPosition = GetSetPosTarget(part, v, currentPosition, true);
  7867. else
  7868. currentPosition = GetSetPosTarget(part, v, currentPosition, false);
  7869. positionChanged = true;
  7870. break;
  7871. case ScriptBaseClass.PRIM_SIZE:
  7872. if (remain < 1)
  7873. return new LSL_List();
  7874. v=rules.GetVector3Item(idx++);
  7875. SetScale(part, v);
  7876. break;
  7877. case ScriptBaseClass.PRIM_ROTATION:
  7878. if (remain < 1)
  7879. return new LSL_List();
  7880. LSL_Rotation q;
  7881. try
  7882. {
  7883. q = rules.GetQuaternionItem(idx++);
  7884. }
  7885. catch(InvalidCastException)
  7886. {
  7887. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
  7888. return new LSL_List();
  7889. }
  7890. // try to let this work as in SL...
  7891. if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
  7892. {
  7893. // special case: If we are root, rotate complete SOG to new rotation
  7894. SetRot(part, q);
  7895. }
  7896. else
  7897. {
  7898. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  7899. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  7900. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  7901. }
  7902. break;
  7903. case ScriptBaseClass.PRIM_TYPE:
  7904. if (remain < 3)
  7905. return new LSL_List();
  7906. try
  7907. {
  7908. code = (int)rules.GetLSLIntegerItem(idx++);
  7909. }
  7910. catch(InvalidCastException)
  7911. {
  7912. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  7913. return new LSL_List();
  7914. }
  7915. remain = rules.Length - idx;
  7916. float hollow;
  7917. LSL_Vector twist;
  7918. LSL_Vector taper_b;
  7919. LSL_Vector topshear;
  7920. float revolutions;
  7921. float radiusoffset;
  7922. float skew;
  7923. LSL_Vector holesize;
  7924. LSL_Vector profilecut;
  7925. switch (code)
  7926. {
  7927. case ScriptBaseClass.PRIM_TYPE_BOX:
  7928. if (remain < 6)
  7929. return new LSL_List();
  7930. try
  7931. {
  7932. face = (int)rules.GetLSLIntegerItem(idx++);
  7933. }
  7934. catch(InvalidCastException)
  7935. {
  7936. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7937. return new LSL_List();
  7938. }
  7939. try
  7940. {
  7941. v = rules.GetVector3Item(idx++); // cut
  7942. }
  7943. catch(InvalidCastException)
  7944. {
  7945. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7946. return new LSL_List();
  7947. }
  7948. try
  7949. {
  7950. hollow = (float)rules.GetLSLFloatItem(idx++);
  7951. }
  7952. catch(InvalidCastException)
  7953. {
  7954. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7955. return new LSL_List();
  7956. }
  7957. try
  7958. {
  7959. twist = rules.GetVector3Item(idx++);
  7960. }
  7961. catch(InvalidCastException)
  7962. {
  7963. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
  7964. return new LSL_List();
  7965. }
  7966. try
  7967. {
  7968. taper_b = rules.GetVector3Item(idx++);
  7969. }
  7970. catch(InvalidCastException)
  7971. {
  7972. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7973. return new LSL_List();
  7974. }
  7975. try
  7976. {
  7977. topshear = rules.GetVector3Item(idx++);
  7978. }
  7979. catch(InvalidCastException)
  7980. {
  7981. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7982. return new LSL_List();
  7983. }
  7984. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7985. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  7986. break;
  7987. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  7988. if (remain < 6)
  7989. return new LSL_List();
  7990. try
  7991. {
  7992. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7993. }
  7994. catch(InvalidCastException)
  7995. {
  7996. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7997. return new LSL_List();
  7998. }
  7999. try
  8000. {
  8001. v = rules.GetVector3Item(idx++); // cut
  8002. }
  8003. catch(InvalidCastException)
  8004. {
  8005. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8006. return new LSL_List();
  8007. }
  8008. try
  8009. {
  8010. hollow = (float)rules.GetLSLFloatItem(idx++);
  8011. }
  8012. catch(InvalidCastException)
  8013. {
  8014. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8015. return new LSL_List();
  8016. }
  8017. try
  8018. {
  8019. twist = rules.GetVector3Item(idx++);
  8020. }
  8021. catch(InvalidCastException)
  8022. {
  8023. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8024. return new LSL_List();
  8025. }
  8026. try
  8027. {
  8028. taper_b = rules.GetVector3Item(idx++);
  8029. }
  8030. catch(InvalidCastException)
  8031. {
  8032. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8033. return new LSL_List();
  8034. }
  8035. try
  8036. {
  8037. topshear = rules.GetVector3Item(idx++);
  8038. }
  8039. catch(InvalidCastException)
  8040. {
  8041. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8042. return new LSL_List();
  8043. }
  8044. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8045. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  8046. break;
  8047. case ScriptBaseClass.PRIM_TYPE_PRISM:
  8048. if (remain < 6)
  8049. return new LSL_List();
  8050. try
  8051. {
  8052. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8053. }
  8054. catch(InvalidCastException)
  8055. {
  8056. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8057. return new LSL_List();
  8058. }
  8059. try
  8060. {
  8061. v = rules.GetVector3Item(idx++); //cut
  8062. }
  8063. catch(InvalidCastException)
  8064. {
  8065. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8066. return new LSL_List();
  8067. }
  8068. try
  8069. {
  8070. hollow = (float)rules.GetLSLFloatItem(idx++);
  8071. }
  8072. catch(InvalidCastException)
  8073. {
  8074. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8075. return new LSL_List();
  8076. }
  8077. try
  8078. {
  8079. twist = rules.GetVector3Item(idx++);
  8080. }
  8081. catch(InvalidCastException)
  8082. {
  8083. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8084. return new LSL_List();
  8085. }
  8086. try
  8087. {
  8088. taper_b = rules.GetVector3Item(idx++);
  8089. }
  8090. catch(InvalidCastException)
  8091. {
  8092. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8093. return new LSL_List();
  8094. }
  8095. try
  8096. {
  8097. topshear = rules.GetVector3Item(idx++);
  8098. }
  8099. catch(InvalidCastException)
  8100. {
  8101. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8102. return new LSL_List();
  8103. }
  8104. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8105. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  8106. break;
  8107. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  8108. if (remain < 5)
  8109. return new LSL_List();
  8110. try
  8111. {
  8112. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8113. }
  8114. catch(InvalidCastException)
  8115. {
  8116. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8117. return new LSL_List();
  8118. }
  8119. try
  8120. {
  8121. v = rules.GetVector3Item(idx++); // cut
  8122. }
  8123. catch(InvalidCastException)
  8124. {
  8125. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8126. return new LSL_List();
  8127. }
  8128. try
  8129. {
  8130. hollow = (float)rules.GetLSLFloatItem(idx++);
  8131. }
  8132. catch(InvalidCastException)
  8133. {
  8134. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8135. return new LSL_List();
  8136. }
  8137. try
  8138. {
  8139. twist = rules.GetVector3Item(idx++);
  8140. }
  8141. catch(InvalidCastException)
  8142. {
  8143. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8144. return new LSL_List();
  8145. }
  8146. try
  8147. {
  8148. taper_b = rules.GetVector3Item(idx++); // dimple
  8149. }
  8150. catch(InvalidCastException)
  8151. {
  8152. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8153. return new LSL_List();
  8154. }
  8155. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  8156. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  8157. break;
  8158. case ScriptBaseClass.PRIM_TYPE_TORUS:
  8159. if (remain < 11)
  8160. return new LSL_List();
  8161. try
  8162. {
  8163. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8164. }
  8165. catch(InvalidCastException)
  8166. {
  8167. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8168. return new LSL_List();
  8169. }
  8170. try
  8171. {
  8172. v = rules.GetVector3Item(idx++); //cut
  8173. }
  8174. catch(InvalidCastException)
  8175. {
  8176. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8177. return new LSL_List();
  8178. }
  8179. try
  8180. {
  8181. hollow = (float)rules.GetLSLFloatItem(idx++);
  8182. }
  8183. catch(InvalidCastException)
  8184. {
  8185. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8186. return new LSL_List();
  8187. }
  8188. try
  8189. {
  8190. twist = rules.GetVector3Item(idx++);
  8191. }
  8192. catch(InvalidCastException)
  8193. {
  8194. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8195. return new LSL_List();
  8196. }
  8197. try
  8198. {
  8199. holesize = rules.GetVector3Item(idx++);
  8200. }
  8201. catch(InvalidCastException)
  8202. {
  8203. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8204. return new LSL_List();
  8205. }
  8206. try
  8207. {
  8208. topshear = rules.GetVector3Item(idx++);
  8209. }
  8210. catch(InvalidCastException)
  8211. {
  8212. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8213. return new LSL_List();
  8214. }
  8215. try
  8216. {
  8217. profilecut = rules.GetVector3Item(idx++);
  8218. }
  8219. catch(InvalidCastException)
  8220. {
  8221. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8222. return new LSL_List();
  8223. }
  8224. try
  8225. {
  8226. taper_b = rules.GetVector3Item(idx++); // taper_a
  8227. }
  8228. catch(InvalidCastException)
  8229. {
  8230. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8231. return new LSL_List();
  8232. }
  8233. try
  8234. {
  8235. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8236. }
  8237. catch(InvalidCastException)
  8238. {
  8239. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8240. return new LSL_List();
  8241. }
  8242. try
  8243. {
  8244. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8245. }
  8246. catch(InvalidCastException)
  8247. {
  8248. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8249. return new LSL_List();
  8250. }
  8251. try
  8252. {
  8253. skew = (float)rules.GetLSLFloatItem(idx++);
  8254. }
  8255. catch(InvalidCastException)
  8256. {
  8257. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
  8258. return new LSL_List();
  8259. }
  8260. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8261. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  8262. break;
  8263. case ScriptBaseClass.PRIM_TYPE_TUBE:
  8264. if (remain < 11)
  8265. return new LSL_List();
  8266. try
  8267. {
  8268. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8269. }
  8270. catch(InvalidCastException)
  8271. {
  8272. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8273. return new LSL_List();
  8274. }
  8275. try
  8276. {
  8277. v = rules.GetVector3Item(idx++); //cut
  8278. }
  8279. catch(InvalidCastException)
  8280. {
  8281. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8282. return new LSL_List();
  8283. }
  8284. try
  8285. {
  8286. hollow = (float)rules.GetLSLFloatItem(idx++);
  8287. }
  8288. catch(InvalidCastException)
  8289. {
  8290. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8291. return new LSL_List();
  8292. }
  8293. try
  8294. {
  8295. twist = rules.GetVector3Item(idx++);
  8296. }
  8297. catch(InvalidCastException)
  8298. {
  8299. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8300. return new LSL_List();
  8301. }
  8302. try
  8303. {
  8304. holesize = rules.GetVector3Item(idx++);
  8305. }
  8306. catch(InvalidCastException)
  8307. {
  8308. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8309. return new LSL_List();
  8310. }
  8311. try
  8312. {
  8313. topshear = rules.GetVector3Item(idx++);
  8314. }
  8315. catch(InvalidCastException)
  8316. {
  8317. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8318. return new LSL_List();
  8319. }
  8320. try
  8321. {
  8322. profilecut = rules.GetVector3Item(idx++);
  8323. }
  8324. catch(InvalidCastException)
  8325. {
  8326. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8327. return new LSL_List();
  8328. }
  8329. try
  8330. {
  8331. taper_b = rules.GetVector3Item(idx++); // taper_a
  8332. }
  8333. catch(InvalidCastException)
  8334. {
  8335. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8336. return new LSL_List();
  8337. }
  8338. try
  8339. {
  8340. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8341. }
  8342. catch(InvalidCastException)
  8343. {
  8344. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8345. return new LSL_List();
  8346. }
  8347. try
  8348. {
  8349. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8350. }
  8351. catch(InvalidCastException)
  8352. {
  8353. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8354. return new LSL_List();
  8355. }
  8356. try
  8357. {
  8358. skew = (float)rules.GetLSLFloatItem(idx++);
  8359. }
  8360. catch(InvalidCastException)
  8361. {
  8362. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8363. return new LSL_List();
  8364. }
  8365. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8366. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  8367. break;
  8368. case ScriptBaseClass.PRIM_TYPE_RING:
  8369. if (remain < 11)
  8370. return new LSL_List();
  8371. try
  8372. {
  8373. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8374. }
  8375. catch(InvalidCastException)
  8376. {
  8377. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8378. return new LSL_List();
  8379. }
  8380. try
  8381. {
  8382. v = rules.GetVector3Item(idx++); //cut
  8383. }
  8384. catch(InvalidCastException)
  8385. {
  8386. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8387. return new LSL_List();
  8388. }
  8389. try
  8390. {
  8391. hollow = (float)rules.GetLSLFloatItem(idx++);
  8392. }
  8393. catch(InvalidCastException)
  8394. {
  8395. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8396. return new LSL_List();
  8397. }
  8398. try
  8399. {
  8400. twist = rules.GetVector3Item(idx++);
  8401. }
  8402. catch(InvalidCastException)
  8403. {
  8404. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8405. return new LSL_List();
  8406. }
  8407. try
  8408. {
  8409. holesize = rules.GetVector3Item(idx++);
  8410. }
  8411. catch(InvalidCastException)
  8412. {
  8413. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8414. return new LSL_List();
  8415. }
  8416. try
  8417. {
  8418. topshear = rules.GetVector3Item(idx++);
  8419. }
  8420. catch(InvalidCastException)
  8421. {
  8422. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8423. return new LSL_List();
  8424. }
  8425. try
  8426. {
  8427. profilecut = rules.GetVector3Item(idx++);
  8428. }
  8429. catch(InvalidCastException)
  8430. {
  8431. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8432. return new LSL_List();
  8433. }
  8434. try
  8435. {
  8436. taper_b = rules.GetVector3Item(idx++); // taper_a
  8437. }
  8438. catch(InvalidCastException)
  8439. {
  8440. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8441. return new LSL_List();
  8442. }
  8443. try
  8444. {
  8445. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8446. }
  8447. catch(InvalidCastException)
  8448. {
  8449. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8450. return new LSL_List();
  8451. }
  8452. try
  8453. {
  8454. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8455. }
  8456. catch(InvalidCastException)
  8457. {
  8458. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8459. return new LSL_List();
  8460. }
  8461. try
  8462. {
  8463. skew = (float)rules.GetLSLFloatItem(idx++);
  8464. }
  8465. catch(InvalidCastException)
  8466. {
  8467. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8468. return new LSL_List();
  8469. }
  8470. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8471. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  8472. break;
  8473. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  8474. if (remain < 2)
  8475. return new LSL_List();
  8476. string map = rules.Data[idx++].ToString();
  8477. try
  8478. {
  8479. face = (int)rules.GetLSLIntegerItem(idx++); // type
  8480. }
  8481. catch(InvalidCastException)
  8482. {
  8483. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8484. return new LSL_List();
  8485. }
  8486. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  8487. break;
  8488. }
  8489. break;
  8490. case ScriptBaseClass.PRIM_TEXTURE:
  8491. if (remain < 5)
  8492. return new LSL_List();
  8493. face=(int)rules.GetLSLIntegerItem(idx++);
  8494. string tex;
  8495. LSL_Vector repeats;
  8496. LSL_Vector offsets;
  8497. double rotation;
  8498. tex = rules.Data[idx++].ToString();
  8499. try
  8500. {
  8501. repeats = rules.GetVector3Item(idx++);
  8502. }
  8503. catch(InvalidCastException)
  8504. {
  8505. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8506. return new LSL_List();
  8507. }
  8508. try
  8509. {
  8510. offsets = rules.GetVector3Item(idx++);
  8511. }
  8512. catch(InvalidCastException)
  8513. {
  8514. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8515. return new LSL_List();
  8516. }
  8517. try
  8518. {
  8519. rotation = (double)rules.GetLSLFloatItem(idx++);
  8520. }
  8521. catch(InvalidCastException)
  8522. {
  8523. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8524. return new LSL_List();
  8525. }
  8526. SetTextureParams(part, tex, repeats.x, repeats.y, offsets.x, offsets.y, rotation, face);
  8527. break;
  8528. case ScriptBaseClass.PRIM_COLOR:
  8529. if (remain < 3)
  8530. return new LSL_List();
  8531. LSL_Vector color;
  8532. double alpha;
  8533. try
  8534. {
  8535. face = (int)rules.GetLSLIntegerItem(idx++);
  8536. }
  8537. catch(InvalidCastException)
  8538. {
  8539. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8540. return new LSL_List();
  8541. }
  8542. try
  8543. {
  8544. color = rules.GetVector3Item(idx++);
  8545. }
  8546. catch(InvalidCastException)
  8547. {
  8548. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8549. return new LSL_List();
  8550. }
  8551. try
  8552. {
  8553. alpha = (double)rules.GetLSLFloatItem(idx++);
  8554. }
  8555. catch(InvalidCastException)
  8556. {
  8557. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8558. return new LSL_List();
  8559. }
  8560. part.SetFaceColorAlpha(face, color, alpha);
  8561. break;
  8562. case ScriptBaseClass.PRIM_FLEXIBLE:
  8563. if (remain < 7)
  8564. return new LSL_List();
  8565. bool flexi;
  8566. int softness;
  8567. float gravity;
  8568. float friction;
  8569. float wind;
  8570. float tension;
  8571. LSL_Vector force;
  8572. try
  8573. {
  8574. flexi = rules.GetLSLIntegerItem(idx++);
  8575. }
  8576. catch(InvalidCastException)
  8577. {
  8578. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8579. return new LSL_List();
  8580. }
  8581. try
  8582. {
  8583. softness = rules.GetLSLIntegerItem(idx++);
  8584. }
  8585. catch(InvalidCastException)
  8586. {
  8587. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8588. return new LSL_List();
  8589. }
  8590. try
  8591. {
  8592. gravity = (float)rules.GetLSLFloatItem(idx++);
  8593. }
  8594. catch(InvalidCastException)
  8595. {
  8596. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8597. return new LSL_List();
  8598. }
  8599. try
  8600. {
  8601. friction = (float)rules.GetLSLFloatItem(idx++);
  8602. }
  8603. catch(InvalidCastException)
  8604. {
  8605. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8606. return new LSL_List();
  8607. }
  8608. try
  8609. {
  8610. wind = (float)rules.GetLSLFloatItem(idx++);
  8611. }
  8612. catch(InvalidCastException)
  8613. {
  8614. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8615. return new LSL_List();
  8616. }
  8617. try
  8618. {
  8619. tension = (float)rules.GetLSLFloatItem(idx++);
  8620. }
  8621. catch(InvalidCastException)
  8622. {
  8623. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
  8624. return new LSL_List();
  8625. }
  8626. try
  8627. {
  8628. force = rules.GetVector3Item(idx++);
  8629. }
  8630. catch(InvalidCastException)
  8631. {
  8632. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8633. return new LSL_List();
  8634. }
  8635. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  8636. break;
  8637. case ScriptBaseClass.PRIM_POINT_LIGHT:
  8638. if (remain < 5)
  8639. return new LSL_List();
  8640. bool light;
  8641. LSL_Vector lightcolor;
  8642. float intensity;
  8643. float radius;
  8644. float falloff;
  8645. try
  8646. {
  8647. light = rules.GetLSLIntegerItem(idx++);
  8648. }
  8649. catch(InvalidCastException)
  8650. {
  8651. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8652. return new LSL_List();
  8653. }
  8654. try
  8655. {
  8656. lightcolor = rules.GetVector3Item(idx++);
  8657. }
  8658. catch(InvalidCastException)
  8659. {
  8660. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8661. return new LSL_List();
  8662. }
  8663. try
  8664. {
  8665. intensity = (float)rules.GetLSLFloatItem(idx++);
  8666. }
  8667. catch(InvalidCastException)
  8668. {
  8669. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8670. return new LSL_List();
  8671. }
  8672. try
  8673. {
  8674. radius = (float)rules.GetLSLFloatItem(idx++);
  8675. }
  8676. catch(InvalidCastException)
  8677. {
  8678. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8679. return new LSL_List();
  8680. }
  8681. try
  8682. {
  8683. falloff = (float)rules.GetLSLFloatItem(idx++);
  8684. }
  8685. catch(InvalidCastException)
  8686. {
  8687. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8688. return new LSL_List();
  8689. }
  8690. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  8691. break;
  8692. case ScriptBaseClass.PRIM_GLOW:
  8693. if (remain < 2)
  8694. return new LSL_List();
  8695. float glow;
  8696. try
  8697. {
  8698. face = rules.GetLSLIntegerItem(idx++);
  8699. }
  8700. catch(InvalidCastException)
  8701. {
  8702. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8703. return new LSL_List();
  8704. }
  8705. try
  8706. {
  8707. glow = (float)rules.GetLSLFloatItem(idx++);
  8708. }
  8709. catch(InvalidCastException)
  8710. {
  8711. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8712. return new LSL_List();
  8713. }
  8714. SetGlow(part, face, glow);
  8715. break;
  8716. case ScriptBaseClass.PRIM_BUMP_SHINY:
  8717. if (remain < 3)
  8718. return new LSL_List();
  8719. int shiny;
  8720. Bumpiness bump;
  8721. try
  8722. {
  8723. face = (int)rules.GetLSLIntegerItem(idx++);
  8724. }
  8725. catch(InvalidCastException)
  8726. {
  8727. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8728. return new LSL_List();
  8729. }
  8730. try
  8731. {
  8732. shiny = (int)rules.GetLSLIntegerItem(idx++);
  8733. }
  8734. catch(InvalidCastException)
  8735. {
  8736. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8737. return new LSL_List();
  8738. }
  8739. try
  8740. {
  8741. bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  8742. }
  8743. catch(InvalidCastException)
  8744. {
  8745. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8746. return new LSL_List();
  8747. }
  8748. SetShiny(part, face, shiny, bump);
  8749. break;
  8750. case ScriptBaseClass.PRIM_FULLBRIGHT:
  8751. if (remain < 2)
  8752. return new LSL_List();
  8753. bool st;
  8754. try
  8755. {
  8756. face = rules.GetLSLIntegerItem(idx++);
  8757. }
  8758. catch(InvalidCastException)
  8759. {
  8760. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8761. return new LSL_List();
  8762. }
  8763. try
  8764. {
  8765. st = rules.GetLSLIntegerItem(idx++);
  8766. }
  8767. catch(InvalidCastException)
  8768. {
  8769. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8770. return new LSL_List();
  8771. }
  8772. SetFullBright(part, face , st);
  8773. break;
  8774. case ScriptBaseClass.PRIM_MATERIAL:
  8775. if (remain < 1)
  8776. return new LSL_List();
  8777. int mat;
  8778. try
  8779. {
  8780. mat = rules.GetLSLIntegerItem(idx++);
  8781. }
  8782. catch(InvalidCastException)
  8783. {
  8784. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8785. return new LSL_List();
  8786. }
  8787. if (mat < 0 || mat > 7)
  8788. return new LSL_List();
  8789. part.Material = Convert.ToByte(mat);
  8790. break;
  8791. case ScriptBaseClass.PRIM_PHANTOM:
  8792. if (remain < 1)
  8793. return new LSL_List();
  8794. string ph = rules.Data[idx++].ToString();
  8795. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  8796. break;
  8797. case ScriptBaseClass.PRIM_PHYSICS:
  8798. if (remain < 1)
  8799. return new LSL_List();
  8800. string phy = rules.Data[idx++].ToString();
  8801. part.ScriptSetPhysicsStatus(phy.Equals("1"));
  8802. break;
  8803. case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  8804. if (remain < 1)
  8805. return new LSL_List();
  8806. int shape_type;
  8807. try
  8808. {
  8809. shape_type = rules.GetLSLIntegerItem(idx++);
  8810. }
  8811. catch(InvalidCastException)
  8812. {
  8813. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8814. return new LSL_List();
  8815. }
  8816. ExtraPhysicsData physdata = new ExtraPhysicsData
  8817. {
  8818. Density = part.Density,
  8819. Bounce = part.Restitution,
  8820. GravitationModifier = part.GravityModifier,
  8821. PhysShapeType = (PhysShapeType)shape_type
  8822. };
  8823. part.UpdateExtraPhysics(physdata);
  8824. break;
  8825. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  8826. if (remain < 5)
  8827. return new LSL_List();
  8828. int material_bits = rules.GetLSLIntegerItem(idx++);
  8829. float material_density = (float)rules.GetLSLFloatItem(idx++);
  8830. float material_friction = (float)rules.GetLSLFloatItem(idx++);
  8831. float material_restitution = (float)rules.GetLSLFloatItem(idx++);
  8832. float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
  8833. SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
  8834. break;
  8835. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  8836. if (remain < 1)
  8837. return new LSL_List();
  8838. string temp = rules.Data[idx++].ToString();
  8839. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  8840. break;
  8841. case ScriptBaseClass.PRIM_TEXGEN:
  8842. if (remain < 2)
  8843. return new LSL_List();
  8844. //face,type
  8845. int style;
  8846. try
  8847. {
  8848. face = rules.GetLSLIntegerItem(idx++);
  8849. }
  8850. catch(InvalidCastException)
  8851. {
  8852. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8853. return new LSL_List();
  8854. }
  8855. try
  8856. {
  8857. style = rules.GetLSLIntegerItem(idx++);
  8858. }
  8859. catch(InvalidCastException)
  8860. {
  8861. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8862. return new LSL_List();
  8863. }
  8864. SetTexGen(part, face, style);
  8865. break;
  8866. case ScriptBaseClass.PRIM_TEXT:
  8867. if (remain < 3)
  8868. return new LSL_List();
  8869. string primText;
  8870. LSL_Vector primTextColor;
  8871. LSL_Float primTextAlpha;
  8872. try
  8873. {
  8874. primText = rules.GetLSLStringItem(idx++);
  8875. }
  8876. catch(InvalidCastException)
  8877. {
  8878. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8879. return new LSL_List();
  8880. }
  8881. try
  8882. {
  8883. primTextColor = rules.GetVector3Item(idx++);
  8884. }
  8885. catch(InvalidCastException)
  8886. {
  8887. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8888. return new LSL_List();
  8889. }
  8890. try
  8891. {
  8892. primTextAlpha = rules.GetLSLFloatItem(idx++);
  8893. }
  8894. catch(InvalidCastException)
  8895. {
  8896. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8897. return new LSL_List();
  8898. }
  8899. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  8900. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  8901. break;
  8902. case ScriptBaseClass.PRIM_NAME:
  8903. if (remain < 1)
  8904. return new LSL_List();
  8905. try
  8906. {
  8907. string primName = rules.GetLSLStringItem(idx++);
  8908. part.Name = primName;
  8909. }
  8910. catch(InvalidCastException)
  8911. {
  8912. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8913. return new LSL_List();
  8914. }
  8915. break;
  8916. case ScriptBaseClass.PRIM_DESC:
  8917. if (remain < 1)
  8918. return new LSL_List();
  8919. try
  8920. {
  8921. string primDesc = rules.GetLSLStringItem(idx++);
  8922. part.Description = primDesc;
  8923. }
  8924. catch(InvalidCastException)
  8925. {
  8926. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8927. return new LSL_List();
  8928. }
  8929. break;
  8930. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8931. if (remain < 1)
  8932. return new LSL_List();
  8933. LSL_Rotation rot;
  8934. try
  8935. {
  8936. rot = rules.GetQuaternionItem(idx++);
  8937. }
  8938. catch(InvalidCastException)
  8939. {
  8940. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8941. return new LSL_List();
  8942. }
  8943. SetRot(part, rot);
  8944. break;
  8945. case ScriptBaseClass.PRIM_OMEGA:
  8946. if (remain < 3)
  8947. return new LSL_List();
  8948. LSL_Vector axis;
  8949. LSL_Float spinrate;
  8950. LSL_Float gain;
  8951. try
  8952. {
  8953. axis = rules.GetVector3Item(idx++);
  8954. }
  8955. catch(InvalidCastException)
  8956. {
  8957. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8958. return new LSL_List();
  8959. }
  8960. try
  8961. {
  8962. spinrate = rules.GetLSLFloatItem(idx++);
  8963. }
  8964. catch(InvalidCastException)
  8965. {
  8966. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8967. return new LSL_List();
  8968. }
  8969. try
  8970. {
  8971. gain = rules.GetLSLFloatItem(idx++);
  8972. }
  8973. catch(InvalidCastException)
  8974. {
  8975. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8976. return new LSL_List();
  8977. }
  8978. TargetOmega(part, axis, (double)spinrate, (double)gain);
  8979. break;
  8980. case ScriptBaseClass.PRIM_SLICE:
  8981. if (remain < 1)
  8982. return new LSL_List();
  8983. LSL_Vector slice;
  8984. try
  8985. {
  8986. slice = rules.GetVector3Item(idx++);
  8987. }
  8988. catch(InvalidCastException)
  8989. {
  8990. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8991. return new LSL_List();
  8992. }
  8993. part.UpdateSlice((float)slice.x, (float)slice.y);
  8994. break;
  8995. case ScriptBaseClass.PRIM_SIT_TARGET:
  8996. if (remain < 3)
  8997. return new LSL_List();
  8998. int active;
  8999. try
  9000. {
  9001. active = rules.GetLSLIntegerItem(idx++);
  9002. }
  9003. catch(InvalidCastException)
  9004. {
  9005. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  9006. return new LSL_List();
  9007. }
  9008. LSL_Vector offset;
  9009. try
  9010. {
  9011. offset = rules.GetVector3Item(idx++);
  9012. }
  9013. catch(InvalidCastException)
  9014. {
  9015. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9016. return new LSL_List();
  9017. }
  9018. LSL_Rotation sitrot;
  9019. try
  9020. {
  9021. sitrot = rules.GetQuaternionItem(idx++);
  9022. }
  9023. catch(InvalidCastException)
  9024. {
  9025. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 3 must be rotation", rulesParsed, idx - idxStart - 1));
  9026. return new LSL_List();
  9027. }
  9028. // not SL compatible since we don't have a independent flag to control active target but use the values of offset and rotation
  9029. if(active == 1)
  9030. {
  9031. if(offset.x == 0 && offset.y == 0 && offset.z == 0 && sitrot.s == 1.0)
  9032. offset.z = 1e-5f; // hack
  9033. SitTarget(part,offset,sitrot);
  9034. }
  9035. else if(active == 0)
  9036. SitTarget(part, Vector3.Zero , Quaternion.Identity);
  9037. break;
  9038. case ScriptBaseClass.PRIM_ALPHA_MODE:
  9039. if (remain < 3)
  9040. return new LSL_List();
  9041. try
  9042. {
  9043. face = rules.GetLSLIntegerItem(idx++);
  9044. }
  9045. catch(InvalidCastException)
  9046. {
  9047. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9048. return new LSL_List();
  9049. }
  9050. int materialAlphaMode;
  9051. try
  9052. {
  9053. materialAlphaMode = rules.GetLSLIntegerItem(idx++);
  9054. }
  9055. catch(InvalidCastException)
  9056. {
  9057. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9058. return new LSL_List();
  9059. }
  9060. if(materialAlphaMode < 0 || materialAlphaMode > 3)
  9061. {
  9062. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 3", rulesParsed, idx - idxStart - 1));
  9063. return new LSL_List();
  9064. }
  9065. int materialMaskCutoff;
  9066. try
  9067. {
  9068. materialMaskCutoff = rules.GetLSLIntegerItem(idx++);
  9069. }
  9070. catch(InvalidCastException)
  9071. {
  9072. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9073. return new LSL_List();
  9074. }
  9075. if(materialMaskCutoff < 0 || materialMaskCutoff > 255)
  9076. {
  9077. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 255", rulesParsed, idx - idxStart - 1));
  9078. return new LSL_List();
  9079. }
  9080. materialChanged |= SetMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9081. break;
  9082. case ScriptBaseClass.PRIM_NORMAL:
  9083. if (remain < 5)
  9084. return new LSL_List();
  9085. try
  9086. {
  9087. face = rules.GetLSLIntegerItem(idx++);
  9088. }
  9089. catch(InvalidCastException)
  9090. {
  9091. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9092. return new LSL_List();
  9093. }
  9094. string mapname = rules.Data[idx++].ToString();
  9095. UUID mapID = UUID.Zero;
  9096. if (!string.IsNullOrEmpty(mapname))
  9097. {
  9098. mapID = ScriptUtils.GetAssetIdFromItemName(m_host, mapname, (int)AssetType.Texture);
  9099. if (mapID == UUID.Zero)
  9100. {
  9101. if (!UUID.TryParse(mapname, out mapID))
  9102. {
  9103. 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));
  9104. return new LSL_List();
  9105. }
  9106. }
  9107. }
  9108. LSL_Vector mnrepeat;
  9109. try
  9110. {
  9111. mnrepeat = rules.GetVector3Item(idx++);
  9112. }
  9113. catch(InvalidCastException)
  9114. {
  9115. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9116. return new LSL_List();
  9117. }
  9118. LSL_Vector mnoffset;
  9119. try
  9120. {
  9121. mnoffset = rules.GetVector3Item(idx++);
  9122. }
  9123. catch(InvalidCastException)
  9124. {
  9125. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9126. return new LSL_List();
  9127. }
  9128. LSL_Float mnrot;
  9129. try
  9130. {
  9131. mnrot = rules.GetLSLFloatItem(idx++);
  9132. }
  9133. catch(InvalidCastException)
  9134. {
  9135. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9136. return new LSL_List();
  9137. }
  9138. float repeatX = (float)Util.Clamp(mnrepeat.x,-100.0, 100.0);
  9139. float repeatY = (float)Util.Clamp(mnrepeat.y,-100.0, 100.0);
  9140. float offsetX = (float)Util.Clamp(mnoffset.x, 0, 1.0);
  9141. float offsetY = (float)Util.Clamp(mnoffset.y, 0, 1.0);
  9142. materialChanged |= SetMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, (float)mnrot);
  9143. break;
  9144. case ScriptBaseClass.PRIM_SPECULAR:
  9145. if (remain < 8)
  9146. return new LSL_List();
  9147. try
  9148. {
  9149. face = rules.GetLSLIntegerItem(idx++);
  9150. }
  9151. catch(InvalidCastException)
  9152. {
  9153. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9154. return new LSL_List();
  9155. }
  9156. string smapname = rules.Data[idx++].ToString();
  9157. UUID smapID = UUID.Zero;
  9158. if(!string.IsNullOrEmpty(smapname))
  9159. {
  9160. smapID = ScriptUtils.GetAssetIdFromItemName(m_host, smapname, (int)AssetType.Texture);
  9161. if (smapID == UUID.Zero)
  9162. {
  9163. if (!UUID.TryParse(smapname, out smapID))
  9164. {
  9165. 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));
  9166. return new LSL_List();
  9167. }
  9168. }
  9169. }
  9170. LSL_Vector msrepeat;
  9171. try
  9172. {
  9173. msrepeat = rules.GetVector3Item(idx++);
  9174. }
  9175. catch(InvalidCastException)
  9176. {
  9177. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9178. return new LSL_List();
  9179. }
  9180. LSL_Vector msoffset;
  9181. try
  9182. {
  9183. msoffset = rules.GetVector3Item(idx++);
  9184. }
  9185. catch(InvalidCastException)
  9186. {
  9187. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9188. return new LSL_List();
  9189. }
  9190. LSL_Float msrot;
  9191. try
  9192. {
  9193. msrot = rules.GetLSLFloatItem(idx++);
  9194. }
  9195. catch(InvalidCastException)
  9196. {
  9197. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9198. return new LSL_List();
  9199. }
  9200. LSL_Vector mscolor;
  9201. try
  9202. {
  9203. mscolor = rules.GetVector3Item(idx++);
  9204. }
  9205. catch(InvalidCastException)
  9206. {
  9207. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9208. return new LSL_List();
  9209. }
  9210. LSL_Integer msgloss;
  9211. try
  9212. {
  9213. msgloss = rules.GetLSLIntegerItem(idx++);
  9214. }
  9215. catch(InvalidCastException)
  9216. {
  9217. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9218. return new LSL_List();
  9219. }
  9220. LSL_Integer msenv;
  9221. try
  9222. {
  9223. msenv = rules.GetLSLIntegerItem(idx++);
  9224. }
  9225. catch(InvalidCastException)
  9226. {
  9227. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9228. return new LSL_List();
  9229. }
  9230. float srepeatX = (float)Util.Clamp(msrepeat.x, -100.0, 100.0);
  9231. float srepeatY = (float)Util.Clamp(msrepeat.y, -100.0, 100.0);
  9232. float soffsetX = (float)Util.Clamp(msoffset.x, -1.0, 1.0);
  9233. float soffsetY = (float)Util.Clamp(msoffset.y, -1.0, 1.0);
  9234. byte colorR = (byte)(255.0 * Util.Clamp(mscolor.x, 0, 1.0) + 0.5);
  9235. byte colorG = (byte)(255.0 * Util.Clamp(mscolor.y, 0, 1.0) + 0.5);
  9236. byte colorB = (byte)(255.0 * Util.Clamp(mscolor.z, 0, 1.0) + 0.5);
  9237. byte gloss = (byte)Util.Clamp((int)msgloss, 0, 255);
  9238. byte env = (byte)Util.Clamp((int)msenv, 0, 255);
  9239. materialChanged |= SetMaterialSpecMap(part, face, smapID, srepeatX, srepeatY, soffsetX, soffsetY,
  9240. (float)msrot, colorR, colorG, colorB, gloss, env);
  9241. break;
  9242. case ScriptBaseClass.PRIM_LINK_TARGET:
  9243. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9244. return new LSL_List();
  9245. return rules.GetSublist(idx, -1);
  9246. default:
  9247. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
  9248. return new LSL_List();
  9249. }
  9250. }
  9251. }
  9252. catch (InvalidCastException e)
  9253. {
  9254. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9255. }
  9256. finally
  9257. {
  9258. if (positionChanged)
  9259. {
  9260. if (part.ParentGroup.RootPart == part)
  9261. {
  9262. SceneObjectGroup parent = part.ParentGroup;
  9263. // Util.FireAndForget(delegate(object x) {
  9264. parent.UpdateGroupPosition(currentPosition);
  9265. // });
  9266. }
  9267. else
  9268. {
  9269. part.OffsetPosition = currentPosition;
  9270. // SceneObjectGroup parent = part.ParentGroup;
  9271. // parent.HasGroupChanged = true;
  9272. // parent.ScheduleGroupForTerseUpdate();
  9273. part.ScheduleTerseUpdate();
  9274. }
  9275. }
  9276. if(materialChanged)
  9277. {
  9278. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  9279. {
  9280. part.TriggerScriptChangedEvent(Changed.TEXTURE);
  9281. part.ScheduleFullUpdate();
  9282. part.ParentGroup.HasGroupChanged = true;
  9283. }
  9284. }
  9285. }
  9286. return new LSL_List();
  9287. }
  9288. protected bool SetMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9289. {
  9290. if(m_materialsModule == null)
  9291. return false;
  9292. int nsides = part.GetNumberOfSides();
  9293. if(face == ScriptBaseClass.ALL_SIDES)
  9294. {
  9295. bool changed = false;
  9296. for(int i = 0; i < nsides; i++)
  9297. changed |= SetFaceMaterialAlphaMode(part, i, materialAlphaMode, materialMaskCutoff);
  9298. return changed;
  9299. }
  9300. if( face >= 0 && face < nsides)
  9301. return SetFaceMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9302. return false;
  9303. }
  9304. protected bool SetFaceMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9305. {
  9306. Primitive.TextureEntry tex = part.Shape.Textures;
  9307. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9308. if(texface == null)
  9309. return false;
  9310. FaceMaterial mat = null;
  9311. UUID oldid = texface.MaterialID;
  9312. if (oldid == UUID.Zero)
  9313. {
  9314. if (materialAlphaMode == 1)
  9315. return false;
  9316. }
  9317. else
  9318. mat = m_materialsModule.GetMaterialCopy(oldid);
  9319. if(mat == null)
  9320. mat = new FaceMaterial();
  9321. mat.DiffuseAlphaMode = (byte)materialAlphaMode;
  9322. mat.AlphaMaskCutoff = (byte)materialMaskCutoff;
  9323. UUID id = m_materialsModule.AddNewMaterial(mat); // id is a hash of entire material hash, so this means no change
  9324. if(oldid == id)
  9325. return false;
  9326. texface.MaterialID = id;
  9327. part.Shape.TextureEntry = tex.GetBytes(9);
  9328. m_materialsModule.RemoveMaterial(oldid);
  9329. return true;
  9330. }
  9331. protected bool SetMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9332. float offsetX, float offsetY, float rot)
  9333. {
  9334. if(m_materialsModule == null)
  9335. return false;
  9336. int nsides = part.GetNumberOfSides();
  9337. if(face == ScriptBaseClass.ALL_SIDES)
  9338. {
  9339. bool changed = false;
  9340. for(int i = 0; i < nsides; i++)
  9341. changed |= SetFaceMaterialNormalMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9342. return changed;
  9343. }
  9344. if( face >= 0 && face < nsides)
  9345. return SetFaceMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9346. return false;
  9347. }
  9348. protected bool SetFaceMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9349. float offsetX, float offsetY, float rot)
  9350. {
  9351. Primitive.TextureEntry tex = part.Shape.Textures;
  9352. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9353. if(texface == null)
  9354. return false;
  9355. FaceMaterial mat = null;
  9356. UUID oldid = texface.MaterialID;
  9357. if (oldid == UUID.Zero)
  9358. {
  9359. if (mapID == UUID.Zero)
  9360. return false;
  9361. }
  9362. else
  9363. mat = m_materialsModule.GetMaterialCopy(oldid);
  9364. if(mat == null)
  9365. mat = new FaceMaterial();
  9366. mat.NormalMapID = mapID;
  9367. mat.NormalOffsetX = offsetX;
  9368. mat.NormalOffsetY = offsetY;
  9369. mat.NormalRepeatX = repeatX;
  9370. mat.NormalRepeatY = repeatY;
  9371. mat.NormalRotation = rot;
  9372. mapID = m_materialsModule.AddNewMaterial(mat);
  9373. if(oldid == mapID)
  9374. return false;
  9375. texface.MaterialID = mapID;
  9376. part.Shape.TextureEntry = tex.GetBytes(9);
  9377. m_materialsModule.RemoveMaterial(oldid);
  9378. return true;
  9379. }
  9380. protected bool SetMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9381. float offsetX, float offsetY, float rot,
  9382. byte colorR, byte colorG, byte colorB,
  9383. byte gloss, byte env)
  9384. {
  9385. if(m_materialsModule == null)
  9386. return false;
  9387. int nsides = part.GetNumberOfSides();
  9388. if(face == ScriptBaseClass.ALL_SIDES)
  9389. {
  9390. bool changed = false;
  9391. for(int i = 0; i < nsides; i++)
  9392. changed |= SetFaceMaterialSpecMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9393. colorR, colorG, colorB, gloss, env);
  9394. return changed;
  9395. }
  9396. if( face >= 0 && face < nsides)
  9397. return SetFaceMaterialSpecMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9398. colorR, colorG, colorB, gloss, env);
  9399. return false;
  9400. }
  9401. protected bool SetFaceMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9402. float offsetX, float offsetY, float rot,
  9403. byte colorR, byte colorG, byte colorB,
  9404. byte gloss, byte env)
  9405. {
  9406. Primitive.TextureEntry tex = part.Shape.Textures;
  9407. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9408. if(texface == null)
  9409. return false;
  9410. FaceMaterial mat = null;
  9411. UUID oldid = texface.MaterialID;
  9412. if(oldid == UUID.Zero)
  9413. {
  9414. if(mapID == UUID.Zero)
  9415. return false;
  9416. }
  9417. else
  9418. mat = m_materialsModule.GetMaterialCopy(oldid);
  9419. if (mat == null)
  9420. mat = new FaceMaterial();
  9421. mat.SpecularMapID = mapID;
  9422. mat.SpecularOffsetX = offsetX;
  9423. mat.SpecularOffsetY = offsetY;
  9424. mat.SpecularRepeatX = repeatX;
  9425. mat.SpecularRepeatY = repeatY;
  9426. mat.SpecularRotation = rot;
  9427. mat.SpecularLightColorR = colorR;
  9428. mat.SpecularLightColorG = colorG;
  9429. mat.SpecularLightColorB = colorB;
  9430. mat.SpecularLightExponent = gloss;
  9431. mat.EnvironmentIntensity = env;
  9432. mapID = m_materialsModule.AddNewMaterial(mat);
  9433. if(oldid == mapID)
  9434. return false;
  9435. texface.MaterialID = mapID;
  9436. part.Shape.TextureEntry = tex.GetBytes(9);
  9437. m_materialsModule.RemoveMaterial(oldid);
  9438. return true;
  9439. }
  9440. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  9441. {
  9442. int idx = 0;
  9443. int idxStart = 0;
  9444. try
  9445. {
  9446. while (idx < rules.Length)
  9447. {
  9448. ++rulesParsed;
  9449. int code = rules.GetLSLIntegerItem(idx++);
  9450. int remain = rules.Length - idx;
  9451. idxStart = idx;
  9452. switch (code)
  9453. {
  9454. case ScriptBaseClass.PRIM_POSITION:
  9455. case ScriptBaseClass.PRIM_POS_LOCAL:
  9456. if (remain < 1)
  9457. return new LSL_List();
  9458. try
  9459. {
  9460. sp.OffsetPosition = rules.GetVector3Item(idx++);
  9461. }
  9462. catch(InvalidCastException)
  9463. {
  9464. if (code == ScriptBaseClass.PRIM_POSITION)
  9465. {
  9466. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9467. }
  9468. else
  9469. {
  9470. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9471. }
  9472. return new LSL_List();
  9473. }
  9474. break;
  9475. case ScriptBaseClass.PRIM_ROTATION:
  9476. if (remain < 1)
  9477. return new LSL_List();
  9478. Quaternion inRot;
  9479. try
  9480. {
  9481. inRot = rules.GetQuaternionItem(idx++);
  9482. }
  9483. catch(InvalidCastException)
  9484. {
  9485. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9486. return new LSL_List();
  9487. }
  9488. SceneObjectPart parentPart = sp.ParentPart;
  9489. if (parentPart != null)
  9490. sp.Rotation = m_host.GetWorldRotation() * inRot;
  9491. break;
  9492. case ScriptBaseClass.PRIM_ROT_LOCAL:
  9493. if (remain < 1)
  9494. return new LSL_List();
  9495. try
  9496. {
  9497. sp.Rotation = rules.GetQuaternionItem(idx++);
  9498. }
  9499. catch(InvalidCastException)
  9500. {
  9501. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9502. return new LSL_List();
  9503. }
  9504. break;
  9505. case ScriptBaseClass.PRIM_TYPE:
  9506. Error(originFunc, "PRIM_TYPE disallowed on agent");
  9507. return new LSL_List();
  9508. case ScriptBaseClass.PRIM_OMEGA:
  9509. Error(originFunc, "PRIM_OMEGA disallowed on agent");
  9510. return new LSL_List();
  9511. case ScriptBaseClass.PRIM_LINK_TARGET:
  9512. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9513. return new LSL_List();
  9514. return rules.GetSublist(idx, -1);
  9515. default:
  9516. Error(originFunc,
  9517. string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
  9518. return new LSL_List();
  9519. }
  9520. }
  9521. }
  9522. catch (InvalidCastException e)
  9523. {
  9524. Error(
  9525. originFunc,
  9526. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9527. }
  9528. return new LSL_List();
  9529. }
  9530. public LSL_String llStringToBase64(string str)
  9531. {
  9532. m_host.AddScriptLPS(1);
  9533. try
  9534. {
  9535. byte[] encData_byte;
  9536. encData_byte = Util.UTF8.GetBytes(str);
  9537. string encodedData = Convert.ToBase64String(encData_byte);
  9538. return encodedData;
  9539. }
  9540. catch
  9541. {
  9542. Error("llBase64ToString", "Error encoding string");
  9543. return String.Empty;
  9544. }
  9545. }
  9546. public LSL_String llBase64ToString(string str)
  9547. {
  9548. m_host.AddScriptLPS(1);
  9549. try
  9550. {
  9551. byte[] b = Convert.FromBase64String(str);
  9552. return Encoding.UTF8.GetString(b);
  9553. }
  9554. catch
  9555. {
  9556. Error("llBase64ToString", "Error decoding string");
  9557. return String.Empty;
  9558. }
  9559. }
  9560. public LSL_String llXorBase64Strings(string str1, string str2)
  9561. {
  9562. int padding = 0;
  9563. string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  9564. ScriptSleep(300);
  9565. m_host.AddScriptLPS(1);
  9566. if (str1 == String.Empty)
  9567. return String.Empty;
  9568. if (str2 == String.Empty)
  9569. return str1;
  9570. int len = str2.Length;
  9571. if ((len % 4) != 0) // LL is EVIL!!!!
  9572. {
  9573. while (str2.EndsWith("="))
  9574. str2 = str2.Substring(0, str2.Length - 1);
  9575. len = str2.Length;
  9576. int mod = len % 4;
  9577. if (mod == 1)
  9578. str2 = str2.Substring(0, str2.Length - 1);
  9579. else if (mod == 2)
  9580. str2 += "==";
  9581. else if (mod == 3)
  9582. str2 += "=";
  9583. }
  9584. byte[] data1;
  9585. byte[] data2;
  9586. try
  9587. {
  9588. data1 = Convert.FromBase64String(str1);
  9589. data2 = Convert.FromBase64String(str2);
  9590. }
  9591. catch (Exception)
  9592. {
  9593. return new LSL_String(String.Empty);
  9594. }
  9595. // For cases where the decoded length of s2 is greater
  9596. // than the decoded length of s1, simply perform a normal
  9597. // decode and XOR
  9598. //
  9599. /*
  9600. if (data2.Length >= data1.Length)
  9601. {
  9602. for (int pos = 0 ; pos < data1.Length ; pos++ )
  9603. data1[pos] ^= data2[pos];
  9604. return Convert.ToBase64String(data1);
  9605. }
  9606. */
  9607. // Remove padding
  9608. while (str1.EndsWith("="))
  9609. {
  9610. str1 = str1.Substring(0, str1.Length - 1);
  9611. padding++;
  9612. }
  9613. while (str2.EndsWith("="))
  9614. str2 = str2.Substring(0, str2.Length - 1);
  9615. byte[] d1 = new byte[str1.Length];
  9616. byte[] d2 = new byte[str2.Length];
  9617. for (int i = 0 ; i < str1.Length ; i++)
  9618. {
  9619. int idx = b64.IndexOf(str1.Substring(i, 1));
  9620. if (idx == -1)
  9621. idx = 0;
  9622. d1[i] = (byte)idx;
  9623. }
  9624. for (int i = 0 ; i < str2.Length ; i++)
  9625. {
  9626. int idx = b64.IndexOf(str2.Substring(i, 1));
  9627. if (idx == -1)
  9628. idx = 0;
  9629. d2[i] = (byte)idx;
  9630. }
  9631. string output = String.Empty;
  9632. for (int pos = 0 ; pos < d1.Length ; pos++)
  9633. output += b64[d1[pos] ^ d2[pos % d2.Length]];
  9634. // Here's a funny thing: LL blithely violate the base64
  9635. // standard pretty much everywhere. Here, padding is
  9636. // added only if the first input string had it, rather
  9637. // than when the data actually needs it. This can result
  9638. // in invalid base64 being returned. Go figure.
  9639. while (padding-- > 0)
  9640. output += "=";
  9641. return output;
  9642. }
  9643. public void llRemoteDataSetRegion()
  9644. {
  9645. m_host.AddScriptLPS(1);
  9646. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  9647. }
  9648. public LSL_Float llLog10(double val)
  9649. {
  9650. m_host.AddScriptLPS(1);
  9651. return (double)Math.Log10(val);
  9652. }
  9653. public LSL_Float llLog(double val)
  9654. {
  9655. m_host.AddScriptLPS(1);
  9656. return (double)Math.Log(val);
  9657. }
  9658. public LSL_List llGetAnimationList(LSL_Key id)
  9659. {
  9660. m_host.AddScriptLPS(1);
  9661. if(!UUID.TryParse(id, out UUID avID))
  9662. return new LSL_List();
  9663. ScenePresence av = World.GetScenePresence(avID);
  9664. if (av == null || av.IsChildAgent) // only if in the region
  9665. return new LSL_List();
  9666. UUID[] anims;
  9667. anims = av.Animator.GetAnimationArray();
  9668. LSL_List l = new LSL_List();
  9669. foreach (UUID foo in anims)
  9670. l.Add(new LSL_Key(foo.ToString()));
  9671. return l;
  9672. }
  9673. public void llSetParcelMusicURL(string url)
  9674. {
  9675. m_host.AddScriptLPS(1);
  9676. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9677. if (land.LandData.OwnerID != m_host.OwnerID)
  9678. return;
  9679. land.SetMusicUrl(url);
  9680. ScriptSleep(m_sleepMsOnSetParcelMusicURL);
  9681. }
  9682. public LSL_String llGetParcelMusicURL()
  9683. {
  9684. m_host.AddScriptLPS(1);
  9685. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9686. if (land.LandData.OwnerID != m_host.OwnerID)
  9687. return String.Empty;
  9688. return land.GetMusicUrl();
  9689. }
  9690. public LSL_Vector llGetRootPosition()
  9691. {
  9692. m_host.AddScriptLPS(1);
  9693. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  9694. }
  9695. /// <summary>
  9696. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  9697. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  9698. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  9699. /// In the root prim:-
  9700. /// Returns the object rotation if not attached
  9701. /// Returns the avatars rotation if attached
  9702. /// Returns the camera rotation if attached and the avatar is in mouselook
  9703. /// </summary>
  9704. public LSL_Rotation llGetRootRotation()
  9705. {
  9706. m_host.AddScriptLPS(1);
  9707. Quaternion q;
  9708. if (m_host.ParentGroup.AttachmentPoint != 0)
  9709. {
  9710. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  9711. if (avatar != null)
  9712. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  9713. q = avatar.CameraRotation; // Mouselook
  9714. else
  9715. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  9716. else
  9717. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  9718. }
  9719. else
  9720. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  9721. return new LSL_Rotation(q);
  9722. }
  9723. public LSL_String llGetObjectDesc()
  9724. {
  9725. return m_host.Description ?? String.Empty;
  9726. }
  9727. public void llSetObjectDesc(string desc)
  9728. {
  9729. m_host.AddScriptLPS(1);
  9730. m_host.Description = desc ?? String.Empty;
  9731. }
  9732. public LSL_Key llGetCreator()
  9733. {
  9734. m_host.AddScriptLPS(1);
  9735. return m_host.CreatorID.ToString();
  9736. }
  9737. public LSL_String llGetTimestamp()
  9738. {
  9739. m_host.AddScriptLPS(1);
  9740. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  9741. }
  9742. public LSL_Integer llGetNumberOfPrims()
  9743. {
  9744. m_host.AddScriptLPS(1);
  9745. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  9746. }
  9747. /// <summary>
  9748. /// Full implementation of llGetBoundingBox according to SL 2015-04-15.
  9749. /// http://wiki.secondlife.com/wiki/LlGetBoundingBox
  9750. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  9751. /// Returns local bounding box of avatar without attachments
  9752. /// if target is non-seated avatar or prim/mesh in avatar attachment.
  9753. /// Returns local bounding box of object
  9754. /// if target is seated avatar or prim/mesh in object.
  9755. /// Uses less accurate box models for speed.
  9756. /// </summary>
  9757. public LSL_List llGetBoundingBox(string obj)
  9758. {
  9759. m_host.AddScriptLPS(1);
  9760. UUID objID = UUID.Zero;
  9761. LSL_List result = new LSL_List();
  9762. // If the ID is not valid, return null result
  9763. if (!UUID.TryParse(obj, out objID))
  9764. {
  9765. result.Add(new LSL_Vector());
  9766. result.Add(new LSL_Vector());
  9767. return result;
  9768. }
  9769. // Check if this is an attached prim. If so, replace
  9770. // the UUID with the avatar UUID and report it's bounding box
  9771. SceneObjectPart part = World.GetSceneObjectPart(objID);
  9772. if (part != null && part.ParentGroup.IsAttachment)
  9773. objID = part.ParentGroup.AttachedAvatar;
  9774. // Find out if this is an avatar ID. If so, return it's box
  9775. ScenePresence presence = World.GetScenePresence(objID);
  9776. if (presence != null)
  9777. {
  9778. LSL_Vector lower;
  9779. LSL_Vector upper;
  9780. Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
  9781. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  9782. == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  9783. {
  9784. // This is for ground sitting avatars TODO!
  9785. lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
  9786. upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
  9787. }
  9788. else
  9789. {
  9790. // This is for standing/flying avatars
  9791. lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
  9792. upper = new LSL_Vector(box.X, box.Y, box.Z);
  9793. }
  9794. if (lower.x > upper.x)
  9795. lower.x = upper.x;
  9796. if (lower.y > upper.y)
  9797. lower.y = upper.y;
  9798. if (lower.z > upper.z)
  9799. lower.z = upper.z;
  9800. result.Add(lower);
  9801. result.Add(upper);
  9802. return result;
  9803. }
  9804. part = World.GetSceneObjectPart(objID);
  9805. // Currently only works for single prims without a sitting avatar
  9806. if (part == null)
  9807. {
  9808. result.Add(new LSL_Vector());
  9809. result.Add(new LSL_Vector());
  9810. return result;
  9811. }
  9812. SceneObjectGroup sog = part.ParentGroup;
  9813. if(sog.IsDeleted)
  9814. {
  9815. result.Add(new LSL_Vector());
  9816. result.Add(new LSL_Vector());
  9817. return result;
  9818. }
  9819. sog.GetBoundingBox(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ);
  9820. result.Add(new LSL_Vector(minX, minY, minZ));
  9821. result.Add(new LSL_Vector(maxX, maxY, maxZ));
  9822. return result;
  9823. }
  9824. /// <summary>
  9825. /// Helper to calculate bounding box of an avatar.
  9826. /// </summary>
  9827. private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper)
  9828. {
  9829. // Adjust from OS model
  9830. // avatar height = visual height - 0.2, bounding box height = visual height
  9831. // to SL model
  9832. // avatar height = visual height, bounding box height = visual height + 0.2
  9833. float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection;
  9834. // According to avatar bounding box in SL 2015-04-18:
  9835. // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h>
  9836. // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5>
  9837. // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h>
  9838. // When avatar is sitting
  9839. if (sp.ParentPart != null)
  9840. {
  9841. lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height);
  9842. upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height);
  9843. }
  9844. // When avatar is groundsitting
  9845. else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  9846. {
  9847. lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height);
  9848. upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height);
  9849. }
  9850. // When avatar is standing or flying
  9851. else
  9852. {
  9853. lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
  9854. upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
  9855. }
  9856. }
  9857. public LSL_Vector llGetGeometricCenter()
  9858. {
  9859. return new LSL_Vector(m_host.GetGeometricCenter());
  9860. }
  9861. public LSL_List llGetPrimitiveParams(LSL_List rules)
  9862. {
  9863. m_host.AddScriptLPS(1);
  9864. LSL_List result = new LSL_List();
  9865. LSL_List remaining = GetPrimParams(m_host, rules, ref result);
  9866. while (!(remaining is null) && remaining.Length > 1)
  9867. {
  9868. int linknumber = remaining.GetLSLIntegerItem(0);
  9869. rules = remaining.GetSublist(1, -1);
  9870. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  9871. if(parts.Count == 0)
  9872. break;
  9873. foreach (SceneObjectPart part in parts)
  9874. remaining = GetPrimParams(part, rules, ref result);
  9875. }
  9876. return result;
  9877. }
  9878. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  9879. {
  9880. m_host.AddScriptLPS(1);
  9881. // acording to SL wiki this must indicate a single link number or link_root or link_this.
  9882. // keep other options as before
  9883. List<SceneObjectPart> parts;
  9884. List<ScenePresence> avatars;
  9885. LSL_List res = new LSL_List();
  9886. LSL_List remaining = new LSL_List();
  9887. while (rules.Length > 0)
  9888. {
  9889. parts = GetLinkParts(linknumber);
  9890. avatars = GetLinkAvatars(linknumber);
  9891. remaining = new LSL_List();
  9892. foreach (SceneObjectPart part in parts)
  9893. {
  9894. remaining = GetPrimParams(part, rules, ref res);
  9895. }
  9896. foreach (ScenePresence avatar in avatars)
  9897. {
  9898. remaining = GetPrimParams(avatar, rules, ref res);
  9899. }
  9900. if (remaining.Length > 0)
  9901. {
  9902. linknumber = remaining.GetLSLIntegerItem(0);
  9903. rules = remaining.GetSublist(1, -1);
  9904. }
  9905. else
  9906. break;
  9907. }
  9908. return res;
  9909. }
  9910. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  9911. {
  9912. int idx = 0;
  9913. int face;
  9914. Primitive.TextureEntry tex;
  9915. int nsides = GetNumberOfSides(part);
  9916. while (idx < rules.Length)
  9917. {
  9918. int code = (int)rules.GetLSLIntegerItem(idx++);
  9919. int remain = rules.Length - idx;
  9920. switch (code)
  9921. {
  9922. case (int)ScriptBaseClass.PRIM_MATERIAL:
  9923. res.Add(new LSL_Integer(part.Material));
  9924. break;
  9925. case (int)ScriptBaseClass.PRIM_PHYSICS:
  9926. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  9927. res.Add(new LSL_Integer(1));
  9928. else
  9929. res.Add(new LSL_Integer(0));
  9930. break;
  9931. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  9932. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  9933. res.Add(new LSL_Integer(1));
  9934. else
  9935. res.Add(new LSL_Integer(0));
  9936. break;
  9937. case (int)ScriptBaseClass.PRIM_PHANTOM:
  9938. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  9939. res.Add(new LSL_Integer(1));
  9940. else
  9941. res.Add(new LSL_Integer(0));
  9942. break;
  9943. case (int)ScriptBaseClass.PRIM_POSITION:
  9944. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  9945. part.AbsolutePosition.Y,
  9946. part.AbsolutePosition.Z);
  9947. res.Add(v);
  9948. break;
  9949. case (int)ScriptBaseClass.PRIM_SIZE:
  9950. res.Add(new LSL_Vector(part.Scale));
  9951. break;
  9952. case (int)ScriptBaseClass.PRIM_ROTATION:
  9953. res.Add(GetPartRot(part));
  9954. break;
  9955. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  9956. res.Add(new LSL_Integer((int)part.PhysicsShapeType));
  9957. break;
  9958. case (int)ScriptBaseClass.PRIM_TYPE:
  9959. // implementing box
  9960. PrimitiveBaseShape Shape = part.Shape;
  9961. int primType = (int)part.GetPrimType();
  9962. res.Add(new LSL_Integer(primType));
  9963. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  9964. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  9965. switch (primType)
  9966. {
  9967. case ScriptBaseClass.PRIM_TYPE_BOX:
  9968. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  9969. case ScriptBaseClass.PRIM_TYPE_PRISM:
  9970. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9971. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9972. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9973. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9974. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9975. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9976. break;
  9977. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  9978. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9979. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9980. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9981. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9982. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9983. break;
  9984. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  9985. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  9986. res.Add(new LSL_Integer(Shape.SculptType));
  9987. break;
  9988. case ScriptBaseClass.PRIM_TYPE_RING:
  9989. case ScriptBaseClass.PRIM_TYPE_TUBE:
  9990. case ScriptBaseClass.PRIM_TYPE_TORUS:
  9991. // holeshape
  9992. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9993. // cut
  9994. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9995. // hollow
  9996. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9997. // twist
  9998. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9999. // vector holesize
  10000. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  10001. // vector topshear
  10002. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  10003. // vector profilecut
  10004. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  10005. // vector tapera
  10006. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  10007. // float revolutions
  10008. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  10009. // Slightly inaccurate, because an unsigned byte is being used to represent
  10010. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  10011. // SL does it).
  10012. //
  10013. // Using these formulas to store and retrieve PathRevolutions, it is not
  10014. // possible to use all values between 1.00 and 4.00. For instance, you can't
  10015. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  10016. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  10017. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  10018. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  10019. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  10020. // such as 1.10. So, SL must store and retreive the actual user input rather
  10021. // than only storing the encoded value.
  10022. // float radiusoffset
  10023. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  10024. // float skew
  10025. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  10026. break;
  10027. }
  10028. break;
  10029. case (int)ScriptBaseClass.PRIM_TEXTURE:
  10030. if (remain < 1)
  10031. return new LSL_List();
  10032. face = (int)rules.GetLSLIntegerItem(idx++);
  10033. tex = part.Shape.Textures;
  10034. if (face == ScriptBaseClass.ALL_SIDES)
  10035. {
  10036. for (face = 0; face < nsides; face++)
  10037. {
  10038. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10039. res.Add(new LSL_String(texface.TextureID.ToString()));
  10040. res.Add(new LSL_Vector(texface.RepeatU,
  10041. texface.RepeatV,
  10042. 0));
  10043. res.Add(new LSL_Vector(texface.OffsetU,
  10044. texface.OffsetV,
  10045. 0));
  10046. res.Add(new LSL_Float(texface.Rotation));
  10047. }
  10048. }
  10049. else
  10050. {
  10051. if (face >= 0 && face < nsides)
  10052. {
  10053. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10054. res.Add(new LSL_String(texface.TextureID.ToString()));
  10055. res.Add(new LSL_Vector(texface.RepeatU,
  10056. texface.RepeatV,
  10057. 0));
  10058. res.Add(new LSL_Vector(texface.OffsetU,
  10059. texface.OffsetV,
  10060. 0));
  10061. res.Add(new LSL_Float(texface.Rotation));
  10062. }
  10063. }
  10064. break;
  10065. case (int)ScriptBaseClass.PRIM_COLOR:
  10066. if (remain < 1)
  10067. return new LSL_List();
  10068. face = (int)rules.GetLSLIntegerItem(idx++);
  10069. tex = part.Shape.Textures;
  10070. Color4 texcolor;
  10071. if (face == ScriptBaseClass.ALL_SIDES)
  10072. {
  10073. for (face = 0; face < nsides; face++)
  10074. {
  10075. texcolor = tex.GetFace((uint)face).RGBA;
  10076. res.Add(new LSL_Vector(texcolor.R,
  10077. texcolor.G,
  10078. texcolor.B));
  10079. res.Add(new LSL_Float(texcolor.A));
  10080. }
  10081. }
  10082. else
  10083. {
  10084. texcolor = tex.GetFace((uint)face).RGBA;
  10085. res.Add(new LSL_Vector(texcolor.R,
  10086. texcolor.G,
  10087. texcolor.B));
  10088. res.Add(new LSL_Float(texcolor.A));
  10089. }
  10090. break;
  10091. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  10092. {
  10093. if (remain < 1)
  10094. return new LSL_List();
  10095. face = (int)rules.GetLSLIntegerItem(idx++);
  10096. tex = part.Shape.Textures;
  10097. int shiny;
  10098. if (face == ScriptBaseClass.ALL_SIDES)
  10099. {
  10100. for (face = 0; face < nsides; face++)
  10101. {
  10102. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10103. if (shinyness == Shininess.High)
  10104. {
  10105. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10106. }
  10107. else if (shinyness == Shininess.Medium)
  10108. {
  10109. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10110. }
  10111. else if (shinyness == Shininess.Low)
  10112. {
  10113. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10114. }
  10115. else
  10116. {
  10117. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10118. }
  10119. res.Add(new LSL_Integer(shiny));
  10120. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10121. }
  10122. }
  10123. else
  10124. {
  10125. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10126. if (shinyness == Shininess.High)
  10127. {
  10128. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10129. }
  10130. else if (shinyness == Shininess.Medium)
  10131. {
  10132. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10133. }
  10134. else if (shinyness == Shininess.Low)
  10135. {
  10136. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10137. }
  10138. else
  10139. {
  10140. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10141. }
  10142. res.Add(new LSL_Integer(shiny));
  10143. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10144. }
  10145. break;
  10146. }
  10147. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  10148. {
  10149. if (remain < 1)
  10150. return new LSL_List();
  10151. face = (int)rules.GetLSLIntegerItem(idx++);
  10152. tex = part.Shape.Textures;
  10153. int fullbright;
  10154. if (face == ScriptBaseClass.ALL_SIDES)
  10155. {
  10156. for (face = 0; face < nsides; face++)
  10157. {
  10158. if (tex.GetFace((uint)face).Fullbright == true)
  10159. {
  10160. fullbright = ScriptBaseClass.TRUE;
  10161. }
  10162. else
  10163. {
  10164. fullbright = ScriptBaseClass.FALSE;
  10165. }
  10166. res.Add(new LSL_Integer(fullbright));
  10167. }
  10168. }
  10169. else
  10170. {
  10171. if (tex.GetFace((uint)face).Fullbright == true)
  10172. {
  10173. fullbright = ScriptBaseClass.TRUE;
  10174. }
  10175. else
  10176. {
  10177. fullbright = ScriptBaseClass.FALSE;
  10178. }
  10179. res.Add(new LSL_Integer(fullbright));
  10180. }
  10181. break;
  10182. }
  10183. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  10184. PrimitiveBaseShape shape = part.Shape;
  10185. if (shape.FlexiEntry)
  10186. res.Add(new LSL_Integer(1)); // active
  10187. else
  10188. res.Add(new LSL_Integer(0));
  10189. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  10190. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  10191. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  10192. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  10193. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  10194. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  10195. shape.FlexiForceY,
  10196. shape.FlexiForceZ));
  10197. break;
  10198. case (int)ScriptBaseClass.PRIM_TEXGEN:
  10199. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  10200. if (remain < 1)
  10201. return new LSL_List();
  10202. face = (int)rules.GetLSLIntegerItem(idx++);
  10203. tex = part.Shape.Textures;
  10204. if (face == ScriptBaseClass.ALL_SIDES)
  10205. {
  10206. for (face = 0; face < nsides; face++)
  10207. {
  10208. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10209. {
  10210. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10211. }
  10212. else
  10213. {
  10214. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10215. }
  10216. }
  10217. }
  10218. else
  10219. {
  10220. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10221. {
  10222. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10223. }
  10224. else
  10225. {
  10226. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10227. }
  10228. }
  10229. break;
  10230. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  10231. shape = part.Shape;
  10232. if (shape.LightEntry)
  10233. res.Add(new LSL_Integer(1)); // active
  10234. else
  10235. res.Add(new LSL_Integer(0));
  10236. res.Add(new LSL_Vector(shape.LightColorR, // color
  10237. shape.LightColorG,
  10238. shape.LightColorB));
  10239. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  10240. res.Add(new LSL_Float(shape.LightRadius)); // radius
  10241. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  10242. break;
  10243. case (int)ScriptBaseClass.PRIM_GLOW:
  10244. if (remain < 1)
  10245. return new LSL_List();
  10246. face = (int)rules.GetLSLIntegerItem(idx++);
  10247. tex = part.Shape.Textures;
  10248. float primglow;
  10249. if (face == ScriptBaseClass.ALL_SIDES)
  10250. {
  10251. for (face = 0; face < nsides; face++)
  10252. {
  10253. primglow = tex.GetFace((uint)face).Glow;
  10254. res.Add(new LSL_Float(primglow));
  10255. }
  10256. }
  10257. else
  10258. {
  10259. primglow = tex.GetFace((uint)face).Glow;
  10260. res.Add(new LSL_Float(primglow));
  10261. }
  10262. break;
  10263. case (int)ScriptBaseClass.PRIM_TEXT:
  10264. Color4 textColor = part.GetTextColor();
  10265. res.Add(new LSL_String(part.Text));
  10266. res.Add(new LSL_Vector(textColor.R,
  10267. textColor.G,
  10268. textColor.B));
  10269. res.Add(new LSL_Float(textColor.A));
  10270. break;
  10271. case (int)ScriptBaseClass.PRIM_NAME:
  10272. res.Add(new LSL_String(part.Name));
  10273. break;
  10274. case (int)ScriptBaseClass.PRIM_DESC:
  10275. res.Add(new LSL_String(part.Description));
  10276. break;
  10277. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  10278. res.Add(new LSL_Rotation(part.RotationOffset));
  10279. break;
  10280. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  10281. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  10282. break;
  10283. case (int)ScriptBaseClass.PRIM_SLICE:
  10284. PrimType prim_type = part.GetPrimType();
  10285. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  10286. res.Add(new LSL_Vector(
  10287. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  10288. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  10289. 0
  10290. ));
  10291. break;
  10292. case (int)ScriptBaseClass.PRIM_OMEGA:
  10293. // this may return values diferent from SL since we don't handle set the same way
  10294. float gain = 1.0f; // we don't use gain and don't store it
  10295. Vector3 axis = part.AngularVelocity;
  10296. float spin = axis.Length();
  10297. if(spin < 1.0e-6)
  10298. {
  10299. axis = Vector3.Zero;
  10300. gain = 0.0f;
  10301. spin = 0.0f;
  10302. }
  10303. else
  10304. {
  10305. axis = axis * (1.0f/spin);
  10306. }
  10307. res.Add(new LSL_Vector(axis.X,
  10308. axis.Y,
  10309. axis.Z));
  10310. res.Add(new LSL_Float(spin));
  10311. res.Add(new LSL_Float(gain));
  10312. break;
  10313. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  10314. if(part.IsSitTargetSet)
  10315. {
  10316. res.Add(new LSL_Integer(1));
  10317. res.Add(new LSL_Vector(part.SitTargetPosition));
  10318. res.Add(new LSL_Rotation(part.SitTargetOrientation));
  10319. }
  10320. else
  10321. {
  10322. res.Add(new LSL_Integer(0));
  10323. res.Add(new LSL_Vector(Vector3.Zero));
  10324. res.Add(new LSL_Rotation(Quaternion.Identity));
  10325. }
  10326. break;
  10327. case (int)ScriptBaseClass.PRIM_NORMAL:
  10328. case (int)ScriptBaseClass.PRIM_SPECULAR:
  10329. case (int)ScriptBaseClass.PRIM_ALPHA_MODE:
  10330. if (remain < 1)
  10331. return new LSL_List();
  10332. face = (int)rules.GetLSLIntegerItem(idx++);
  10333. tex = part.Shape.Textures;
  10334. if (face == ScriptBaseClass.ALL_SIDES)
  10335. {
  10336. for (face = 0; face < nsides; face++)
  10337. {
  10338. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10339. getLSLFaceMaterial(ref res, code, part, texface);
  10340. }
  10341. }
  10342. else
  10343. {
  10344. if (face >= 0 && face < nsides)
  10345. {
  10346. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10347. getLSLFaceMaterial(ref res, code, part, texface);
  10348. }
  10349. }
  10350. break;
  10351. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  10352. // TODO: Should be issuing a runtime script warning in this case.
  10353. if (remain < 2)
  10354. return new LSL_List();
  10355. return rules.GetSublist(idx, -1);
  10356. }
  10357. }
  10358. return new LSL_List();
  10359. }
  10360. private string GetMaterialTextureUUIDbyRights(UUID origID, SceneObjectPart part)
  10361. {
  10362. if(World.Permissions.CanEditObject(m_host.ParentGroup.UUID, m_host.ParentGroup.RootPart.OwnerID))
  10363. return origID.ToString();
  10364. lock(part.TaskInventory)
  10365. {
  10366. foreach(KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  10367. {
  10368. if(inv.Value.InvType == (int)InventoryType.Texture && inv.Value.AssetID == origID)
  10369. return origID.ToString();
  10370. }
  10371. }
  10372. return ScriptBaseClass.NULL_KEY;
  10373. }
  10374. private void getLSLFaceMaterial(ref LSL_List res, int code, SceneObjectPart part, Primitive.TextureEntryFace texface)
  10375. {
  10376. UUID matID = UUID.Zero;
  10377. if(m_materialsModule != null)
  10378. matID = texface.MaterialID;
  10379. if(matID != UUID.Zero)
  10380. {
  10381. FaceMaterial mat = m_materialsModule.GetMaterial(matID);
  10382. if(mat != null)
  10383. {
  10384. if(code == ScriptBaseClass.PRIM_NORMAL)
  10385. {
  10386. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.NormalMapID, part)));
  10387. res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0));
  10388. res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0));
  10389. res.Add(new LSL_Float(mat.NormalRotation));
  10390. }
  10391. else if(code == ScriptBaseClass.PRIM_SPECULAR)
  10392. {
  10393. const float colorScale = 1.0f / 255f;
  10394. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.SpecularMapID, part)));
  10395. res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0));
  10396. res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0));
  10397. res.Add(new LSL_Float(mat.SpecularRotation));
  10398. res.Add(new LSL_Vector(mat.SpecularLightColorR * colorScale,
  10399. mat.SpecularLightColorG * colorScale,
  10400. mat.SpecularLightColorB * colorScale));
  10401. res.Add(new LSL_Integer(mat.SpecularLightExponent));
  10402. res.Add(new LSL_Integer(mat.EnvironmentIntensity));
  10403. }
  10404. else if(code == ScriptBaseClass.PRIM_ALPHA_MODE)
  10405. {
  10406. res.Add(new LSL_Integer(mat.DiffuseAlphaMode));
  10407. res.Add(new LSL_Integer(mat.AlphaMaskCutoff));
  10408. }
  10409. return;
  10410. }
  10411. }
  10412. // material not found
  10413. if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10414. {
  10415. res.Add(new LSL_String(ScriptBaseClass.NULL_KEY));
  10416. res.Add(new LSL_Vector(1.0, 1.0, 0));
  10417. res.Add(new LSL_Vector(0, 0, 0));
  10418. res.Add(new LSL_Float(0));
  10419. if(code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10420. {
  10421. res.Add(new LSL_Vector(1.0, 1.0, 1.0));
  10422. res.Add(new LSL_Integer(51));
  10423. res.Add(new LSL_Integer(0));
  10424. }
  10425. }
  10426. else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE)
  10427. {
  10428. res.Add(new LSL_Integer(1));
  10429. res.Add(new LSL_Integer(0));
  10430. }
  10431. }
  10432. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  10433. {
  10434. m_host.AddScriptLPS(1);
  10435. ScriptSleep(m_sleepMsOnGetPrimMediaParams);
  10436. return GetPrimMediaParams(m_host, face, rules);
  10437. }
  10438. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10439. {
  10440. m_host.AddScriptLPS(1);
  10441. ScriptSleep(m_sleepMsOnGetLinkMedia);
  10442. if (link == ScriptBaseClass.LINK_ROOT)
  10443. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10444. else if (link == ScriptBaseClass.LINK_THIS)
  10445. return GetPrimMediaParams(m_host, face, rules);
  10446. else
  10447. {
  10448. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10449. if (null != part)
  10450. return GetPrimMediaParams(part, face, rules);
  10451. }
  10452. return new LSL_List();
  10453. }
  10454. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  10455. {
  10456. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  10457. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  10458. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  10459. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10460. return new LSL_List();
  10461. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10462. if (null == module)
  10463. return new LSL_List();
  10464. MediaEntry me = module.GetMediaEntry(part, face);
  10465. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  10466. if (null == me)
  10467. return new LSL_List();
  10468. LSL_List res = new LSL_List();
  10469. for (int i = 0; i < rules.Length; i++)
  10470. {
  10471. int code = (int)rules.GetLSLIntegerItem(i);
  10472. switch (code)
  10473. {
  10474. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10475. // Not implemented
  10476. res.Add(new LSL_Integer(0));
  10477. break;
  10478. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10479. if (me.Controls == MediaControls.Standard)
  10480. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  10481. else
  10482. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  10483. break;
  10484. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10485. res.Add(new LSL_String(me.CurrentURL));
  10486. break;
  10487. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10488. res.Add(new LSL_String(me.HomeURL));
  10489. break;
  10490. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10491. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10492. break;
  10493. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10494. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10495. break;
  10496. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10497. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10498. break;
  10499. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10500. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10501. break;
  10502. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10503. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10504. break;
  10505. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10506. res.Add(new LSL_Integer(me.Width));
  10507. break;
  10508. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10509. res.Add(new LSL_Integer(me.Height));
  10510. break;
  10511. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10512. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10513. break;
  10514. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10515. string[] urls = (string[])me.WhiteList.Clone();
  10516. for (int j = 0; j < urls.Length; j++)
  10517. urls[j] = Uri.EscapeDataString(urls[j]);
  10518. res.Add(new LSL_String(string.Join(", ", urls)));
  10519. break;
  10520. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10521. res.Add(new LSL_Integer((int)me.InteractPermissions));
  10522. break;
  10523. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10524. res.Add(new LSL_Integer((int)me.ControlPermissions));
  10525. break;
  10526. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10527. }
  10528. }
  10529. return res;
  10530. }
  10531. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  10532. {
  10533. m_host.AddScriptLPS(1);
  10534. ScriptSleep(m_sleepMsOnSetPrimMediaParams);
  10535. return SetPrimMediaParams(m_host, face, rules);
  10536. }
  10537. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10538. {
  10539. m_host.AddScriptLPS(1);
  10540. ScriptSleep(m_sleepMsOnSetLinkMedia);
  10541. if (link == ScriptBaseClass.LINK_ROOT)
  10542. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10543. else if (link == ScriptBaseClass.LINK_THIS)
  10544. return SetPrimMediaParams(m_host, face, rules);
  10545. else
  10546. {
  10547. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10548. if (null != part)
  10549. return SetPrimMediaParams(part, face, rules);
  10550. }
  10551. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10552. }
  10553. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  10554. {
  10555. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  10556. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10557. // Don't perform the media check directly
  10558. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10559. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10560. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10561. if (null == module)
  10562. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10563. MediaEntry me = module.GetMediaEntry(part, face);
  10564. if (null == me)
  10565. me = new MediaEntry();
  10566. int i = 0;
  10567. while (i < rules.Length - 1)
  10568. {
  10569. int code = rules.GetLSLIntegerItem(i++);
  10570. switch (code)
  10571. {
  10572. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10573. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  10574. break;
  10575. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10576. int v = rules.GetLSLIntegerItem(i++);
  10577. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  10578. me.Controls = MediaControls.Standard;
  10579. else
  10580. me.Controls = MediaControls.Mini;
  10581. break;
  10582. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10583. me.CurrentURL = rules.GetLSLStringItem(i++);
  10584. break;
  10585. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10586. me.HomeURL = rules.GetLSLStringItem(i++);
  10587. break;
  10588. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10589. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10590. break;
  10591. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10592. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10593. break;
  10594. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10595. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10596. break;
  10597. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10598. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10599. break;
  10600. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10601. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10602. break;
  10603. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10604. me.Width = (int)rules.GetLSLIntegerItem(i++);
  10605. break;
  10606. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10607. me.Height = (int)rules.GetLSLIntegerItem(i++);
  10608. break;
  10609. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10610. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10611. break;
  10612. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10613. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  10614. List<string> whiteListUrls = new List<string>();
  10615. Array.ForEach(
  10616. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  10617. me.WhiteList = whiteListUrls.ToArray();
  10618. break;
  10619. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10620. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10621. break;
  10622. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10623. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10624. break;
  10625. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10626. }
  10627. }
  10628. module.SetMediaEntry(part, face, me);
  10629. return ScriptBaseClass.LSL_STATUS_OK;
  10630. }
  10631. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  10632. {
  10633. m_host.AddScriptLPS(1);
  10634. ScriptSleep(m_sleepMsOnClearPrimMedia);
  10635. return ClearPrimMedia(m_host, face);
  10636. }
  10637. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  10638. {
  10639. m_host.AddScriptLPS(1);
  10640. ScriptSleep(m_sleepMsOnClearLinkMedia);
  10641. if (link == ScriptBaseClass.LINK_ROOT)
  10642. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  10643. else if (link == ScriptBaseClass.LINK_THIS)
  10644. return ClearPrimMedia(m_host, face);
  10645. else
  10646. {
  10647. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10648. if (null != part)
  10649. return ClearPrimMedia(part, face);
  10650. }
  10651. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10652. }
  10653. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  10654. {
  10655. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  10656. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10657. // FIXME: Don't perform the media check directly
  10658. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10659. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10660. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10661. if (null == module)
  10662. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10663. module.ClearMediaEntry(part, face);
  10664. return ScriptBaseClass.LSL_STATUS_OK;
  10665. }
  10666. // <remarks>
  10667. // <para>
  10668. // The .NET definition of base 64 is:
  10669. // <list>
  10670. // <item>
  10671. // Significant: A-Z a-z 0-9 + -
  10672. // </item>
  10673. // <item>
  10674. // Whitespace: \t \n \r ' '
  10675. // </item>
  10676. // <item>
  10677. // Valueless: =
  10678. // </item>
  10679. // <item>
  10680. // End-of-string: \0 or '=='
  10681. // </item>
  10682. // </list>
  10683. // </para>
  10684. // <para>
  10685. // Each point in a base-64 string represents
  10686. // a 6 bit value. A 32-bit integer can be
  10687. // represented using 6 characters (with some
  10688. // redundancy).
  10689. // </para>
  10690. // <para>
  10691. // LSL requires a base64 string to be 8
  10692. // characters in length. LSL also uses '/'
  10693. // rather than '-' (MIME compliant).
  10694. // </para>
  10695. // <para>
  10696. // RFC 1341 used as a reference (as specified
  10697. // by the SecondLife Wiki).
  10698. // </para>
  10699. // <para>
  10700. // SL do not record any kind of exception for
  10701. // these functions, so the string to integer
  10702. // conversion returns '0' if an invalid
  10703. // character is encountered during conversion.
  10704. // </para>
  10705. // <para>
  10706. // References
  10707. // <list>
  10708. // <item>
  10709. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  10710. // </item>
  10711. // <item>
  10712. // </item>
  10713. // </list>
  10714. // </para>
  10715. // </remarks>
  10716. // <summary>
  10717. // Table for converting 6-bit integers into
  10718. // base-64 characters
  10719. // </summary>
  10720. protected static readonly char[] i2ctable =
  10721. {
  10722. 'A','B','C','D','E','F','G','H',
  10723. 'I','J','K','L','M','N','O','P',
  10724. 'Q','R','S','T','U','V','W','X',
  10725. 'Y','Z',
  10726. 'a','b','c','d','e','f','g','h',
  10727. 'i','j','k','l','m','n','o','p',
  10728. 'q','r','s','t','u','v','w','x',
  10729. 'y','z',
  10730. '0','1','2','3','4','5','6','7',
  10731. '8','9',
  10732. '+','/'
  10733. };
  10734. // <summary>
  10735. // Table for converting base-64 characters
  10736. // into 6-bit integers.
  10737. // </summary>
  10738. protected static readonly int[] c2itable =
  10739. {
  10740. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  10741. -1,-1,-1,-1,-1,-1,-1,-1,
  10742. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  10743. -1,-1,-1,-1,-1,-1,-1,-1,
  10744. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  10745. -1,-1,-1,63,-1,-1,-1,64,
  10746. 53,54,55,56,57,58,59,60, // 3x
  10747. 61,62,-1,-1,-1,0,-1,-1,
  10748. -1,1,2,3,4,5,6,7, // 4x
  10749. 8,9,10,11,12,13,14,15,
  10750. 16,17,18,19,20,21,22,23, // 5x
  10751. 24,25,26,-1,-1,-1,-1,-1,
  10752. -1,27,28,29,30,31,32,33, // 6x
  10753. 34,35,36,37,38,39,40,41,
  10754. 42,43,44,45,46,47,48,49, // 7x
  10755. 50,51,52,-1,-1,-1,-1,-1,
  10756. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  10757. -1,-1,-1,-1,-1,-1,-1,-1,
  10758. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  10759. -1,-1,-1,-1,-1,-1,-1,-1,
  10760. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  10761. -1,-1,-1,-1,-1,-1,-1,-1,
  10762. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  10763. -1,-1,-1,-1,-1,-1,-1,-1,
  10764. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  10765. -1,-1,-1,-1,-1,-1,-1,-1,
  10766. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  10767. -1,-1,-1,-1,-1,-1,-1,-1,
  10768. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  10769. -1,-1,-1,-1,-1,-1,-1,-1,
  10770. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  10771. -1,-1,-1,-1,-1,-1,-1,-1
  10772. };
  10773. // <summary>
  10774. // Converts a 32-bit integer into a Base64
  10775. // character string. Base64 character strings
  10776. // are always 8 characters long. All iinteger
  10777. // values are acceptable.
  10778. // </summary>
  10779. // <param name="number">
  10780. // 32-bit integer to be converted.
  10781. // </param>
  10782. // <returns>
  10783. // 8 character string. The 1st six characters
  10784. // contain the encoded number, the last two
  10785. // characters are padded with "=".
  10786. // </returns>
  10787. public LSL_String llIntegerToBase64(int number)
  10788. {
  10789. // uninitialized string
  10790. char[] imdt = new char[8];
  10791. m_host.AddScriptLPS(1);
  10792. // Manually unroll the loop
  10793. imdt[7] = '=';
  10794. imdt[6] = '=';
  10795. imdt[5] = i2ctable[number<<4 & 0x3F];
  10796. imdt[4] = i2ctable[number>>2 & 0x3F];
  10797. imdt[3] = i2ctable[number>>8 & 0x3F];
  10798. imdt[2] = i2ctable[number>>14 & 0x3F];
  10799. imdt[1] = i2ctable[number>>20 & 0x3F];
  10800. imdt[0] = i2ctable[number>>26 & 0x3F];
  10801. return new string(imdt);
  10802. }
  10803. // <summary>
  10804. // Converts an eight character base-64 string
  10805. // into a 32-bit integer.
  10806. // </summary>
  10807. // <param name="str">
  10808. // 8 characters string to be converted. Other
  10809. // length strings return zero.
  10810. // </param>
  10811. // <returns>
  10812. // Returns an integer representing the
  10813. // encoded value providedint he 1st 6
  10814. // characters of the string.
  10815. // </returns>
  10816. // <remarks>
  10817. // This is coded to behave like LSL's
  10818. // implementation (I think), based upon the
  10819. // information available at the Wiki.
  10820. // If more than 8 characters are supplied,
  10821. // zero is returned.
  10822. // If a NULL string is supplied, zero will
  10823. // be returned.
  10824. // If fewer than 6 characters are supplied, then
  10825. // the answer will reflect a partial
  10826. // accumulation.
  10827. // <para>
  10828. // The 6-bit segments are
  10829. // extracted left-to-right in big-endian mode,
  10830. // which means that segment 6 only contains the
  10831. // two low-order bits of the 32 bit integer as
  10832. // its high order 2 bits. A short string therefore
  10833. // means loss of low-order information. E.g.
  10834. //
  10835. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  10836. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  10837. // |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|
  10838. // |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|
  10839. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  10840. //
  10841. // </para>
  10842. // </remarks>
  10843. public LSL_Integer llBase64ToInteger(string str)
  10844. {
  10845. int number = 0;
  10846. int digit;
  10847. m_host.AddScriptLPS(1);
  10848. // Require a well-fromed base64 string
  10849. if (str.Length > 8)
  10850. return 0;
  10851. // The loop is unrolled in the interests
  10852. // of performance and simple necessity.
  10853. //
  10854. // MUST find 6 digits to be well formed
  10855. // -1 == invalid
  10856. // 0 == padding
  10857. if ((digit = c2itable[str[0]]) <= 0)
  10858. {
  10859. return digit < 0 ? (int)0 : number;
  10860. }
  10861. number += --digit<<26;
  10862. if ((digit = c2itable[str[1]]) <= 0)
  10863. {
  10864. return digit < 0 ? (int)0 : number;
  10865. }
  10866. number += --digit<<20;
  10867. if ((digit = c2itable[str[2]]) <= 0)
  10868. {
  10869. return digit < 0 ? (int)0 : number;
  10870. }
  10871. number += --digit<<14;
  10872. if ((digit = c2itable[str[3]]) <= 0)
  10873. {
  10874. return digit < 0 ? (int)0 : number;
  10875. }
  10876. number += --digit<<8;
  10877. if ((digit = c2itable[str[4]]) <= 0)
  10878. {
  10879. return digit < 0 ? (int)0 : number;
  10880. }
  10881. number += --digit<<2;
  10882. if ((digit = c2itable[str[5]]) <= 0)
  10883. {
  10884. return digit < 0 ? (int)0 : number;
  10885. }
  10886. number += --digit>>4;
  10887. // ignore trailing padding
  10888. return number;
  10889. }
  10890. public LSL_Float llGetGMTclock()
  10891. {
  10892. m_host.AddScriptLPS(1);
  10893. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  10894. }
  10895. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  10896. {
  10897. m_host.AddScriptLPS(1);
  10898. if (m_UrlModule != null)
  10899. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  10900. return String.Empty;
  10901. }
  10902. public LSL_String llGetSimulatorHostname()
  10903. {
  10904. m_host.AddScriptLPS(1);
  10905. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  10906. return UrlModule.ExternalHostNameForLSL;
  10907. }
  10908. // <summary>
  10909. // Scan the string supplied in 'src' and
  10910. // tokenize it based upon two sets of
  10911. // tokenizers provided in two lists,
  10912. // separators and spacers.
  10913. // </summary>
  10914. //
  10915. // <remarks>
  10916. // Separators demarcate tokens and are
  10917. // elided as they are encountered. Spacers
  10918. // also demarcate tokens, but are themselves
  10919. // retained as tokens.
  10920. //
  10921. // Both separators and spacers may be arbitrarily
  10922. // long strings. i.e. ":::".
  10923. //
  10924. // The function returns an ordered list
  10925. // representing the tokens found in the supplied
  10926. // sources string. If two successive tokenizers
  10927. // are encountered, then a null-string entry is
  10928. // added to the list.
  10929. //
  10930. // It is a precondition that the source and
  10931. // toekizer lisst are non-null. If they are null,
  10932. // then a null pointer exception will be thrown
  10933. // while their lengths are being determined.
  10934. //
  10935. // A small amount of working memoryis required
  10936. // of approximately 8*#tokenizers + 8*srcstrlen.
  10937. //
  10938. // There are many ways in which this function
  10939. // can be implemented, this implementation is
  10940. // fairly naive and assumes that when the
  10941. // function is invooked with a short source
  10942. // string and/or short lists of tokenizers, then
  10943. // performance will not be an issue.
  10944. //
  10945. // In order to minimize the perofrmance
  10946. // effects of long strings, or large numbers
  10947. // of tokeizers, the function skips as far as
  10948. // possible whenever a toekenizer is found,
  10949. // and eliminates redundant tokenizers as soon
  10950. // as is possible.
  10951. //
  10952. // The implementation tries to minimize temporary
  10953. // garbage generation.
  10954. // </remarks>
  10955. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  10956. {
  10957. return ParseString2List(src, separators, spacers, true);
  10958. }
  10959. private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  10960. {
  10961. int srclen = src.Length;
  10962. int seplen = separators.Length;
  10963. object[] separray = separators.Data;
  10964. int spclen = spacers.Length;
  10965. object[] spcarray = spacers.Data;
  10966. int dellen = 0;
  10967. string[] delarray = new string[seplen+spclen];
  10968. int outlen = 0;
  10969. string[] outarray = new string[srclen*2+1];
  10970. int i, j;
  10971. string d;
  10972. m_host.AddScriptLPS(1);
  10973. /*
  10974. * Convert separator and spacer lists to C# strings.
  10975. * Also filter out null strings so we don't hang.
  10976. */
  10977. for (i = 0; i < seplen; i ++)
  10978. {
  10979. d = separray[i].ToString();
  10980. if (d.Length > 0)
  10981. {
  10982. delarray[dellen++] = d;
  10983. }
  10984. }
  10985. seplen = dellen;
  10986. for (i = 0; i < spclen; i ++)
  10987. {
  10988. d = spcarray[i].ToString();
  10989. if (d.Length > 0)
  10990. {
  10991. delarray[dellen++] = d;
  10992. }
  10993. }
  10994. /*
  10995. * Scan through source string from beginning to end.
  10996. */
  10997. for (i = 0;;)
  10998. {
  10999. /*
  11000. * Find earliest delimeter in src starting at i (if any).
  11001. */
  11002. int earliestDel = -1;
  11003. int earliestSrc = srclen;
  11004. string earliestStr = null;
  11005. for (j = 0; j < dellen; j ++)
  11006. {
  11007. d = delarray[j];
  11008. if (d != null)
  11009. {
  11010. int index = src.IndexOf(d, i);
  11011. if (index < 0)
  11012. {
  11013. delarray[j] = null; // delim nowhere in src, don't check it anymore
  11014. }
  11015. else if (index < earliestSrc)
  11016. {
  11017. earliestSrc = index; // where delimeter starts in source string
  11018. earliestDel = j; // where delimeter is in delarray[]
  11019. earliestStr = d; // the delimeter string from delarray[]
  11020. if (index == i) break; // can't do any better than found at beg of string
  11021. }
  11022. }
  11023. }
  11024. /*
  11025. * Output source string starting at i through start of earliest delimeter.
  11026. */
  11027. if (keepNulls || (earliestSrc > i))
  11028. {
  11029. outarray[outlen++] = src.Substring(i, earliestSrc - i);
  11030. }
  11031. /*
  11032. * If no delimeter found at or after i, we're done scanning.
  11033. */
  11034. if (earliestDel < 0) break;
  11035. /*
  11036. * If delimeter was a spacer, output the spacer.
  11037. */
  11038. if (earliestDel >= seplen)
  11039. {
  11040. outarray[outlen++] = earliestStr;
  11041. }
  11042. /*
  11043. * Look at rest of src string following delimeter.
  11044. */
  11045. i = earliestSrc + earliestStr.Length;
  11046. }
  11047. /*
  11048. * Make up an exact-sized output array suitable for an LSL_List object.
  11049. */
  11050. object[] outlist = new object[outlen];
  11051. for (i = 0; i < outlen; i ++)
  11052. {
  11053. outlist[i] = new LSL_String(outarray[i]);
  11054. }
  11055. return new LSL_List(outlist);
  11056. }
  11057. private const uint fullperms = (uint)PermissionMask.All; // no export for now
  11058. private int PermissionMaskToLSLPerm(uint value)
  11059. {
  11060. value &= fullperms;
  11061. if (value == fullperms)
  11062. return ScriptBaseClass.PERM_ALL;
  11063. if( value == 0)
  11064. return 0;
  11065. int ret = 0;
  11066. if ((value & (uint)PermissionMask.Copy) != 0)
  11067. ret |= ScriptBaseClass.PERM_COPY;
  11068. if ((value & (uint)PermissionMask.Modify) != 0)
  11069. ret |= ScriptBaseClass.PERM_MODIFY;
  11070. if ((value & (uint)PermissionMask.Move) != 0)
  11071. ret |= ScriptBaseClass.PERM_MOVE;
  11072. if ((value & (uint)PermissionMask.Transfer) != 0)
  11073. ret |= ScriptBaseClass.PERM_TRANSFER;
  11074. return ret;
  11075. }
  11076. private uint LSLPermToPermissionMask(int lslperm, uint oldvalue)
  11077. {
  11078. lslperm &= ScriptBaseClass.PERM_ALL;
  11079. if (lslperm == ScriptBaseClass.PERM_ALL)
  11080. return oldvalue |= fullperms;
  11081. oldvalue &= ~fullperms;
  11082. if(lslperm != 0)
  11083. {
  11084. if ((lslperm & ScriptBaseClass.PERM_COPY) != 0)
  11085. oldvalue |= (uint)PermissionMask.Copy;
  11086. if ((lslperm & ScriptBaseClass.PERM_MODIFY) != 0)
  11087. oldvalue |= (uint)PermissionMask.Modify;
  11088. if ((lslperm & ScriptBaseClass.PERM_MOVE) != 0)
  11089. oldvalue |= (uint)PermissionMask.Move;
  11090. if ((lslperm & ScriptBaseClass.PERM_TRANSFER) != 0)
  11091. oldvalue |= (uint)PermissionMask.Transfer;
  11092. }
  11093. return oldvalue;
  11094. }
  11095. private int fixedCopyTransfer(int value)
  11096. {
  11097. if ((value & (ScriptBaseClass.PERM_COPY | ScriptBaseClass.PERM_TRANSFER)) == 0)
  11098. value |= ScriptBaseClass.PERM_TRANSFER;
  11099. return value;
  11100. }
  11101. public LSL_Integer llGetObjectPermMask(int mask)
  11102. {
  11103. m_host.AddScriptLPS(1);
  11104. switch(mask)
  11105. {
  11106. case ScriptBaseClass.MASK_BASE:
  11107. return PermissionMaskToLSLPerm(m_host.BaseMask);
  11108. case ScriptBaseClass.MASK_OWNER:
  11109. return PermissionMaskToLSLPerm(m_host.OwnerMask);
  11110. case ScriptBaseClass.MASK_GROUP:
  11111. return PermissionMaskToLSLPerm(m_host.GroupMask);
  11112. case ScriptBaseClass.MASK_EVERYONE:
  11113. return PermissionMaskToLSLPerm(m_host.EveryoneMask);
  11114. case ScriptBaseClass.MASK_NEXT:
  11115. return PermissionMaskToLSLPerm(m_host.NextOwnerMask);
  11116. }
  11117. return -1;
  11118. }
  11119. public void llSetObjectPermMask(int mask, int value)
  11120. {
  11121. m_host.AddScriptLPS(1);
  11122. if (!m_AllowGodFunctions || !World.Permissions.IsAdministrator(m_host.OwnerID))
  11123. return;
  11124. // not even admins have right to violate basic rules
  11125. if (mask != ScriptBaseClass.MASK_BASE)
  11126. {
  11127. mask &= PermissionMaskToLSLPerm(m_host.BaseMask);
  11128. if (mask != ScriptBaseClass.MASK_OWNER)
  11129. mask &= PermissionMaskToLSLPerm(m_host.OwnerMask);
  11130. }
  11131. switch (mask)
  11132. {
  11133. case ScriptBaseClass.MASK_BASE:
  11134. value = fixedCopyTransfer(value);
  11135. m_host.BaseMask = LSLPermToPermissionMask(value, m_host.BaseMask);
  11136. break;
  11137. case ScriptBaseClass.MASK_OWNER:
  11138. value = fixedCopyTransfer(value);
  11139. m_host.OwnerMask = LSLPermToPermissionMask(value, m_host.OwnerMask);
  11140. break;
  11141. case ScriptBaseClass.MASK_GROUP:
  11142. m_host.GroupMask = LSLPermToPermissionMask(value, m_host.GroupMask);
  11143. break;
  11144. case ScriptBaseClass.MASK_EVERYONE:
  11145. m_host.EveryoneMask = LSLPermToPermissionMask(value, m_host.EveryoneMask);
  11146. break;
  11147. case ScriptBaseClass.MASK_NEXT:
  11148. value = fixedCopyTransfer(value);
  11149. m_host.NextOwnerMask = LSLPermToPermissionMask(value, m_host.NextOwnerMask);
  11150. break;
  11151. default:
  11152. return;
  11153. }
  11154. m_host.ParentGroup.AggregatePerms();
  11155. }
  11156. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  11157. {
  11158. m_host.AddScriptLPS(1);
  11159. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11160. if (item == null)
  11161. return -1;
  11162. switch (mask)
  11163. {
  11164. case ScriptBaseClass.MASK_BASE:
  11165. return PermissionMaskToLSLPerm(item.BasePermissions);
  11166. case ScriptBaseClass.MASK_OWNER:
  11167. return PermissionMaskToLSLPerm(item.CurrentPermissions);
  11168. case ScriptBaseClass.MASK_GROUP:
  11169. return PermissionMaskToLSLPerm(item.GroupPermissions);
  11170. case ScriptBaseClass.MASK_EVERYONE:
  11171. return PermissionMaskToLSLPerm(item.EveryonePermissions);
  11172. case ScriptBaseClass.MASK_NEXT:
  11173. return PermissionMaskToLSLPerm(item.NextPermissions);
  11174. }
  11175. return -1;
  11176. }
  11177. public void llSetInventoryPermMask(string itemName, int mask, int value)
  11178. {
  11179. m_host.AddScriptLPS(1);
  11180. if(!m_AllowGodFunctions || !World.Permissions.IsAdministrator(m_host.OwnerID))
  11181. return;
  11182. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11183. if (item != null)
  11184. {
  11185. if (mask != ScriptBaseClass.MASK_BASE)
  11186. {
  11187. mask &= PermissionMaskToLSLPerm(item.BasePermissions);
  11188. if (mask != ScriptBaseClass.MASK_OWNER)
  11189. mask &= PermissionMaskToLSLPerm(item.CurrentPermissions);
  11190. }
  11191. /*
  11192. if(item.Type == (int)(AssetType.Settings))
  11193. value |= ScriptBaseClass.PERM_COPY;
  11194. */
  11195. switch (mask)
  11196. {
  11197. case ScriptBaseClass.MASK_BASE:
  11198. value = fixedCopyTransfer(value);
  11199. item.BasePermissions = LSLPermToPermissionMask(value, item.BasePermissions);
  11200. break;
  11201. case ScriptBaseClass.MASK_OWNER:
  11202. value = fixedCopyTransfer(value);
  11203. item.CurrentPermissions = LSLPermToPermissionMask(value, item.CurrentPermissions);
  11204. break;
  11205. case ScriptBaseClass.MASK_GROUP:
  11206. item.GroupPermissions = LSLPermToPermissionMask(value, item.GroupPermissions);
  11207. break;
  11208. case ScriptBaseClass.MASK_EVERYONE:
  11209. item.EveryonePermissions = LSLPermToPermissionMask(value, item.EveryonePermissions);
  11210. break;
  11211. case ScriptBaseClass.MASK_NEXT:
  11212. value = fixedCopyTransfer(value);
  11213. item.NextPermissions = LSLPermToPermissionMask(value, item.NextPermissions);
  11214. break;
  11215. default:
  11216. return;
  11217. }
  11218. m_host.ParentGroup.InvalidateDeepEffectivePerms();
  11219. m_host.ParentGroup.AggregatePerms();
  11220. }
  11221. }
  11222. public LSL_Key llGetInventoryCreator(string itemName)
  11223. {
  11224. m_host.AddScriptLPS(1);
  11225. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11226. if (item == null)
  11227. {
  11228. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  11229. return String.Empty;
  11230. }
  11231. return item.CreatorID.ToString();
  11232. }
  11233. public void llOwnerSay(string msg)
  11234. {
  11235. m_host.AddScriptLPS(1);
  11236. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  11237. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  11238. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  11239. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  11240. }
  11241. public LSL_Key llRequestSecureURL()
  11242. {
  11243. m_host.AddScriptLPS(1);
  11244. if (m_UrlModule != null)
  11245. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11246. return ScriptBaseClass.NULL_KEY;
  11247. }
  11248. public LSL_Key llRequestSimulatorData(string simulator, int data)
  11249. {
  11250. try
  11251. {
  11252. m_host.AddScriptLPS(1);
  11253. if (World.RegionInfo.RegionName == simulator)
  11254. {
  11255. string lreply = String.Empty;
  11256. GridRegion linfo = new GridRegion(World.RegionInfo);
  11257. switch (data)
  11258. {
  11259. case ScriptBaseClass.DATA_SIM_POS:
  11260. {
  11261. lreply = new LSL_Vector(
  11262. linfo.RegionLocX,
  11263. linfo.RegionLocY,
  11264. 0).ToString();
  11265. }
  11266. break;
  11267. case ScriptBaseClass.DATA_SIM_STATUS:
  11268. lreply = "up"; // Duh!
  11269. break;
  11270. case ScriptBaseClass.DATA_SIM_RATING:
  11271. int access = linfo.Maturity;
  11272. if (access == 0)
  11273. lreply = "PG";
  11274. else if (access == 1)
  11275. lreply = "MATURE";
  11276. else if (access == 2)
  11277. lreply = "ADULT";
  11278. else
  11279. lreply = "UNKNOWN";
  11280. break;
  11281. case ScriptBaseClass.DATA_SIM_RELEASE:
  11282. lreply = "OpenSim";
  11283. break;
  11284. default:
  11285. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11286. return ScriptBaseClass.NULL_KEY; // Raise no event
  11287. }
  11288. string ltid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  11289. m_item.ItemID, lreply);
  11290. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11291. return ltid;
  11292. }
  11293. Action<string> act = eventID =>
  11294. {
  11295. GridRegion info = World.GridService.GetRegionByName(RegionScopeID, simulator);
  11296. string reply = "unknown";
  11297. if (info != null)
  11298. {
  11299. switch (data)
  11300. {
  11301. case ScriptBaseClass.DATA_SIM_POS:
  11302. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  11303. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  11304. // anything is present we need to disambiguate.
  11305. //
  11306. // FIXME: Hypergrid should be storing this data in a different field.
  11307. RegionFlags regionFlags = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  11308. info.ScopeID, info.RegionID);
  11309. if ((regionFlags & RegionFlags.Hyperlink) != 0)
  11310. {
  11311. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out uint rx, out uint ry);
  11312. reply = new LSL_Vector(rx, ry, 0).ToString();
  11313. }
  11314. else
  11315. {
  11316. // Local grid co-oridnates
  11317. reply = new LSL_Vector(info.RegionLocX, info.RegionLocY, 0).ToString();
  11318. }
  11319. break;
  11320. case ScriptBaseClass.DATA_SIM_STATUS:
  11321. reply = "up"; // Duh!
  11322. break;
  11323. case ScriptBaseClass.DATA_SIM_RATING:
  11324. int access = info.Maturity;
  11325. if (access == 0)
  11326. reply = "PG";
  11327. else if (access == 1)
  11328. reply = "MATURE";
  11329. else if (access == 2)
  11330. reply = "ADULT";
  11331. else
  11332. reply = "UNKNOWN";
  11333. break;
  11334. case ScriptBaseClass.DATA_SIM_RELEASE:
  11335. reply = "OpenSim";
  11336. break;
  11337. default:
  11338. break;
  11339. }
  11340. }
  11341. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  11342. };
  11343. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(
  11344. m_host.LocalId, m_item.ItemID, act);
  11345. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11346. return tid.ToString();
  11347. }
  11348. catch(Exception)
  11349. {
  11350. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  11351. return ScriptBaseClass.NULL_KEY;
  11352. }
  11353. }
  11354. public LSL_Key llRequestURL()
  11355. {
  11356. m_host.AddScriptLPS(1);
  11357. if (m_UrlModule != null)
  11358. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11359. return ScriptBaseClass.NULL_KEY;
  11360. }
  11361. public void llForceMouselook(int mouselook)
  11362. {
  11363. m_host.AddScriptLPS(1);
  11364. m_host.SetForceMouselook(mouselook != 0);
  11365. }
  11366. public LSL_Float llGetObjectMass(LSL_Key id)
  11367. {
  11368. m_host.AddScriptLPS(1);
  11369. UUID key = new UUID();
  11370. if (!UUID.TryParse(id, out key))
  11371. return 0;
  11372. // return total object mass
  11373. SceneObjectPart part = World.GetSceneObjectPart(key);
  11374. if (part != null)
  11375. return part.ParentGroup.GetMass();
  11376. // the object is null so the key is for an avatar
  11377. ScenePresence avatar = World.GetScenePresence(key);
  11378. if (avatar != null)
  11379. {
  11380. if (avatar.IsChildAgent)
  11381. {
  11382. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  11383. // child agents have a mass of 1.0
  11384. return 1;
  11385. }
  11386. else
  11387. {
  11388. return avatar.GetMass();
  11389. }
  11390. }
  11391. return 0;
  11392. }
  11393. /// <summary>
  11394. /// llListReplaceList removes the sub-list defined by the inclusive indices
  11395. /// start and end and inserts the src list in its place. The inclusive
  11396. /// nature of the indices means that at least one element must be deleted
  11397. /// if the indices are within the bounds of the existing list. I.e. 2,2
  11398. /// will remove the element at index 2 and replace it with the source
  11399. /// list. Both indices may be negative, with the usual interpretation. An
  11400. /// interesting case is where end is lower than start. As these indices
  11401. /// bound the list to be removed, then 0->end, and start->lim are removed
  11402. /// and the source list is added as a suffix.
  11403. /// </summary>
  11404. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  11405. {
  11406. LSL_List pref;
  11407. m_host.AddScriptLPS(1);
  11408. // Note that although we have normalized, both
  11409. // indices could still be negative.
  11410. if (start < 0)
  11411. {
  11412. start = start+dest.Length;
  11413. }
  11414. if (end < 0)
  11415. {
  11416. end = end+dest.Length;
  11417. }
  11418. // The comventional case, remove a sequence starting with
  11419. // start and ending with end. And then insert the source
  11420. // list.
  11421. if (start <= end)
  11422. {
  11423. // If greater than zero, then there is going to be a
  11424. // surviving prefix. Otherwise the inclusive nature
  11425. // of the indices mean that we're going to add the
  11426. // source list as a prefix.
  11427. if (start > 0)
  11428. {
  11429. pref = dest.GetSublist(0,start-1);
  11430. // Only add a suffix if there is something
  11431. // beyond the end index (it's inclusive too).
  11432. if (end + 1 < dest.Length)
  11433. {
  11434. return pref + src + dest.GetSublist(end + 1, -1);
  11435. }
  11436. else
  11437. {
  11438. return pref + src;
  11439. }
  11440. }
  11441. // If start is less than or equal to zero, then
  11442. // the new list is simply a prefix. We still need to
  11443. // figure out any necessary surgery to the destination
  11444. // based upon end. Note that if end exceeds the upper
  11445. // bound in this case, the entire destination list
  11446. // is removed.
  11447. else if (start == 0)
  11448. {
  11449. if (end + 1 < dest.Length)
  11450. return src + dest.GetSublist(end + 1, -1);
  11451. else
  11452. return src;
  11453. }
  11454. else // Start < 0
  11455. {
  11456. if (end + 1 < dest.Length)
  11457. return dest.GetSublist(end + 1, -1);
  11458. else
  11459. return new LSL_List();
  11460. }
  11461. }
  11462. // Finally, if start > end, we strip away a prefix and
  11463. // a suffix, to leave the list that sits <between> ens
  11464. // and start, and then tag on the src list. AT least
  11465. // that's my interpretation. We can get sublist to do
  11466. // this for us. Note that one, or both of the indices
  11467. // might have been negative.
  11468. else
  11469. {
  11470. return dest.GetSublist(end + 1, start - 1) + src;
  11471. }
  11472. }
  11473. public void llLoadURL(string avatar_id, string message, string url)
  11474. {
  11475. m_host.AddScriptLPS(1);
  11476. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  11477. if (null != dm)
  11478. dm.SendUrlToUser(
  11479. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  11480. ScriptSleep(m_sleepMsOnLoadURL);
  11481. }
  11482. public void llParcelMediaCommandList(LSL_List commandList)
  11483. {
  11484. // TODO: Not implemented yet (missing in libomv?):
  11485. // 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)
  11486. m_host.AddScriptLPS(1);
  11487. // according to the docs, this command only works if script owner and land owner are the same
  11488. // lets add estate owners and gods, too, and use the generic permission check.
  11489. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11490. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false)) return;
  11491. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  11492. byte loop = 0;
  11493. LandData landData = landObject.LandData;
  11494. string url = landData.MediaURL;
  11495. string texture = landData.MediaID.ToString();
  11496. bool autoAlign = landData.MediaAutoScale != 0;
  11497. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  11498. string description = "";
  11499. int width = 0;
  11500. int height = 0;
  11501. ParcelMediaCommandEnum? commandToSend = null;
  11502. float time = 0.0f; // default is from start
  11503. uint cmndFlags = 0;
  11504. ScenePresence presence = null;
  11505. int cmd;
  11506. for (int i = 0; i < commandList.Data.Length; i++)
  11507. {
  11508. if(commandList.Data[i] is LSL_Integer)
  11509. cmd = (LSL_Integer)commandList.Data[i];
  11510. else
  11511. cmd = (int)commandList.Data[i];
  11512. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)cmd;
  11513. switch (command)
  11514. {
  11515. case ParcelMediaCommandEnum.Agent:
  11516. // we send only to one agent
  11517. if ((i + 1) < commandList.Length)
  11518. {
  11519. if (commandList.Data[i + 1] is LSL_String)
  11520. {
  11521. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out UUID agentID))
  11522. {
  11523. presence = World.GetScenePresence(agentID);
  11524. if(presence == null || presence.IsNPC)
  11525. return;
  11526. }
  11527. }
  11528. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  11529. ++i;
  11530. }
  11531. break;
  11532. case ParcelMediaCommandEnum.Loop:
  11533. loop = 1;
  11534. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_LOOP);
  11535. commandToSend = command;
  11536. update = true; //need to send the media update packet to set looping
  11537. break;
  11538. case ParcelMediaCommandEnum.Play:
  11539. loop = 0;
  11540. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PLAY);
  11541. commandToSend = command;
  11542. update = true; //need to send the media update packet to make sure it doesn't loop
  11543. break;
  11544. case ParcelMediaCommandEnum.Pause:
  11545. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PAUSE);
  11546. commandToSend = command;
  11547. break;
  11548. case ParcelMediaCommandEnum.Stop:
  11549. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_STOP);
  11550. commandToSend = command;
  11551. break;
  11552. case ParcelMediaCommandEnum.Unload:
  11553. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_UNLOAD);
  11554. commandToSend = command;
  11555. break;
  11556. case ParcelMediaCommandEnum.Url:
  11557. if ((i + 1) < commandList.Length)
  11558. {
  11559. if (commandList.Data[i + 1] is LSL_String)
  11560. {
  11561. url = (LSL_String)commandList.Data[i + 1];
  11562. try
  11563. {
  11564. Uri dummy = new Uri(url, UriKind.Absolute);
  11565. }
  11566. catch
  11567. {
  11568. Error("llParcelMediaCommandList", "invalid PARCEL_MEDIA_COMMAND_URL");
  11569. return;
  11570. }
  11571. update = true;
  11572. }
  11573. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  11574. ++i;
  11575. }
  11576. break;
  11577. case ParcelMediaCommandEnum.Texture:
  11578. if ((i + 1) < commandList.Length)
  11579. {
  11580. if (commandList.Data[i + 1] is LSL_String)
  11581. {
  11582. texture = (LSL_String)commandList.Data[i + 1];
  11583. update = true;
  11584. }
  11585. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  11586. ++i;
  11587. }
  11588. break;
  11589. case ParcelMediaCommandEnum.Time:
  11590. if ((i + 1) < commandList.Length)
  11591. {
  11592. if (commandList.Data[i + 1] is LSL_Float)
  11593. {
  11594. time = (float)(LSL_Float)commandList.Data[i + 1];
  11595. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_TIME);
  11596. }
  11597. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  11598. ++i;
  11599. }
  11600. break;
  11601. case ParcelMediaCommandEnum.AutoAlign:
  11602. if ((i + 1) < commandList.Length)
  11603. {
  11604. if (commandList.Data[i + 1] is LSL_Integer)
  11605. {
  11606. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  11607. update = true;
  11608. }
  11609. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  11610. ++i;
  11611. }
  11612. break;
  11613. case ParcelMediaCommandEnum.Type:
  11614. if ((i + 1) < commandList.Length)
  11615. {
  11616. if (commandList.Data[i + 1] is LSL_String)
  11617. {
  11618. mediaType = (LSL_String)commandList.Data[i + 1];
  11619. update = true;
  11620. }
  11621. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  11622. ++i;
  11623. }
  11624. break;
  11625. case ParcelMediaCommandEnum.Desc:
  11626. if ((i + 1) < commandList.Length)
  11627. {
  11628. if (commandList.Data[i + 1] is LSL_String)
  11629. {
  11630. description = (LSL_String)commandList.Data[i + 1];
  11631. update = true;
  11632. }
  11633. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  11634. ++i;
  11635. }
  11636. break;
  11637. case ParcelMediaCommandEnum.Size:
  11638. if ((i + 2) < commandList.Length)
  11639. {
  11640. if (commandList.Data[i + 1] is LSL_Integer)
  11641. {
  11642. if (commandList.Data[i + 2] is LSL_Integer)
  11643. {
  11644. width = (LSL_Integer)commandList.Data[i + 1];
  11645. height = (LSL_Integer)commandList.Data[i + 2];
  11646. update = true;
  11647. }
  11648. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11649. }
  11650. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11651. i += 2;
  11652. }
  11653. break;
  11654. default:
  11655. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  11656. break;
  11657. }//end switch
  11658. }//end for
  11659. // if we didn't get a presence, we send to all and change the url
  11660. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  11661. // did something important change or do we only start/stop/pause?
  11662. if (update)
  11663. {
  11664. if (presence == null)
  11665. {
  11666. // we send to all
  11667. landData.MediaID = new UUID(texture);
  11668. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  11669. landData.MediaWidth = width;
  11670. landData.MediaHeight = height;
  11671. landData.MediaType = mediaType;
  11672. // do that one last, it will cause a ParcelPropertiesUpdate
  11673. landObject.SetMediaUrl(url);
  11674. // now send to all (non-child) agents in the parcel
  11675. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11676. {
  11677. if (sp.currentParcelUUID == landData.GlobalID)
  11678. {
  11679. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  11680. landData.MediaID,
  11681. landData.MediaAutoScale,
  11682. mediaType,
  11683. description,
  11684. width, height,
  11685. loop);
  11686. }
  11687. });
  11688. }
  11689. else if (!presence.IsChildAgent)
  11690. {
  11691. // we only send to one (root) agent
  11692. presence.ControllingClient.SendParcelMediaUpdate(url,
  11693. new UUID(texture),
  11694. autoAlign ? (byte)1 : (byte)0,
  11695. mediaType,
  11696. description,
  11697. width, height,
  11698. loop);
  11699. }
  11700. }
  11701. if (commandToSend != null)
  11702. {
  11703. // the commandList contained a start/stop/... command, too
  11704. if (presence == null)
  11705. {
  11706. // send to all (non-child) agents in the parcel
  11707. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11708. {
  11709. if (sp.currentParcelUUID == landData.GlobalID)
  11710. {
  11711. sp.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11712. commandToSend.Value, time);
  11713. }
  11714. });
  11715. }
  11716. else if (!presence.IsChildAgent)
  11717. {
  11718. presence.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11719. commandToSend.Value, time);
  11720. }
  11721. }
  11722. ScriptSleep(m_sleepMsOnParcelMediaCommandList);
  11723. }
  11724. public LSL_List llParcelMediaQuery(LSL_List aList)
  11725. {
  11726. m_host.AddScriptLPS(1);
  11727. LSL_List list = new LSL_List();
  11728. Vector3 pos = m_host.AbsolutePosition;
  11729. ILandObject landObject = World.LandChannel.GetLandObject(pos);
  11730. if(landObject == null)
  11731. return list;
  11732. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false))
  11733. return list;
  11734. LandData land = landObject.LandData;
  11735. if(land == null)
  11736. return list;
  11737. //TO DO: make the implementation for the missing commands
  11738. //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)
  11739. for (int i = 0; i < aList.Data.Length; i++)
  11740. {
  11741. if (aList.Data[i] != null)
  11742. {
  11743. switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
  11744. {
  11745. case ParcelMediaCommandEnum.Url:
  11746. list.Add(new LSL_String(land.MediaURL));
  11747. break;
  11748. case ParcelMediaCommandEnum.Desc:
  11749. list.Add(new LSL_String(land.MediaDescription));
  11750. break;
  11751. case ParcelMediaCommandEnum.Texture:
  11752. list.Add(new LSL_String(land.MediaID.ToString()));
  11753. break;
  11754. case ParcelMediaCommandEnum.Type:
  11755. list.Add(new LSL_String(land.MediaType));
  11756. break;
  11757. case ParcelMediaCommandEnum.Size:
  11758. list.Add(new LSL_String(land.MediaWidth));
  11759. list.Add(new LSL_String(land.MediaHeight));
  11760. break;
  11761. default:
  11762. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  11763. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  11764. break;
  11765. }
  11766. }
  11767. }
  11768. ScriptSleep(m_sleepMsOnParcelMediaQuery);
  11769. return list;
  11770. }
  11771. public LSL_Integer llModPow(int a, int b, int c)
  11772. {
  11773. m_host.AddScriptLPS(1);
  11774. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out long tmp);
  11775. ScriptSleep(m_sleepMsOnModPow);
  11776. return (int)tmp;
  11777. }
  11778. public LSL_Integer llGetInventoryType(string name)
  11779. {
  11780. m_host.AddScriptLPS(1);
  11781. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11782. if (item == null)
  11783. return -1;
  11784. return item.Type;
  11785. }
  11786. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  11787. {
  11788. m_host.AddScriptLPS(1);
  11789. if(m_host.LocalId != m_host.ParentGroup.RootPart.LocalId)
  11790. return;
  11791. if (quick_pay_buttons.Data.Length < 4)
  11792. {
  11793. int x;
  11794. for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
  11795. {
  11796. quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
  11797. }
  11798. }
  11799. int[] nPrice = new int[5];
  11800. nPrice[0] = price;
  11801. nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
  11802. nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
  11803. nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
  11804. nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
  11805. m_host.ParentGroup.RootPart.PayPrice = nPrice;
  11806. m_host.ParentGroup.HasGroupChanged = true;
  11807. }
  11808. public LSL_Vector llGetCameraPos()
  11809. {
  11810. m_host.AddScriptLPS(1);
  11811. if (m_item.PermsGranter == UUID.Zero)
  11812. return Vector3.Zero;
  11813. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11814. {
  11815. Error("llGetCameraPos", "No permissions to track the camera");
  11816. return Vector3.Zero;
  11817. }
  11818. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11819. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11820. if (presence != null)
  11821. {
  11822. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  11823. return pos;
  11824. }
  11825. return Vector3.Zero;
  11826. }
  11827. public LSL_Rotation llGetCameraRot()
  11828. {
  11829. m_host.AddScriptLPS(1);
  11830. if (m_item.PermsGranter == UUID.Zero)
  11831. return Quaternion.Identity;
  11832. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11833. {
  11834. Error("llGetCameraRot", "No permissions to track the camera");
  11835. return Quaternion.Identity;
  11836. }
  11837. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11838. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11839. if (presence != null)
  11840. {
  11841. return new LSL_Rotation(presence.CameraRotation);
  11842. }
  11843. return Quaternion.Identity;
  11844. }
  11845. public void llSetPrimURL(string url)
  11846. {
  11847. m_host.AddScriptLPS(1);
  11848. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  11849. ScriptSleep(m_sleepMsOnSetPrimURL);
  11850. }
  11851. public void llRefreshPrimURL()
  11852. {
  11853. m_host.AddScriptLPS(1);
  11854. Deprecated("llRefreshPrimURL");
  11855. ScriptSleep(m_sleepMsOnRefreshPrimURL);
  11856. }
  11857. public LSL_String llEscapeURL(string url)
  11858. {
  11859. m_host.AddScriptLPS(1);
  11860. try
  11861. {
  11862. return Uri.EscapeDataString(url);
  11863. }
  11864. catch (Exception ex)
  11865. {
  11866. return "llEscapeURL: " + ex.ToString();
  11867. }
  11868. }
  11869. public LSL_String llUnescapeURL(string url)
  11870. {
  11871. m_host.AddScriptLPS(1);
  11872. try
  11873. {
  11874. return Uri.UnescapeDataString(url);
  11875. }
  11876. catch (Exception ex)
  11877. {
  11878. return "llUnescapeURL: " + ex.ToString();
  11879. }
  11880. }
  11881. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  11882. {
  11883. m_host.AddScriptLPS(1);
  11884. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  11885. if (detectedParams == null)
  11886. {
  11887. if (m_host.ParentGroup.IsAttachment == true)
  11888. {
  11889. detectedParams = new DetectParams
  11890. {
  11891. Key = m_host.OwnerID
  11892. };
  11893. }
  11894. else
  11895. {
  11896. return;
  11897. }
  11898. }
  11899. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  11900. if (avatar != null)
  11901. {
  11902. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  11903. simname, pos, lookAt);
  11904. }
  11905. ScriptSleep(m_sleepMsOnMapDestination);
  11906. }
  11907. public void llAddToLandBanList(LSL_Key avatar, LSL_Float hours)
  11908. {
  11909. m_host.AddScriptLPS(1);
  11910. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11911. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11912. {
  11913. int expires = 0;
  11914. if (hours != 0)
  11915. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  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.Ban)
  11922. return true;
  11923. return false;
  11924. });
  11925. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  11926. return;
  11927. if (idx != -1)
  11928. land.LandData.ParcelAccessList.RemoveAt(idx);
  11929. LandAccessEntry entry = new LandAccessEntry
  11930. {
  11931. AgentID = key,
  11932. Flags = AccessList.Ban,
  11933. Expires = expires
  11934. };
  11935. land.LandData.ParcelAccessList.Add(entry);
  11936. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11937. }
  11938. }
  11939. ScriptSleep(m_sleepMsOnAddToLandBanList);
  11940. }
  11941. public void llRemoveFromLandPassList(string avatar)
  11942. {
  11943. m_host.AddScriptLPS(1);
  11944. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11945. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  11946. {
  11947. if (UUID.TryParse(avatar, out UUID key))
  11948. {
  11949. int idx = land.LandData.ParcelAccessList.FindIndex(
  11950. delegate(LandAccessEntry e)
  11951. {
  11952. if (e.AgentID == key && e.Flags == AccessList.Access)
  11953. return true;
  11954. return false;
  11955. });
  11956. if (idx != -1)
  11957. {
  11958. land.LandData.ParcelAccessList.RemoveAt(idx);
  11959. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11960. }
  11961. }
  11962. }
  11963. ScriptSleep(m_sleepMsOnRemoveFromLandPassList);
  11964. }
  11965. public void llRemoveFromLandBanList(string avatar)
  11966. {
  11967. m_host.AddScriptLPS(1);
  11968. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11969. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11970. {
  11971. if (UUID.TryParse(avatar, out UUID key))
  11972. {
  11973. int idx = land.LandData.ParcelAccessList.FindIndex(
  11974. delegate(LandAccessEntry e)
  11975. {
  11976. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11977. return true;
  11978. return false;
  11979. });
  11980. if (idx != -1)
  11981. {
  11982. land.LandData.ParcelAccessList.RemoveAt(idx);
  11983. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11984. }
  11985. }
  11986. }
  11987. ScriptSleep(m_sleepMsOnRemoveFromLandBanList);
  11988. }
  11989. public void llSetCameraParams(LSL_List rules)
  11990. {
  11991. m_host.AddScriptLPS(1);
  11992. // the object we are in
  11993. UUID objectID = m_host.ParentUUID;
  11994. if (objectID == UUID.Zero)
  11995. return;
  11996. // we need the permission first, to know which avatar we want to set the camera for
  11997. UUID agentID = m_item.PermsGranter;
  11998. if (agentID == UUID.Zero)
  11999. return;
  12000. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  12001. return;
  12002. ScenePresence presence = World.GetScenePresence(agentID);
  12003. // we are not interested in child-agents
  12004. if (presence.IsChildAgent) return;
  12005. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  12006. object[] data = rules.Data;
  12007. for (int i = 0; i < data.Length; ++i)
  12008. {
  12009. int type;
  12010. try
  12011. {
  12012. type = Convert.ToInt32(data[i++].ToString());
  12013. }
  12014. catch
  12015. {
  12016. Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
  12017. return;
  12018. }
  12019. if (i >= data.Length) break; // odd number of entries => ignore the last
  12020. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  12021. switch (type)
  12022. {
  12023. case ScriptBaseClass.CAMERA_FOCUS:
  12024. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12025. case ScriptBaseClass.CAMERA_POSITION:
  12026. LSL_Vector v = (LSL_Vector)data[i];
  12027. try
  12028. {
  12029. parameters.Add(type + 1, (float)v.x);
  12030. }
  12031. catch
  12032. {
  12033. switch(type)
  12034. {
  12035. case ScriptBaseClass.CAMERA_FOCUS:
  12036. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
  12037. return;
  12038. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12039. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
  12040. return;
  12041. case ScriptBaseClass.CAMERA_POSITION:
  12042. Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
  12043. return;
  12044. }
  12045. }
  12046. try
  12047. {
  12048. parameters.Add(type + 2, (float)v.y);
  12049. }
  12050. catch
  12051. {
  12052. switch(type)
  12053. {
  12054. case ScriptBaseClass.CAMERA_FOCUS:
  12055. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
  12056. return;
  12057. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12058. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
  12059. return;
  12060. case ScriptBaseClass.CAMERA_POSITION:
  12061. Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
  12062. return;
  12063. }
  12064. }
  12065. try
  12066. {
  12067. parameters.Add(type + 3, (float)v.z);
  12068. }
  12069. catch
  12070. {
  12071. switch(type)
  12072. {
  12073. case ScriptBaseClass.CAMERA_FOCUS:
  12074. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
  12075. return;
  12076. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12077. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
  12078. return;
  12079. case ScriptBaseClass.CAMERA_POSITION:
  12080. Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
  12081. return;
  12082. }
  12083. }
  12084. break;
  12085. default:
  12086. // TODO: clean that up as soon as the implicit casts are in
  12087. if (data[i] is LSL_Float)
  12088. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  12089. else if (data[i] is LSL_Integer)
  12090. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  12091. else
  12092. {
  12093. try
  12094. {
  12095. parameters.Add(type, Convert.ToSingle(data[i]));
  12096. }
  12097. catch
  12098. {
  12099. Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
  12100. }
  12101. }
  12102. break;
  12103. }
  12104. }
  12105. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  12106. }
  12107. public void llClearCameraParams()
  12108. {
  12109. m_host.AddScriptLPS(1);
  12110. // the object we are in
  12111. UUID objectID = m_host.ParentUUID;
  12112. if (objectID == UUID.Zero)
  12113. return;
  12114. // we need the permission first, to know which avatar we want to clear the camera for
  12115. UUID agentID = m_item.PermsGranter;
  12116. if (agentID == UUID.Zero)
  12117. return;
  12118. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  12119. return;
  12120. ScenePresence presence = World.GetScenePresence(agentID);
  12121. // we are not interested in child-agents
  12122. if (presence.IsChildAgent)
  12123. return;
  12124. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  12125. }
  12126. public LSL_Float llListStatistics(int operation, LSL_List src)
  12127. {
  12128. m_host.AddScriptLPS(1);
  12129. switch (operation)
  12130. {
  12131. case ScriptBaseClass.LIST_STAT_RANGE:
  12132. return src.Range();
  12133. case ScriptBaseClass.LIST_STAT_MIN:
  12134. return src.Min();
  12135. case ScriptBaseClass.LIST_STAT_MAX:
  12136. return src.Max();
  12137. case ScriptBaseClass.LIST_STAT_MEAN:
  12138. return src.Mean();
  12139. case ScriptBaseClass.LIST_STAT_MEDIAN:
  12140. return LSL_List.ToDoubleList(src).Median();
  12141. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  12142. return src.NumericLength();
  12143. case ScriptBaseClass.LIST_STAT_STD_DEV:
  12144. return src.StdDev();
  12145. case ScriptBaseClass.LIST_STAT_SUM:
  12146. return src.Sum();
  12147. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  12148. return src.SumSqrs();
  12149. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  12150. return src.GeometricMean();
  12151. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  12152. return src.HarmonicMean();
  12153. default:
  12154. return 0.0;
  12155. }
  12156. }
  12157. public LSL_Integer llGetUnixTime()
  12158. {
  12159. m_host.AddScriptLPS(1);
  12160. return Util.UnixTimeSinceEpoch();
  12161. }
  12162. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  12163. {
  12164. m_host.AddScriptLPS(1);
  12165. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  12166. }
  12167. public LSL_Integer llGetRegionFlags()
  12168. {
  12169. m_host.AddScriptLPS(1);
  12170. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  12171. if (estate == null)
  12172. return 67108864;
  12173. return (int)estate.GetRegionFlags();
  12174. }
  12175. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  12176. {
  12177. m_host.AddScriptLPS(1);
  12178. if (str1 == String.Empty)
  12179. return String.Empty;
  12180. if (str2 == String.Empty)
  12181. return str1;
  12182. int len = str2.Length;
  12183. if ((len % 4) != 0) // LL is EVIL!!!!
  12184. {
  12185. while (str2.EndsWith("="))
  12186. str2 = str2.Substring(0, str2.Length - 1);
  12187. len = str2.Length;
  12188. int mod = len % 4;
  12189. if (mod == 1)
  12190. str2 = str2.Substring(0, str2.Length - 1);
  12191. else if (mod == 2)
  12192. str2 += "==";
  12193. else if (mod == 3)
  12194. str2 += "=";
  12195. }
  12196. byte[] data1;
  12197. byte[] data2;
  12198. try
  12199. {
  12200. data1 = Convert.FromBase64String(str1);
  12201. data2 = Convert.FromBase64String(str2);
  12202. }
  12203. catch (Exception)
  12204. {
  12205. return new LSL_String(String.Empty);
  12206. }
  12207. byte[] d2 = new Byte[data1.Length];
  12208. int pos = 0;
  12209. if (data1.Length <= data2.Length)
  12210. {
  12211. Array.Copy(data2, 0, d2, 0, data1.Length);
  12212. }
  12213. else
  12214. {
  12215. while (pos < data1.Length)
  12216. {
  12217. len = data1.Length - pos;
  12218. if (len > data2.Length)
  12219. len = data2.Length;
  12220. Array.Copy(data2, 0, d2, pos, len);
  12221. pos += len;
  12222. }
  12223. }
  12224. for (pos = 0 ; pos < data1.Length ; pos++ )
  12225. data1[pos] ^= d2[pos];
  12226. return Convert.ToBase64String(data1);
  12227. }
  12228. public LSL_Key llHTTPRequest(string url, LSL_List parameters, string body)
  12229. {
  12230. m_host.AddScriptLPS(1);
  12231. IHttpRequestModule httpScriptMod = m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  12232. if(httpScriptMod == null)
  12233. return "";
  12234. if(!httpScriptMod.CheckThrottle(m_host.LocalId, m_host.OwnerID))
  12235. return ScriptBaseClass.NULL_KEY;
  12236. List<string> param = new List<string>();
  12237. bool ok;
  12238. int nCustomHeaders = 0;
  12239. for (int i = 0; i < parameters.Data.Length; i += 2)
  12240. {
  12241. ok = Int32.TryParse(parameters.Data[i].ToString(), out int flag);
  12242. if (!ok || flag < 0 ||
  12243. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  12244. {
  12245. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  12246. }
  12247. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  12248. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  12249. {
  12250. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  12251. }
  12252. else
  12253. {
  12254. //Parameters are in pairs and custom header takes
  12255. //arguments in pairs so adjust for header marker.
  12256. ++i;
  12257. //Maximum of 8 headers are allowed based on the
  12258. //Second Life documentation for llHTTPRequest.
  12259. for (int count = 1; count <= 8; ++count)
  12260. {
  12261. if(nCustomHeaders >= 8)
  12262. {
  12263. Error("llHTTPRequest", "Max number of custom headers is 8, excess ignored");
  12264. break;
  12265. }
  12266. //Enough parameters remaining for (another) header?
  12267. if (parameters.Data.Length - i < 2)
  12268. {
  12269. //There must be at least one name/value pair for custom header
  12270. if (count == 1)
  12271. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  12272. break;
  12273. }
  12274. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString()))
  12275. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  12276. param.Add(parameters.Data[i].ToString());
  12277. param.Add(parameters.Data[i+1].ToString());
  12278. nCustomHeaders++;
  12279. //Have we reached the end of the list of headers?
  12280. //End is marked by a string with a single digit.
  12281. if (i + 2 >= parameters.Data.Length ||
  12282. Char.IsDigit(parameters.Data[i + 2].ToString()[0]))
  12283. {
  12284. break;
  12285. }
  12286. i += 2;
  12287. }
  12288. }
  12289. }
  12290. Vector3 position = m_host.AbsolutePosition;
  12291. Vector3 velocity = m_host.Velocity;
  12292. Quaternion rotation = m_host.RotationOffset;
  12293. string ownerName = String.Empty;
  12294. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  12295. if (scenePresence == null)
  12296. ownerName = resolveName(m_host.OwnerID);
  12297. else
  12298. ownerName = scenePresence.Name;
  12299. RegionInfo regionInfo = World.RegionInfo;
  12300. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  12301. string shard = "OpenSim";
  12302. IConfigSource config = m_ScriptEngine.ConfigSource;
  12303. if (config.Configs["Network"] != null)
  12304. {
  12305. shard = config.Configs["Network"].GetString("shard", shard);
  12306. }
  12307. httpHeaders["X-SecondLife-Shard"] = shard;
  12308. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  12309. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  12310. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  12311. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  12312. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  12313. 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);
  12314. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  12315. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  12316. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  12317. if (userAgent != null)
  12318. httpHeaders["User-Agent"] = userAgent;
  12319. // See if the URL contains any header hacks
  12320. string[] urlParts = url.Split(new char[] {'\n'});
  12321. if (urlParts.Length > 1)
  12322. {
  12323. // Iterate the passed headers and parse them
  12324. for (int i = 1 ; i < urlParts.Length ; i++ )
  12325. {
  12326. // The rest of those would be added to the body in SL.
  12327. // Let's not do that.
  12328. if (urlParts[i] == String.Empty)
  12329. break;
  12330. // See if this could be a valid header
  12331. string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
  12332. if (headerParts.Length != 2)
  12333. continue;
  12334. string headerName = headerParts[0].Trim();
  12335. string headerValue = headerParts[1].Trim();
  12336. // Filter out headers that could be used to abuse
  12337. // another system or cloak the request
  12338. if (headerName.ToLower() == "x-secondlife-shard" ||
  12339. headerName.ToLower() == "x-secondlife-object-name" ||
  12340. headerName.ToLower() == "x-secondlife-object-key" ||
  12341. headerName.ToLower() == "x-secondlife-region" ||
  12342. headerName.ToLower() == "x-secondlife-local-position" ||
  12343. headerName.ToLower() == "x-secondlife-local-velocity" ||
  12344. headerName.ToLower() == "x-secondlife-local-rotation" ||
  12345. headerName.ToLower() == "x-secondlife-owner-name" ||
  12346. headerName.ToLower() == "x-secondlife-owner-key" ||
  12347. headerName.ToLower() == "connection" ||
  12348. headerName.ToLower() == "content-length" ||
  12349. headerName.ToLower() == "from" ||
  12350. headerName.ToLower() == "host" ||
  12351. headerName.ToLower() == "proxy-authorization" ||
  12352. headerName.ToLower() == "referer" ||
  12353. headerName.ToLower() == "trailer" ||
  12354. headerName.ToLower() == "transfer-encoding" ||
  12355. headerName.ToLower() == "via" ||
  12356. headerName.ToLower() == "authorization")
  12357. continue;
  12358. httpHeaders[headerName] = headerValue;
  12359. }
  12360. // Finally, strip any protocol specifier from the URL
  12361. url = urlParts[0].Trim();
  12362. int idx = url.IndexOf(" HTTP/");
  12363. if (idx != -1)
  12364. url = url.Substring(0, idx);
  12365. }
  12366. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  12367. Regex r = new Regex(authregex);
  12368. int[] gnums = r.GetGroupNumbers();
  12369. Match m = r.Match(url);
  12370. if (m.Success)
  12371. {
  12372. for (int i = 1; i < gnums.Length; i++)
  12373. {
  12374. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  12375. //CaptureCollection cc = g.Captures;
  12376. }
  12377. if (m.Groups.Count == 5)
  12378. {
  12379. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  12380. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  12381. }
  12382. }
  12383. UUID reqID = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body,
  12384. out HttpInitialRequestStatus status);
  12385. if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER)
  12386. Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url));
  12387. if (reqID != UUID.Zero)
  12388. return reqID.ToString();
  12389. else
  12390. return "";
  12391. }
  12392. public void llHTTPResponse(LSL_Key id, int status, string body)
  12393. {
  12394. // Partial implementation: support for parameter flags needed
  12395. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  12396. m_host.AddScriptLPS(1);
  12397. if (m_UrlModule != null)
  12398. m_UrlModule.HttpResponse(new UUID(id), status,body);
  12399. }
  12400. public void llResetLandBanList()
  12401. {
  12402. m_host.AddScriptLPS(1);
  12403. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12404. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12405. {
  12406. var todelete = new List<LandAccessEntry>();
  12407. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12408. {
  12409. if (entry.Flags == AccessList.Ban)
  12410. todelete.Add(entry);
  12411. }
  12412. foreach (LandAccessEntry entry in todelete)
  12413. land.ParcelAccessList.Remove(entry);
  12414. }
  12415. ScriptSleep(m_sleepMsOnResetLandBanList);
  12416. }
  12417. public void llResetLandPassList()
  12418. {
  12419. m_host.AddScriptLPS(1);
  12420. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12421. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12422. {
  12423. var todelete = new List<LandAccessEntry>();
  12424. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12425. {
  12426. if (entry.Flags == AccessList.Access)
  12427. todelete.Add(entry);
  12428. }
  12429. foreach (LandAccessEntry entry in todelete)
  12430. land.ParcelAccessList.Remove(entry);
  12431. }
  12432. ScriptSleep(m_sleepMsOnResetLandPassList);
  12433. }
  12434. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  12435. {
  12436. m_host.AddScriptLPS(1);
  12437. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12438. if (lo == null)
  12439. return 0;
  12440. IPrimCounts pc = lo.PrimCounts;
  12441. if (sim_wide != ScriptBaseClass.FALSE)
  12442. {
  12443. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12444. {
  12445. return pc.Simulator;
  12446. }
  12447. else
  12448. {
  12449. // counts not implemented yet
  12450. return 0;
  12451. }
  12452. }
  12453. else
  12454. {
  12455. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12456. return pc.Total;
  12457. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  12458. return pc.Owner;
  12459. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  12460. return pc.Group;
  12461. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  12462. return pc.Others;
  12463. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  12464. return pc.Selected;
  12465. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  12466. return 0; // counts not implemented yet
  12467. }
  12468. return 0;
  12469. }
  12470. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  12471. {
  12472. m_host.AddScriptLPS(1);
  12473. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12474. LSL_List ret = new LSL_List();
  12475. if (land != null)
  12476. {
  12477. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  12478. {
  12479. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  12480. ret.Add(new LSL_Integer(detectedParams.Value));
  12481. }
  12482. }
  12483. ScriptSleep(m_sleepMsOnGetParcelPrimOwners);
  12484. return ret;
  12485. }
  12486. public LSL_Integer llGetObjectPrimCount(LSL_Key object_id)
  12487. {
  12488. m_host.AddScriptLPS(1);
  12489. if(!UUID.TryParse(object_id, out UUID id))
  12490. return 0;
  12491. SceneObjectPart part = World.GetSceneObjectPart(id);
  12492. if (part == null)
  12493. return 0;
  12494. return part.ParentGroup.PrimCount;
  12495. }
  12496. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  12497. {
  12498. m_host.AddScriptLPS(1);
  12499. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12500. if (lo == null)
  12501. return 0;
  12502. if (sim_wide != 0)
  12503. return lo.GetSimulatorMaxPrimCount();
  12504. else
  12505. return lo.GetParcelMaxPrimCount();
  12506. }
  12507. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  12508. {
  12509. m_host.AddScriptLPS(1);
  12510. LandData land = World.GetLandData(pos);
  12511. if (land == null)
  12512. {
  12513. return new LSL_List(0);
  12514. }
  12515. LSL_List ret = new LSL_List();
  12516. foreach (object o in param.Data)
  12517. {
  12518. switch (o.ToString())
  12519. {
  12520. case "0":
  12521. ret.Add(new LSL_String(land.Name));
  12522. break;
  12523. case "1":
  12524. ret.Add(new LSL_String(land.Description));
  12525. break;
  12526. case "2":
  12527. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  12528. break;
  12529. case "3":
  12530. ret.Add(new LSL_Key(land.GroupID.ToString()));
  12531. break;
  12532. case "4":
  12533. ret.Add(new LSL_Integer(land.Area));
  12534. break;
  12535. case "5":
  12536. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  12537. break;
  12538. case "64":
  12539. ret.Add(new LSL_Integer(land.Dwell));
  12540. break;
  12541. default:
  12542. ret.Add(new LSL_Integer(0));
  12543. break;
  12544. }
  12545. }
  12546. return ret;
  12547. }
  12548. public LSL_String llStringTrim(LSL_String src, LSL_Integer type)
  12549. {
  12550. m_host.AddScriptLPS(1);
  12551. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return ((string)src).TrimStart(); }
  12552. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return ((string)src).TrimEnd(); }
  12553. if (type == (int)ScriptBaseClass.STRING_TRIM) { return ((string)src).Trim(); }
  12554. return src;
  12555. }
  12556. public LSL_List llGetObjectDetails(LSL_Key id, LSL_List args)
  12557. {
  12558. m_host.AddScriptLPS(1);
  12559. LSL_List ret = new LSL_List();
  12560. UUID key = new UUID();
  12561. if (!UUID.TryParse(id, out key))
  12562. return ret;
  12563. int count = 0;
  12564. ScenePresence av = World.GetScenePresence(key);
  12565. if (av != null)
  12566. {
  12567. List<SceneObjectGroup> Attachments = null;
  12568. int? nAnimated = null;
  12569. foreach (object o in args.Data)
  12570. {
  12571. switch (int.Parse(o.ToString()))
  12572. {
  12573. case ScriptBaseClass.OBJECT_NAME:
  12574. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  12575. break;
  12576. case ScriptBaseClass.OBJECT_DESC:
  12577. ret.Add(new LSL_String(""));
  12578. break;
  12579. case ScriptBaseClass.OBJECT_POS:
  12580. Vector3 avpos;
  12581. if (av.ParentID != 0 && av.ParentPart != null &&
  12582. av.ParentPart.ParentGroup != null && av.ParentPart.ParentGroup.RootPart != null )
  12583. {
  12584. avpos = av.OffsetPosition;
  12585. if(!av.LegacySitOffsets)
  12586. {
  12587. Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
  12588. avpos -= sitOffset;
  12589. }
  12590. SceneObjectPart sitRoot = av.ParentPart.ParentGroup.RootPart;
  12591. avpos = sitRoot.GetWorldPosition() + avpos * sitRoot.GetWorldRotation();
  12592. }
  12593. else
  12594. avpos = av.AbsolutePosition;
  12595. ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
  12596. break;
  12597. case ScriptBaseClass.OBJECT_ROT:
  12598. Quaternion avrot = av.GetWorldRotation();
  12599. ret.Add(new LSL_Rotation(avrot));
  12600. break;
  12601. case ScriptBaseClass.OBJECT_VELOCITY:
  12602. Vector3 avvel = av.GetWorldVelocity();
  12603. ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
  12604. break;
  12605. case ScriptBaseClass.OBJECT_OWNER:
  12606. ret.Add(new LSL_Key((string)id));
  12607. break;
  12608. case ScriptBaseClass.OBJECT_GROUP:
  12609. ret.Add(new LSL_String(ScriptBaseClass.NULL_KEY));
  12610. break;
  12611. case ScriptBaseClass.OBJECT_CREATOR:
  12612. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12613. break;
  12614. // For the following 8 see the Object version below
  12615. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12616. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  12617. break;
  12618. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12619. ret.Add(new LSL_Integer(av.ScriptCount()));
  12620. break;
  12621. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12622. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  12623. break;
  12624. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12625. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  12626. break;
  12627. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12628. ret.Add(new LSL_Integer(1));
  12629. break;
  12630. case ScriptBaseClass.OBJECT_SERVER_COST:
  12631. ret.Add(new LSL_Float(0));
  12632. break;
  12633. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12634. ret.Add(new LSL_Float(0));
  12635. break;
  12636. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12637. ret.Add(new LSL_Float(0));
  12638. break;
  12639. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12640. ret.Add(new LSL_Float(0));
  12641. break;
  12642. case ScriptBaseClass.OBJECT_ROOT:
  12643. SceneObjectPart p = av.ParentPart;
  12644. if (p != null)
  12645. {
  12646. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  12647. }
  12648. else
  12649. {
  12650. ret.Add(new LSL_Key((string)id));
  12651. }
  12652. break;
  12653. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12654. ret.Add(new LSL_Integer(0));
  12655. break;
  12656. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  12657. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  12658. break;
  12659. case ScriptBaseClass.OBJECT_PHYSICS:
  12660. ret.Add(new LSL_Integer(0));
  12661. break;
  12662. case ScriptBaseClass.OBJECT_PHANTOM:
  12663. ret.Add(new LSL_Integer(0));
  12664. break;
  12665. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12666. ret.Add(new LSL_Integer(0));
  12667. break;
  12668. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12669. ret.Add(new LSL_Integer(-1));
  12670. break;
  12671. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12672. ret.Add(new LSL_Float(0));
  12673. break;
  12674. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12675. LSL_Float shapeType;
  12676. if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0)
  12677. shapeType = new LSL_Float(1);
  12678. else
  12679. shapeType = new LSL_Float(0);
  12680. ret.Add(shapeType);
  12681. break;
  12682. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12683. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12684. break;
  12685. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12686. ret.Add(new LSL_Integer(0));
  12687. break;
  12688. case ScriptBaseClass.OBJECT_OMEGA:
  12689. ret.Add(new LSL_Vector(Vector3.Zero));
  12690. break;
  12691. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12692. if (Attachments == null)
  12693. Attachments = av.GetAttachments();
  12694. count = 0;
  12695. try
  12696. {
  12697. foreach (SceneObjectGroup Attachment in Attachments)
  12698. count += Attachment.PrimCount;
  12699. }
  12700. catch { };
  12701. ret.Add(new LSL_Integer(count));
  12702. break;
  12703. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12704. if (Attachments == null)
  12705. Attachments = av.GetAttachments();
  12706. count = 0;
  12707. try
  12708. {
  12709. foreach (SceneObjectGroup Attachment in Attachments)
  12710. {
  12711. SceneObjectPart[] parts = Attachment.Parts;
  12712. for(int i = 0; i < parts.Length; i++)
  12713. count += parts[i].Inventory.Count;
  12714. }
  12715. } catch { };
  12716. ret.Add(new LSL_Integer(count));
  12717. break;
  12718. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12719. ret.Add(new LSL_Key((string)id));
  12720. break;
  12721. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12722. ret.Add(new LSL_String(av.Grouptitle));
  12723. break;
  12724. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12725. ret.Add(new LSL_Integer(0));
  12726. break;
  12727. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  12728. ret.Add(new LSL_Integer(Constants.MaxAgentAttachments - av.GetAttachmentsCount()));
  12729. break;
  12730. case ScriptBaseClass.OBJECT_CREATION_TIME:
  12731. ret.Add(new LSL_String(""));
  12732. break;
  12733. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  12734. ret.Add(new LSL_Integer(0));
  12735. break;
  12736. case ScriptBaseClass.OBJECT_SIT_COUNT:
  12737. ret.Add(new LSL_Integer(0));
  12738. break;
  12739. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  12740. count = 0;
  12741. if (nAnimated.HasValue)
  12742. count = nAnimated.Value;
  12743. else
  12744. {
  12745. if (Attachments == null)
  12746. Attachments = av.GetAttachments();
  12747. try
  12748. {
  12749. for(int i = 0; i < Attachments.Count;++i)
  12750. {
  12751. if(Attachments[i].RootPart.Shape.MeshFlagEntry)
  12752. ++count;
  12753. }
  12754. }
  12755. catch { };
  12756. nAnimated = count;
  12757. }
  12758. ret.Add(new LSL_Integer(count));
  12759. break;
  12760. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  12761. count = 0;
  12762. if (nAnimated.HasValue)
  12763. count = nAnimated.Value;
  12764. else
  12765. {
  12766. if (Attachments == null)
  12767. Attachments = av.GetAttachments();
  12768. count = 0;
  12769. try
  12770. {
  12771. for (int i = 0; i < Attachments.Count; ++i)
  12772. {
  12773. if (Attachments[i].RootPart.Shape.MeshFlagEntry)
  12774. ++count;
  12775. }
  12776. }
  12777. catch { };
  12778. nAnimated = count;
  12779. }
  12780. count = 2 - count; // for now hardcoded max (simulator features, viewers settings, etc)
  12781. if(count < 0)
  12782. count = 0;
  12783. ret.Add(new LSL_Integer(count));
  12784. break;
  12785. default:
  12786. // Invalid or unhandled constant.
  12787. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12788. break;
  12789. }
  12790. }
  12791. return ret;
  12792. }
  12793. SceneObjectPart obj = World.GetSceneObjectPart(key);
  12794. if (obj != null)
  12795. {
  12796. foreach (object o in args.Data)
  12797. {
  12798. switch (int.Parse(o.ToString()))
  12799. {
  12800. case ScriptBaseClass.OBJECT_NAME:
  12801. ret.Add(new LSL_String(obj.Name));
  12802. break;
  12803. case ScriptBaseClass.OBJECT_DESC:
  12804. ret.Add(new LSL_String(obj.Description));
  12805. break;
  12806. case ScriptBaseClass.OBJECT_POS:
  12807. Vector3 opos = obj.AbsolutePosition;
  12808. ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
  12809. break;
  12810. case ScriptBaseClass.OBJECT_ROT:
  12811. Quaternion rot = Quaternion.Identity;
  12812. if (obj.ParentGroup.IsAttachment)
  12813. {
  12814. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12815. if (sp != null)
  12816. rot = sp.GetWorldRotation();
  12817. }
  12818. else
  12819. {
  12820. if (obj.ParentGroup.RootPart == obj)
  12821. rot = obj.ParentGroup.GroupRotation;
  12822. else
  12823. rot = obj.GetWorldRotation();
  12824. }
  12825. LSL_Rotation objrot = new LSL_Rotation(rot);
  12826. ret.Add(objrot);
  12827. break;
  12828. case ScriptBaseClass.OBJECT_VELOCITY:
  12829. Vector3 vel = Vector3.Zero;
  12830. if (obj.ParentGroup.IsAttachment)
  12831. {
  12832. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12833. if (sp != null)
  12834. vel = sp.GetWorldVelocity();
  12835. }
  12836. else
  12837. {
  12838. vel = obj.Velocity;
  12839. }
  12840. ret.Add(vel);
  12841. break;
  12842. case ScriptBaseClass.OBJECT_OWNER:
  12843. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  12844. break;
  12845. case ScriptBaseClass.OBJECT_GROUP:
  12846. ret.Add(new LSL_String(obj.GroupID.ToString()));
  12847. break;
  12848. case ScriptBaseClass.OBJECT_CREATOR:
  12849. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  12850. break;
  12851. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12852. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  12853. break;
  12854. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12855. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  12856. break;
  12857. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12858. // The value returned in SL for mono scripts is 65536 * number of active scripts
  12859. // and 16384 * number of active scripts for LSO. since llGetFreememory
  12860. // is coded to give the LSO value use it here
  12861. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  12862. break;
  12863. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12864. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  12865. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  12866. break;
  12867. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12868. // according to the SL wiki A prim or linkset will have prim
  12869. // equivalent of the number of prims in a linkset if it does not
  12870. // contain a mesh anywhere in the link set or is not a normal prim
  12871. // The value returned in SL for normal prims is prim count
  12872. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12873. break;
  12874. // costs below may need to be diferent for root parts, need to check
  12875. case ScriptBaseClass.OBJECT_SERVER_COST:
  12876. // The linden calculation is here
  12877. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  12878. // The value returned in SL for normal prims looks like the prim count
  12879. ret.Add(new LSL_Float(0));
  12880. break;
  12881. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12882. // The value returned in SL for normal prims is prim count * 0.06
  12883. ret.Add(new LSL_Float(obj.StreamingCost));
  12884. break;
  12885. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12886. // The value returned in SL for normal prims is prim count
  12887. ret.Add(new LSL_Float(obj.PhysicsCost));
  12888. break;
  12889. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12890. ret.Add(new LSL_Float(0));
  12891. break;
  12892. case ScriptBaseClass.OBJECT_ROOT:
  12893. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  12894. break;
  12895. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12896. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  12897. break;
  12898. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  12899. byte pcode = obj.Shape.PCode;
  12900. if (obj.ParentGroup.AttachmentPoint != 0
  12901. || pcode == (byte)PCode.Grass
  12902. || pcode == (byte)PCode.Tree
  12903. || pcode == (byte)PCode.NewTree)
  12904. {
  12905. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  12906. }
  12907. else
  12908. {
  12909. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  12910. }
  12911. break;
  12912. case ScriptBaseClass.OBJECT_PHYSICS:
  12913. if (obj.ParentGroup.AttachmentPoint != 0)
  12914. {
  12915. ret.Add(new LSL_Integer(0)); // Always false if attached
  12916. }
  12917. else
  12918. {
  12919. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  12920. }
  12921. break;
  12922. case ScriptBaseClass.OBJECT_PHANTOM:
  12923. if (obj.ParentGroup.AttachmentPoint != 0)
  12924. {
  12925. ret.Add(new LSL_Integer(0)); // Always false if attached
  12926. }
  12927. else
  12928. {
  12929. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  12930. }
  12931. break;
  12932. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12933. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  12934. break;
  12935. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12936. ret.Add(new LSL_Integer(0));
  12937. break;
  12938. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12939. ret.Add(new LSL_Float(0));
  12940. break;
  12941. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12942. ret.Add(new LSL_Float(-1));
  12943. break;
  12944. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12945. ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString()));
  12946. break;
  12947. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12948. ret.Add(new LSL_Integer(obj.ClickAction));
  12949. break;
  12950. case ScriptBaseClass.OBJECT_OMEGA:
  12951. ret.Add(new LSL_Vector(obj.AngularVelocity));
  12952. break;
  12953. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12954. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12955. break;
  12956. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12957. SceneObjectPart[] parts = obj.ParentGroup.Parts;
  12958. count = 0;
  12959. for(int i = 0; i < parts.Length; i++)
  12960. count += parts[i].Inventory.Count;
  12961. ret.Add(new LSL_Integer(count));
  12962. break;
  12963. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12964. ret.Add(new LSL_Key(obj.ParentGroup.RezzerID.ToString()));
  12965. break;
  12966. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12967. ret.Add(new LSL_String(String.Empty));
  12968. break;
  12969. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12970. if (obj.ParentGroup.AttachmentPoint != 0 && obj.ParentGroup.FromItemID == UUID.Zero)
  12971. {
  12972. ret.Add(new LSL_Integer(1));
  12973. }
  12974. else
  12975. {
  12976. ret.Add(new LSL_Integer(0));
  12977. }
  12978. break;
  12979. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  12980. ret.Add(new LSL_Integer(0));
  12981. break;
  12982. case ScriptBaseClass.OBJECT_CREATION_TIME:
  12983. DateTime date = Util.ToDateTime(m_host.ParentGroup.RootPart.CreationDate);
  12984. ret.Add(new LSL_String(date.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)));
  12985. break;
  12986. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  12987. ret.Add(new LSL_Integer(0));
  12988. break;
  12989. case ScriptBaseClass.OBJECT_SIT_COUNT:
  12990. ret.Add(new LSL_Integer(m_host.ParentGroup.GetSittingAvatarsCount()));
  12991. break;
  12992. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  12993. if(m_host.ParentGroup.RootPart.Shape.MeshFlagEntry)
  12994. ret.Add(new LSL_Integer(1));
  12995. else
  12996. ret.Add(new LSL_Integer(0));
  12997. break;
  12998. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  12999. ret.Add(new LSL_Integer(0));
  13000. break;
  13001. default:
  13002. // Invalid or unhandled constant.
  13003. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  13004. break;
  13005. }
  13006. }
  13007. }
  13008. return ret;
  13009. }
  13010. internal UUID GetScriptByName(string name)
  13011. {
  13012. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13013. if (item == null || item.Type != 10)
  13014. return UUID.Zero;
  13015. return item.ItemID;
  13016. }
  13017. /// <summary>
  13018. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  13019. /// </summary>
  13020. /// <param name="command">The name of the command that generated the error.</param>
  13021. /// <param name="message">The error message to report to the user.</param>
  13022. internal void Error(string command, string message)
  13023. {
  13024. string text = command + ": " + message;
  13025. if (text.Length > 1023)
  13026. {
  13027. text = text.Substring(0, 1023);
  13028. }
  13029. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  13030. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  13031. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  13032. if (wComm != null)
  13033. {
  13034. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  13035. }
  13036. Sleep(1000);
  13037. }
  13038. /// <summary>
  13039. /// Reports that the command is not implemented as a script error.
  13040. /// </summary>
  13041. /// <param name="command">The name of the command that is not implemented.</param>
  13042. /// <param name="message">Additional information to report to the user. (Optional)</param>
  13043. internal void NotImplemented(string command, string message = "")
  13044. {
  13045. if (throwErrorOnNotImplemented)
  13046. {
  13047. if (message != "")
  13048. {
  13049. message = " - " + message;
  13050. }
  13051. throw new NotImplementedException("Command not implemented: " + command + message);
  13052. }
  13053. else
  13054. {
  13055. string text = "Command not implemented";
  13056. if (message != "")
  13057. {
  13058. text = text + " - " + message;
  13059. }
  13060. Error(command, text);
  13061. }
  13062. }
  13063. /// <summary>
  13064. /// Reports that the command is deprecated as a script error.
  13065. /// </summary>
  13066. /// <param name="command">The name of the command that is deprecated.</param>
  13067. /// <param name="message">Additional information to report to the user. (Optional)</param>
  13068. internal void Deprecated(string command, string message = "")
  13069. {
  13070. string text = "Command deprecated";
  13071. if (message != "")
  13072. {
  13073. text = text + " - " + message;
  13074. }
  13075. Error(command, text);
  13076. }
  13077. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  13078. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  13079. {
  13080. World.AssetService.Get(assetID.ToString(), this,
  13081. delegate(string i, object sender, AssetBase a)
  13082. {
  13083. UUID uuid = UUID.Zero;
  13084. UUID.TryParse(i, out uuid);
  13085. cb(uuid, a);
  13086. });
  13087. }
  13088. public LSL_Key llGetNumberOfNotecardLines(string name)
  13089. {
  13090. m_host.AddScriptLPS(1);
  13091. UUID assetID = UUID.Zero;
  13092. if (!UUID.TryParse(name, out assetID))
  13093. {
  13094. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13095. if (item != null && item.Type == 7)
  13096. assetID = item.AssetID;
  13097. }
  13098. if (assetID == UUID.Zero)
  13099. {
  13100. // => complain loudly, as specified by the LSL docs
  13101. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  13102. return ScriptBaseClass.NULL_KEY;
  13103. }
  13104. if (NotecardCache.IsCached(assetID))
  13105. {
  13106. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId, m_item.ItemID, NotecardCache.GetLines(assetID).ToString());
  13107. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  13108. return ftid;
  13109. }
  13110. Action<string> act = eventID =>
  13111. {
  13112. if (NotecardCache.IsCached(assetID))
  13113. {
  13114. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLines(assetID).ToString());
  13115. return;
  13116. }
  13117. AssetBase a = World.AssetService.Get(assetID.ToString());
  13118. if (a == null || a.Type != 7)
  13119. {
  13120. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, string.Empty);
  13121. return;
  13122. }
  13123. NotecardCache.Cache(assetID, a.Data);
  13124. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLines(assetID).ToString());
  13125. };
  13126. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13127. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  13128. return tid.ToString();
  13129. }
  13130. public LSL_Key llGetNotecardLine(string name, int line)
  13131. {
  13132. m_host.AddScriptLPS(1);
  13133. UUID assetID = UUID.Zero;
  13134. if (!UUID.TryParse(name, out assetID))
  13135. {
  13136. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13137. if (item != null && item.Type == 7)
  13138. assetID = item.AssetID;
  13139. }
  13140. if (assetID == UUID.Zero)
  13141. {
  13142. // => complain loudly, as specified by the LSL docs
  13143. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  13144. return ScriptBaseClass.NULL_KEY;
  13145. }
  13146. if (NotecardCache.IsCached(assetID))
  13147. {
  13148. string eid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId, m_item.ItemID,
  13149. NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13150. ScriptSleep(m_sleepMsOnGetNotecardLine);
  13151. return eid;
  13152. }
  13153. Action<string> act = eventID =>
  13154. {
  13155. if (NotecardCache.IsCached(assetID))
  13156. {
  13157. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13158. return;
  13159. }
  13160. AssetBase a = World.AssetService.Get(assetID.ToString());
  13161. if (a == null || a.Type != 7)
  13162. {
  13163. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, string.Empty);
  13164. return;
  13165. }
  13166. NotecardCache.Cache(assetID, a.Data);
  13167. m_AsyncCommands.DataserverPlugin.DataserverReply(
  13168. eventID, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13169. };
  13170. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13171. ScriptSleep(m_sleepMsOnGetNotecardLine);
  13172. return tid.ToString();
  13173. }
  13174. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  13175. {
  13176. if (!UUID.TryParse(prim, out UUID id))
  13177. return;
  13178. SceneObjectPart obj = World.GetSceneObjectPart(id);
  13179. if (obj == null || obj.OwnerID != m_host.OwnerID)
  13180. return;
  13181. uint rulesParsed = 0;
  13182. LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
  13183. while (remaining.Length > 2)
  13184. {
  13185. int linknumber;
  13186. try
  13187. {
  13188. linknumber = remaining.GetLSLIntegerItem(0);
  13189. }
  13190. catch (InvalidCastException)
  13191. {
  13192. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET parameter must be integer", rulesParsed));
  13193. return;
  13194. }
  13195. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13196. if (entities.Count == 0)
  13197. break;
  13198. rules = remaining.GetSublist(1, -1);
  13199. foreach (ISceneEntity entity in entities)
  13200. {
  13201. if (entity is SceneObjectPart)
  13202. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  13203. else
  13204. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  13205. }
  13206. }
  13207. }
  13208. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  13209. {
  13210. LSL_List result = new LSL_List();
  13211. if (!UUID.TryParse(prim, out UUID id))
  13212. return result;
  13213. SceneObjectPart obj = World.GetSceneObjectPart(id);
  13214. if (obj == null || obj.OwnerID != m_host.OwnerID)
  13215. return result;
  13216. LSL_List remaining = GetPrimParams(obj, rules, ref result);
  13217. while (remaining.Length > 1)
  13218. {
  13219. int linknumber;
  13220. try
  13221. {
  13222. linknumber = remaining.GetLSLIntegerItem(0);
  13223. }
  13224. catch (InvalidCastException)
  13225. {
  13226. Error("", string.Format("Error PRIM_LINK_TARGET: parameter must be integer"));
  13227. return result;
  13228. }
  13229. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13230. if (entities.Count == 0)
  13231. break;
  13232. rules = remaining.GetSublist(1, -1);
  13233. foreach (ISceneEntity entity in entities)
  13234. {
  13235. if (entity is SceneObjectPart)
  13236. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  13237. else
  13238. remaining = GetPrimParams((ScenePresence)entity, rules, ref result);
  13239. }
  13240. }
  13241. return result;
  13242. }
  13243. public void print(string str)
  13244. {
  13245. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  13246. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  13247. if (ossl != null)
  13248. {
  13249. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  13250. m_log.Info("LSL print():" + str);
  13251. }
  13252. }
  13253. public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
  13254. {
  13255. List<SceneObjectPart> parts = GetLinkParts(link);
  13256. if (parts.Count < 1)
  13257. return 0;
  13258. return GetNumberOfSides(parts[0]);
  13259. }
  13260. private string Name2Username(string name)
  13261. {
  13262. string[] parts = name.Split(new char[] {' '});
  13263. if (parts.Length < 2)
  13264. return name.ToLower();
  13265. if (parts[1] == "Resident")
  13266. return parts[0].ToLower();
  13267. return name.Replace(" ", ".").ToLower();
  13268. }
  13269. public LSL_String llGetUsername(LSL_Key id)
  13270. {
  13271. return Name2Username(llKey2Name(id));
  13272. }
  13273. public LSL_Key llRequestUsername(LSL_Key id)
  13274. {
  13275. m_host.AddScriptLPS(1);
  13276. if (!UUID.TryParse(id, out UUID key) || key == UUID.Zero)
  13277. return string.Empty;
  13278. ScenePresence lpresence = World.GetScenePresence(key);
  13279. if (lpresence != null)
  13280. {
  13281. string lname = lpresence.Name;
  13282. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  13283. m_item.ItemID, Name2Username(lname));
  13284. return ftid;
  13285. }
  13286. Action<string> act = eventID =>
  13287. {
  13288. string name = String.Empty;
  13289. ScenePresence presence = World.GetScenePresence(key);
  13290. if (presence != null)
  13291. {
  13292. name = presence.Name;
  13293. }
  13294. else if (World.TryGetSceneObjectPart(key, out SceneObjectPart sop ) && sop != null)
  13295. {
  13296. name = sop.Name;
  13297. }
  13298. else
  13299. {
  13300. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, key);
  13301. if(account != null)
  13302. {
  13303. name = account.FirstName + " " + account.LastName;
  13304. }
  13305. }
  13306. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, Name2Username(name));
  13307. };
  13308. UUID rq = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13309. ScriptSleep(m_sleepMsOnRequestAgentData);
  13310. return rq.ToString();
  13311. }
  13312. public LSL_String llGetDisplayName(LSL_Key id)
  13313. {
  13314. m_host.AddScriptLPS(1);
  13315. if (UUID.TryParse(id, out UUID key) && key != UUID.Zero)
  13316. {
  13317. ScenePresence presence = World.GetScenePresence(key);
  13318. if (presence != null)
  13319. {
  13320. return presence.Name;
  13321. }
  13322. }
  13323. return String.Empty;
  13324. }
  13325. public LSL_Key llRequestDisplayName(LSL_Key id)
  13326. {
  13327. m_host.AddScriptLPS(1);
  13328. if (!UUID.TryParse(id, out UUID key) || key == UUID.Zero)
  13329. return string.Empty;
  13330. ScenePresence lpresence = World.GetScenePresence(key);
  13331. if (lpresence != null)
  13332. {
  13333. string lname = lpresence.Name;
  13334. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  13335. m_item.ItemID, lname);
  13336. return ftid;
  13337. }
  13338. Action<string> act = eventID =>
  13339. {
  13340. string name = String.Empty;
  13341. ScenePresence presence = World.GetScenePresence(key);
  13342. if (presence != null)
  13343. {
  13344. name = presence.Name;
  13345. }
  13346. else if (World.TryGetSceneObjectPart(key, out SceneObjectPart sop) && sop != null)
  13347. {
  13348. name = sop.Name;
  13349. }
  13350. else
  13351. {
  13352. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, key);
  13353. if (account != null)
  13354. {
  13355. name = account.FirstName + " " + account.LastName;
  13356. }
  13357. }
  13358. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, name);
  13359. };
  13360. UUID rq = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13361. return rq.ToString();
  13362. }
  13363. private struct Tri
  13364. {
  13365. public Vector3 p1;
  13366. public Vector3 p2;
  13367. public Vector3 p3;
  13368. }
  13369. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  13370. {
  13371. float height = avatar.Appearance.AvatarHeight;
  13372. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  13373. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  13374. if (point.X > b1.X && point.X < b2.X &&
  13375. point.Y > b1.Y && point.Y < b2.Y &&
  13376. point.Z > b1.Z && point.Z < b2.Z)
  13377. return true;
  13378. return false;
  13379. }
  13380. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd, bool skipPhys)
  13381. {
  13382. List<ContactResult> contacts = new List<ContactResult>();
  13383. Vector3 ab = rayEnd - rayStart;
  13384. float ablen = ab.Length();
  13385. World.ForEachScenePresence(delegate(ScenePresence sp)
  13386. {
  13387. if(skipPhys && sp.PhysicsActor != null)
  13388. return;
  13389. Vector3 ac = sp.AbsolutePosition - rayStart;
  13390. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / ablen);
  13391. if (d > 1.5)
  13392. return;
  13393. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13394. if (d2 > 0)
  13395. return;
  13396. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  13397. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  13398. if (!InBoundingBox(sp, p))
  13399. return;
  13400. ContactResult result = new ContactResult
  13401. {
  13402. ConsumerID = sp.LocalId,
  13403. Depth = Vector3.Distance(rayStart, p),
  13404. Normal = Vector3.Zero,
  13405. Pos = p
  13406. };
  13407. contacts.Add(result);
  13408. });
  13409. return contacts.ToArray();
  13410. }
  13411. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  13412. {
  13413. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13414. List<ContactResult> contacts = new List<ContactResult>();
  13415. Vector3 ab = rayEnd - rayStart;
  13416. World.ForEachSOG(delegate(SceneObjectGroup group)
  13417. {
  13418. if (m_host.ParentGroup == group)
  13419. return;
  13420. if (group.IsAttachment)
  13421. return;
  13422. if (group.RootPart.PhysActor == null)
  13423. {
  13424. if (!includePhantom)
  13425. return;
  13426. }
  13427. else
  13428. {
  13429. if (group.RootPart.PhysActor.IsPhysical)
  13430. {
  13431. if (!includePhysical)
  13432. return;
  13433. }
  13434. else
  13435. {
  13436. if (!includeNonPhysical)
  13437. return;
  13438. }
  13439. }
  13440. // Find the radius ouside of which we don't even need to hit test
  13441. float radius = 0.0f;
  13442. group.GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ);
  13443. if (Math.Abs(minX) > radius)
  13444. radius = Math.Abs(minX);
  13445. if (Math.Abs(minY) > radius)
  13446. radius = Math.Abs(minY);
  13447. if (Math.Abs(minZ) > radius)
  13448. radius = Math.Abs(minZ);
  13449. if (Math.Abs(maxX) > radius)
  13450. radius = Math.Abs(maxX);
  13451. if (Math.Abs(maxY) > radius)
  13452. radius = Math.Abs(maxY);
  13453. if (Math.Abs(maxZ) > radius)
  13454. radius = Math.Abs(maxZ);
  13455. radius = radius*1.413f;
  13456. Vector3 ac = group.AbsolutePosition - rayStart;
  13457. // Vector3 bc = group.AbsolutePosition - rayEnd;
  13458. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  13459. // Too far off ray, don't bother
  13460. if (d > radius)
  13461. return;
  13462. // Behind ray, drop
  13463. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13464. if (d2 > 0)
  13465. return;
  13466. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13467. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  13468. // Miss.
  13469. if (!intersection.HitTF)
  13470. return;
  13471. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  13472. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  13473. //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);
  13474. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  13475. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  13476. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  13477. return;
  13478. ContactResult result = new ContactResult
  13479. {
  13480. ConsumerID = group.LocalId,
  13481. //Depth = intersection.distance;
  13482. Normal = intersection.normal,
  13483. Pos = intersection.ipoint
  13484. };
  13485. result.Depth = Vector3.Mag(rayStart - result.Pos);
  13486. contacts.Add(result);
  13487. });
  13488. return contacts.ToArray();
  13489. }
  13490. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  13491. {
  13492. double[,] heightfield = World.Heightmap.GetDoubles();
  13493. List<ContactResult> contacts = new List<ContactResult>();
  13494. double min = 2048.0;
  13495. double max = 0.0;
  13496. // Find the min and max of the heightfield
  13497. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  13498. {
  13499. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  13500. {
  13501. if (heightfield[x, y] > max)
  13502. max = heightfield[x, y];
  13503. if (heightfield[x, y] < min)
  13504. min = heightfield[x, y];
  13505. }
  13506. }
  13507. // A ray extends past rayEnd, but doesn't go back before
  13508. // rayStart. If the start is above the highest point of the ground
  13509. // and the ray goes up, we can't hit the ground. Ever.
  13510. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  13511. return null;
  13512. // Same for going down
  13513. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  13514. return null;
  13515. List<Tri> trilist = new List<Tri>();
  13516. // Create our triangle list
  13517. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  13518. {
  13519. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  13520. {
  13521. Tri t1 = new Tri();
  13522. Tri t2 = new Tri();
  13523. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  13524. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  13525. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  13526. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  13527. t1.p1 = p1;
  13528. t1.p2 = p2;
  13529. t1.p3 = p3;
  13530. t2.p1 = p3;
  13531. t2.p2 = p4;
  13532. t2.p3 = p1;
  13533. trilist.Add(t1);
  13534. trilist.Add(t2);
  13535. }
  13536. }
  13537. // Ray direction
  13538. Vector3 rayDirection = rayEnd - rayStart;
  13539. foreach (Tri t in trilist)
  13540. {
  13541. // Compute triangle plane normal and edges
  13542. Vector3 u = t.p2 - t.p1;
  13543. Vector3 v = t.p3 - t.p1;
  13544. Vector3 n = Vector3.Cross(u, v);
  13545. if (n == Vector3.Zero)
  13546. continue;
  13547. Vector3 w0 = rayStart - t.p1;
  13548. double a = -Vector3.Dot(n, w0);
  13549. double b = Vector3.Dot(n, rayDirection);
  13550. // Not intersecting the plane, or in plane (same thing)
  13551. // Ignoring this MAY cause the ground to not be detected
  13552. // sometimes
  13553. if (Math.Abs(b) < 0.000001)
  13554. continue;
  13555. double r = a / b;
  13556. // ray points away from plane
  13557. if (r < 0.0)
  13558. continue;
  13559. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  13560. float uu = Vector3.Dot(u, u);
  13561. float uv = Vector3.Dot(u, v);
  13562. float vv = Vector3.Dot(v, v);
  13563. Vector3 w = ip - t.p1;
  13564. float wu = Vector3.Dot(w, u);
  13565. float wv = Vector3.Dot(w, v);
  13566. float d = uv * uv - uu * vv;
  13567. float cs = (uv * wv - vv * wu) / d;
  13568. if (cs < 0 || cs > 1.0)
  13569. continue;
  13570. float ct = (uv * wu - uu * wv) / d;
  13571. if (ct < 0 || (cs + ct) > 1.0)
  13572. continue;
  13573. // Add contact point
  13574. ContactResult result = new ContactResult
  13575. {
  13576. ConsumerID = 0,
  13577. Depth = Vector3.Distance(rayStart, ip),
  13578. Normal = n,
  13579. Pos = ip
  13580. };
  13581. contacts.Add(result);
  13582. }
  13583. if (contacts.Count == 0)
  13584. return null;
  13585. contacts.Sort(delegate(ContactResult a, ContactResult b)
  13586. {
  13587. return (int)(a.Depth - b.Depth);
  13588. });
  13589. return contacts[0];
  13590. }
  13591. /*
  13592. // not done:
  13593. private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
  13594. {
  13595. ContactResult[] contacts = null;
  13596. World.ForEachSOG(delegate(SceneObjectGroup group)
  13597. {
  13598. if (m_host.ParentGroup == group)
  13599. return;
  13600. if (group.IsAttachment)
  13601. return;
  13602. if(group.RootPart.PhysActor != null)
  13603. return;
  13604. contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
  13605. });
  13606. return contacts;
  13607. }
  13608. */
  13609. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  13610. {
  13611. LSL_List list = new LSL_List();
  13612. m_host.AddScriptLPS(1);
  13613. Vector3 rayStart = start;
  13614. Vector3 rayEnd = end;
  13615. Vector3 dir = rayEnd - rayStart;
  13616. float dist = dir.Length();
  13617. int count = 1;
  13618. bool detectPhantom = false;
  13619. int dataFlags = 0;
  13620. int rejectTypes = 0;
  13621. for (int i = 0; i < options.Length; i += 2)
  13622. {
  13623. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13624. count = options.GetLSLIntegerItem(i + 1);
  13625. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13626. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  13627. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13628. dataFlags = options.GetLSLIntegerItem(i + 1);
  13629. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13630. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13631. }
  13632. if (count > 16)
  13633. count = 16;
  13634. List<ContactResult> results = new List<ContactResult>();
  13635. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  13636. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  13637. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  13638. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  13639. bool rejectHost = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOST) != 0);
  13640. bool rejectHostGroup = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOSTGROUP) != 0);
  13641. if (World.SupportsRayCastFiltered())
  13642. {
  13643. if (dist == 0)
  13644. return list;
  13645. RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull;
  13646. if (checkTerrain)
  13647. rayfilter |= RayFilterFlags.land;
  13648. if (checkAgents)
  13649. rayfilter |= RayFilterFlags.agent;
  13650. if (checkPhysical)
  13651. rayfilter |= RayFilterFlags.physical;
  13652. if (checkNonPhysical)
  13653. rayfilter |= RayFilterFlags.nonphysical;
  13654. if (detectPhantom)
  13655. rayfilter |= RayFilterFlags.LSLPhantom;
  13656. Vector3 direction = dir * ( 1/dist);
  13657. if(rayfilter == 0)
  13658. {
  13659. list.Add(new LSL_Integer(0));
  13660. return list;
  13661. }
  13662. // get some more contacts to sort ???
  13663. int physcount = 4 * count;
  13664. if (physcount > 20)
  13665. physcount = 20;
  13666. object physresults;
  13667. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  13668. if (physresults == null)
  13669. {
  13670. // list.Add(new LSL_Integer(-3)); // timeout error
  13671. // return list;
  13672. results = new List<ContactResult>();
  13673. }
  13674. else
  13675. results = (List<ContactResult>)physresults;
  13676. // for now physics doesn't detect sitted avatars so do it outside physics
  13677. if (checkAgents)
  13678. {
  13679. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, true);
  13680. foreach (ContactResult r in agentHits)
  13681. results.Add(r);
  13682. }
  13683. // TODO: Replace this with a better solution. ObjectIntersection can only
  13684. // detect nonphysical phantoms. They are detected by virtue of being
  13685. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  13686. // physicsl phantoms as done by the physics scene
  13687. // We don't want anything else but phantoms here.
  13688. if (detectPhantom)
  13689. {
  13690. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  13691. foreach (ContactResult r in objectHits)
  13692. results.Add(r);
  13693. }
  13694. // Double check this because of current ODE distance problems
  13695. if (checkTerrain && dist > 60)
  13696. {
  13697. bool skipGroundCheck = false;
  13698. foreach (ContactResult c in results)
  13699. {
  13700. if (c.ConsumerID == 0) // Physics gave us a ground collision
  13701. skipGroundCheck = true;
  13702. }
  13703. if (!skipGroundCheck)
  13704. {
  13705. float tmp = dir.X * dir.X + dir.Y * dir.Y;
  13706. if(tmp > 2500)
  13707. {
  13708. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13709. if (groundContact != null)
  13710. results.Add((ContactResult)groundContact);
  13711. }
  13712. }
  13713. }
  13714. }
  13715. else
  13716. {
  13717. if (checkAgents)
  13718. {
  13719. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, false);
  13720. foreach (ContactResult r in agentHits)
  13721. results.Add(r);
  13722. }
  13723. if (checkPhysical || checkNonPhysical || detectPhantom)
  13724. {
  13725. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  13726. for (int iter = 0; iter < objectHits.Length; iter++)
  13727. {
  13728. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  13729. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  13730. results.Add(objectHits[iter]);
  13731. }
  13732. }
  13733. if (checkTerrain)
  13734. {
  13735. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13736. if (groundContact != null)
  13737. results.Add((ContactResult)groundContact);
  13738. }
  13739. }
  13740. results.Sort(delegate(ContactResult a, ContactResult b)
  13741. {
  13742. return a.Depth.CompareTo(b.Depth);
  13743. });
  13744. int values = 0;
  13745. SceneObjectGroup thisgrp = m_host.ParentGroup;
  13746. foreach (ContactResult result in results)
  13747. {
  13748. if (result.Depth > dist)
  13749. continue;
  13750. // physics ray can return colisions with host prim
  13751. if (rejectHost && m_host.LocalId == result.ConsumerID)
  13752. continue;
  13753. UUID itemID = UUID.Zero;
  13754. int linkNum = 0;
  13755. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  13756. // It's a prim!
  13757. if (part != null)
  13758. {
  13759. if (rejectHostGroup && part.ParentGroup == thisgrp)
  13760. continue;
  13761. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  13762. itemID = part.ParentGroup.UUID;
  13763. else
  13764. itemID = part.UUID;
  13765. linkNum = part.LinkNum;
  13766. }
  13767. else
  13768. {
  13769. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  13770. /// It it a boy? a girl?
  13771. if (sp != null)
  13772. itemID = sp.UUID;
  13773. }
  13774. list.Add(new LSL_String(itemID.ToString()));
  13775. list.Add(new LSL_String(result.Pos.ToString()));
  13776. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  13777. list.Add(new LSL_Integer(linkNum));
  13778. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  13779. list.Add(new LSL_Vector(result.Normal));
  13780. values++;
  13781. if (values >= count)
  13782. break;
  13783. }
  13784. list.Add(new LSL_Integer(values));
  13785. return list;
  13786. }
  13787. /// <summary>
  13788. /// Implementation of llCastRay similar to SL 2015-04-21.
  13789. /// http://wiki.secondlife.com/wiki/LlCastRay
  13790. /// Uses pure geometry, bounding shapes, meshing and no physics
  13791. /// for prims, sculpts, meshes, avatars and terrain.
  13792. /// Implements all flags, reject types and data flags.
  13793. /// Can handle both objects/groups and prims/parts, by config.
  13794. /// May sometimes be inaccurate owing to calculation precision,
  13795. /// meshing detail level and a bug in libopenmetaverse PrimMesher.
  13796. /// </summary>
  13797. public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options)
  13798. {
  13799. m_host.AddScriptLPS(1);
  13800. LSL_List result = new LSL_List();
  13801. // Prepare throttle data
  13802. int calledMs = Environment.TickCount;
  13803. Stopwatch stopWatch = new Stopwatch();
  13804. stopWatch.Start();
  13805. UUID regionId = World.RegionInfo.RegionID;
  13806. UUID userId = UUID.Zero;
  13807. int msAvailable = 0;
  13808. // Throttle per owner when attachment or "vehicle" (sat upon)
  13809. if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatarsCount() > 0)
  13810. {
  13811. userId = m_host.OwnerID;
  13812. msAvailable = m_msPerAvatarInCastRay;
  13813. }
  13814. // Throttle per parcel when not attachment or vehicle
  13815. else
  13816. {
  13817. LandData land = World.GetLandData(m_host.GetWorldPosition());
  13818. if (land != null)
  13819. msAvailable = m_msPerRegionInCastRay * land.Area / 65536;
  13820. }
  13821. // Clamp for "oversized" parcels on varregions
  13822. if (msAvailable > m_msMaxInCastRay)
  13823. msAvailable = m_msMaxInCastRay;
  13824. // Check throttle data
  13825. int fromCalledMs = calledMs - m_msThrottleInCastRay;
  13826. lock (m_castRayCalls)
  13827. {
  13828. for (int i = m_castRayCalls.Count - 1; i >= 0; i--)
  13829. {
  13830. // Delete old calls from throttle data
  13831. if (m_castRayCalls[i].CalledMs < fromCalledMs)
  13832. m_castRayCalls.RemoveAt(i);
  13833. // Use current region (in multi-region sims)
  13834. else if (m_castRayCalls[i].RegionId == regionId)
  13835. {
  13836. // Reduce available time with recent calls
  13837. if (m_castRayCalls[i].UserId == userId)
  13838. msAvailable -= m_castRayCalls[i].UsedMs;
  13839. }
  13840. }
  13841. // Return failure if not enough available time
  13842. if (msAvailable < m_msMinInCastRay)
  13843. {
  13844. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED));
  13845. return result;
  13846. }
  13847. }
  13848. // Initialize
  13849. List<RayHit> rayHits = new List<RayHit>();
  13850. float tol = m_floatToleranceInCastRay;
  13851. Vector3 pos1Ray = start;
  13852. Vector3 pos2Ray = end;
  13853. // Get input options
  13854. int rejectTypes = 0;
  13855. int dataFlags = 0;
  13856. int maxHits = 1;
  13857. bool notdetectPhantom = true;
  13858. for (int i = 0; i < options.Length; i += 2)
  13859. {
  13860. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13861. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13862. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13863. dataFlags = options.GetLSLIntegerItem(i + 1);
  13864. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13865. maxHits = options.GetLSLIntegerItem(i + 1);
  13866. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13867. notdetectPhantom = (options.GetLSLIntegerItem(i + 1) == 0);
  13868. }
  13869. if (maxHits > m_maxHitsInCastRay)
  13870. maxHits = m_maxHitsInCastRay;
  13871. bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0);
  13872. bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0);
  13873. bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0);
  13874. bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0);
  13875. bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0);
  13876. bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0);
  13877. bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0);
  13878. // Calculate some basic parameters
  13879. Vector3 vecRay = pos2Ray - pos1Ray;
  13880. float rayLength = vecRay.Length();
  13881. // Try to get a mesher and return failure if none, degenerate ray, or max 0 hits
  13882. IRendering primMesher = null;
  13883. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  13884. if (renderers.Count < 1 || rayLength < tol || m_maxHitsInCastRay < 1)
  13885. {
  13886. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN));
  13887. return result;
  13888. }
  13889. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  13890. // Iterate over all objects/groups and prims/parts in region
  13891. World.ForEachSOG(
  13892. delegate(SceneObjectGroup group)
  13893. {
  13894. if(group.IsDeleted || group.RootPart == null)
  13895. return;
  13896. // Check group filters unless part filters are configured
  13897. bool isPhysical = (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical);
  13898. bool isNonphysical = !isPhysical;
  13899. bool isPhantom = group.IsPhantom || group.IsVolumeDetect;
  13900. bool isAttachment = group.IsAttachment;
  13901. if (isPhysical && rejectPhysical)
  13902. return;
  13903. if (isNonphysical && rejectNonphysical)
  13904. return;
  13905. if (isPhantom && notdetectPhantom)
  13906. return;
  13907. if (isAttachment && !m_doAttachmentsInCastRay)
  13908. return;
  13909. // Parse object/group if passed filters
  13910. // Iterate over all prims/parts in object/group
  13911. foreach(SceneObjectPart part in group.Parts)
  13912. {
  13913. // ignore PhysicsShapeType.None as physics engines do
  13914. // or we will get into trouble in future
  13915. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  13916. continue;
  13917. isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical);
  13918. isNonphysical = !isPhysical;
  13919. isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) ||
  13920. (part.VolumeDetectActive);
  13921. if (isPhysical && rejectPhysical)
  13922. continue;
  13923. if (isNonphysical && rejectNonphysical)
  13924. continue;
  13925. if (isPhantom && notdetectPhantom)
  13926. continue;
  13927. // Parse prim/part and project ray if passed filters
  13928. Vector3 scalePart = part.Scale;
  13929. Vector3 posPart = part.GetWorldPosition();
  13930. Quaternion rotPart = part.GetWorldRotation();
  13931. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  13932. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  13933. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  13934. // Filter parts by shape bounding boxes
  13935. Vector3 shapeBoxMax = new Vector3(0.5f, 0.5f, 0.5f);
  13936. if (!part.Shape.SculptEntry)
  13937. shapeBoxMax = shapeBoxMax * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ));
  13938. shapeBoxMax = shapeBoxMax + (new Vector3(tol, tol, tol));
  13939. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  13940. {
  13941. // Prepare data needed to check for ray hits
  13942. RayTrans rayTrans = new RayTrans
  13943. {
  13944. PartId = part.UUID,
  13945. GroupId = part.ParentGroup.UUID,
  13946. Link = group.PrimCount > 1 ? part.LinkNum : 0,
  13947. ScalePart = scalePart,
  13948. PositionPart = posPart,
  13949. RotationPart = rotPart,
  13950. ShapeNeedsEnds = true,
  13951. Position1Ray = pos1Ray,
  13952. Position1RayProj = pos1RayProj,
  13953. VectorRayProj = pos2RayProj - pos1RayProj
  13954. };
  13955. // Get detail level depending on type
  13956. int lod = 0;
  13957. // Mesh detail level
  13958. if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13959. lod = (int)m_meshLodInCastRay;
  13960. // Sculpt detail level
  13961. else if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13962. lod = (int)m_sculptLodInCastRay;
  13963. // Shape detail level
  13964. else if (!part.Shape.SculptEntry)
  13965. lod = (int)m_primLodInCastRay;
  13966. // Try to get cached mesh if configured
  13967. ulong meshKey = 0;
  13968. FacetedMesh mesh = null;
  13969. if (m_useMeshCacheInCastRay)
  13970. {
  13971. meshKey = part.Shape.GetMeshKey(Vector3.One, (float)(4 << lod));
  13972. lock (m_cachedMeshes)
  13973. {
  13974. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  13975. }
  13976. }
  13977. // Create mesh if no cached mesh
  13978. if (mesh == null)
  13979. {
  13980. // Make an OMV prim to be able to mesh part
  13981. Primitive omvPrim = part.Shape.ToOmvPrimitive(posPart, rotPart);
  13982. byte[] sculptAsset = null;
  13983. if (omvPrim.Sculpt != null)
  13984. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  13985. // When part is mesh, get mesh
  13986. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  13987. {
  13988. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  13989. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, m_meshLodInCastRay, out mesh);
  13990. meshAsset = null;
  13991. }
  13992. // When part is sculpt, create mesh
  13993. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  13994. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  13995. {
  13996. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  13997. if (imgDecoder != null)
  13998. {
  13999. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  14000. if (sculpt != null)
  14001. {
  14002. mesh = primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, m_sculptLodInCastRay);
  14003. sculpt.Dispose();
  14004. }
  14005. }
  14006. }
  14007. // When part is shape, create mesh
  14008. else if (omvPrim.Sculpt == null)
  14009. {
  14010. if (
  14011. omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 &&
  14012. omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 &&
  14013. omvPrim.PrimData.PathSkew == 0.0 &&
  14014. omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0
  14015. )
  14016. rayTrans.ShapeNeedsEnds = false;
  14017. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_primLodInCastRay);
  14018. }
  14019. // Cache mesh if configured
  14020. if (m_useMeshCacheInCastRay && mesh != null)
  14021. {
  14022. lock(m_cachedMeshes)
  14023. {
  14024. if (!m_cachedMeshes.ContainsKey(meshKey))
  14025. m_cachedMeshes.Add(meshKey, mesh);
  14026. }
  14027. }
  14028. }
  14029. // Check mesh for ray hits
  14030. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  14031. mesh = null;
  14032. }
  14033. }
  14034. }
  14035. );
  14036. // Check avatar filter
  14037. if (!rejectAgents)
  14038. {
  14039. // Iterate over all avatars in region
  14040. World.ForEachRootScenePresence(
  14041. delegate (ScenePresence sp)
  14042. {
  14043. // Get bounding box
  14044. BoundingBoxOfScenePresence(sp, out Vector3 lower, out Vector3 upper);
  14045. // Parse avatar
  14046. Vector3 scalePart = upper - lower;
  14047. Vector3 posPart = sp.AbsolutePosition;
  14048. Quaternion rotPart = sp.GetWorldRotation();
  14049. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  14050. posPart = posPart + (lower + upper) * 0.5f * rotPart;
  14051. // Project ray
  14052. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  14053. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  14054. // Filter avatars by shape bounding boxes
  14055. Vector3 shapeBoxMax = new Vector3(0.5f + tol, 0.5f + tol, 0.5f + tol);
  14056. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  14057. {
  14058. // Prepare data needed to check for ray hits
  14059. RayTrans rayTrans = new RayTrans
  14060. {
  14061. PartId = sp.UUID,
  14062. GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID,
  14063. Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0,
  14064. ScalePart = scalePart,
  14065. PositionPart = posPart,
  14066. RotationPart = rotPart,
  14067. ShapeNeedsEnds = false,
  14068. Position1Ray = pos1Ray,
  14069. Position1RayProj = pos1RayProj,
  14070. VectorRayProj = pos2RayProj - pos1RayProj
  14071. };
  14072. // Try to get cached mesh if configured
  14073. PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere();
  14074. int lod = (int)m_avatarLodInCastRay;
  14075. ulong meshKey = prim.GetMeshKey(Vector3.One, (float)(4 << lod));
  14076. FacetedMesh mesh = null;
  14077. if (m_useMeshCacheInCastRay)
  14078. {
  14079. lock (m_cachedMeshes)
  14080. {
  14081. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  14082. }
  14083. }
  14084. // Create mesh if no cached mesh
  14085. if (mesh == null)
  14086. {
  14087. // Make OMV prim and create mesh
  14088. prim.Scale = scalePart;
  14089. Primitive omvPrim = prim.ToOmvPrimitive(posPart, rotPart);
  14090. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_avatarLodInCastRay);
  14091. // Cache mesh if configured
  14092. if (m_useMeshCacheInCastRay && mesh != null)
  14093. {
  14094. lock(m_cachedMeshes)
  14095. {
  14096. if (!m_cachedMeshes.ContainsKey(meshKey))
  14097. m_cachedMeshes.Add(meshKey, mesh);
  14098. }
  14099. }
  14100. }
  14101. // Check mesh for ray hits
  14102. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  14103. mesh = null;
  14104. }
  14105. }
  14106. );
  14107. }
  14108. // Check terrain filter
  14109. if (!rejectLand)
  14110. {
  14111. // Parse terrain
  14112. // Mesh terrain and check bounding box
  14113. List<Tri> triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out Vector3 lower, out Vector3 upper);
  14114. lower.Z -= tol;
  14115. upper.Z += tol;
  14116. if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z))
  14117. {
  14118. // Prepare data needed to check for ray hits
  14119. RayTrans rayTrans = new RayTrans
  14120. {
  14121. PartId = UUID.Zero,
  14122. GroupId = UUID.Zero,
  14123. Link = 0,
  14124. ScalePart = new Vector3(1.0f, 1.0f, 1.0f),
  14125. PositionPart = Vector3.Zero,
  14126. RotationPart = Quaternion.Identity,
  14127. ShapeNeedsEnds = true,
  14128. Position1Ray = pos1Ray,
  14129. Position1RayProj = pos1Ray,
  14130. VectorRayProj = vecRay
  14131. };
  14132. // Check mesh
  14133. AddRayInTris(triangles, rayTrans, ref rayHits);
  14134. triangles = null;
  14135. }
  14136. }
  14137. // Sort hits by ascending distance
  14138. rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance));
  14139. // Check excess hits per part and group
  14140. for (int t = 0; t < 2; t++)
  14141. {
  14142. int maxHitsPerType = 0;
  14143. UUID id = UUID.Zero;
  14144. if (t == 0)
  14145. maxHitsPerType = m_maxHitsPerPrimInCastRay;
  14146. else
  14147. maxHitsPerType = m_maxHitsPerObjectInCastRay;
  14148. // Handle excess hits only when needed
  14149. if (maxHitsPerType < m_maxHitsInCastRay)
  14150. {
  14151. // Find excess hits
  14152. Hashtable hits = new Hashtable();
  14153. for (int i = rayHits.Count - 1; i >= 0; i--)
  14154. {
  14155. if (t == 0)
  14156. id = rayHits[i].PartId;
  14157. else
  14158. id = rayHits[i].GroupId;
  14159. if (hits.ContainsKey(id))
  14160. hits[id] = (int)hits[id] + 1;
  14161. else
  14162. hits[id] = 1;
  14163. }
  14164. // Remove excess hits
  14165. for (int i = rayHits.Count - 1; i >= 0; i--)
  14166. {
  14167. if (t == 0)
  14168. id = rayHits[i].PartId;
  14169. else
  14170. id = rayHits[i].GroupId;
  14171. int hit = (int)hits[id];
  14172. if (hit > m_maxHitsPerPrimInCastRay)
  14173. {
  14174. rayHits.RemoveAt(i);
  14175. hit--;
  14176. hits[id] = hit;
  14177. }
  14178. }
  14179. }
  14180. }
  14181. // Parse hits into result list according to data flags
  14182. int hitCount = rayHits.Count;
  14183. if (hitCount > maxHits)
  14184. hitCount = maxHits;
  14185. for (int i = 0; i < hitCount; i++)
  14186. {
  14187. RayHit rayHit = rayHits[i];
  14188. if (getRootKey)
  14189. result.Add(new LSL_Key(rayHit.GroupId.ToString()));
  14190. else
  14191. result.Add(new LSL_Key(rayHit.PartId.ToString()));
  14192. result.Add(new LSL_Vector(rayHit.Position));
  14193. if (getLinkNum)
  14194. result.Add(new LSL_Integer(rayHit.Link));
  14195. if (getNormal)
  14196. result.Add(new LSL_Vector(rayHit.Normal));
  14197. }
  14198. result.Add(new LSL_Integer(hitCount));
  14199. // Add to throttle data
  14200. stopWatch.Stop();
  14201. lock (m_castRayCalls)
  14202. {
  14203. CastRayCall castRayCall = new CastRayCall
  14204. {
  14205. RegionId = regionId,
  14206. UserId = userId,
  14207. CalledMs = calledMs,
  14208. UsedMs = (int)stopWatch.ElapsedMilliseconds
  14209. };
  14210. m_castRayCalls.Add(castRayCall);
  14211. }
  14212. // Return hits
  14213. return result;
  14214. }
  14215. /// <summary>
  14216. /// Struct for transmitting parameters required for finding llCastRay ray hits.
  14217. /// </summary>
  14218. public struct RayTrans
  14219. {
  14220. public UUID PartId;
  14221. public UUID GroupId;
  14222. public int Link;
  14223. public Vector3 ScalePart;
  14224. public Vector3 PositionPart;
  14225. public Quaternion RotationPart;
  14226. public bool ShapeNeedsEnds;
  14227. public Vector3 Position1Ray;
  14228. public Vector3 Position1RayProj;
  14229. public Vector3 VectorRayProj;
  14230. }
  14231. /// <summary>
  14232. /// Struct for llCastRay ray hits.
  14233. /// </summary>
  14234. public struct RayHit
  14235. {
  14236. public UUID PartId;
  14237. public UUID GroupId;
  14238. public int Link;
  14239. public Vector3 Position;
  14240. public Vector3 Normal;
  14241. public float Distance;
  14242. }
  14243. /// <summary>
  14244. /// Struct for llCastRay throttle data.
  14245. /// </summary>
  14246. public struct CastRayCall
  14247. {
  14248. public UUID RegionId;
  14249. public UUID UserId;
  14250. public int CalledMs;
  14251. public int UsedMs;
  14252. }
  14253. /// <summary>
  14254. /// Helper to check if a ray intersects a shape bounding box.
  14255. /// </summary>
  14256. private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax)
  14257. {
  14258. // Skip if ray can't intersect bounding box;
  14259. Vector3 rayBoxProjMin = Vector3.Min(pos1RayProj, pos2RayProj);
  14260. Vector3 rayBoxProjMax = Vector3.Max(pos1RayProj, pos2RayProj);
  14261. if (
  14262. rayBoxProjMin.X > shapeBoxMax.X || rayBoxProjMin.Y > shapeBoxMax.Y || rayBoxProjMin.Z > shapeBoxMax.Z ||
  14263. rayBoxProjMax.X < -shapeBoxMax.X || rayBoxProjMax.Y < -shapeBoxMax.Y || rayBoxProjMax.Z < -shapeBoxMax.Z
  14264. )
  14265. return false;
  14266. // Check if ray intersect any bounding box side
  14267. int sign = 0;
  14268. float dist = 0.0f;
  14269. Vector3 posProj = Vector3.Zero;
  14270. Vector3 vecRayProj = pos2RayProj - pos1RayProj;
  14271. // Check both X sides unless ray is parallell to them
  14272. if (Math.Abs(vecRayProj.X) > m_floatToleranceInCastRay)
  14273. {
  14274. for (sign = -1; sign <= 1; sign += 2)
  14275. {
  14276. dist = ((float)sign * shapeBoxMax.X - pos1RayProj.X) / vecRayProj.X;
  14277. posProj = pos1RayProj + vecRayProj * dist;
  14278. if (Math.Abs(posProj.Y) <= shapeBoxMax.Y && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14279. return true;
  14280. }
  14281. }
  14282. // Check both Y sides unless ray is parallell to them
  14283. if (Math.Abs(vecRayProj.Y) > m_floatToleranceInCastRay)
  14284. {
  14285. for (sign = -1; sign <= 1; sign += 2)
  14286. {
  14287. dist = ((float)sign * shapeBoxMax.Y - pos1RayProj.Y) / vecRayProj.Y;
  14288. posProj = pos1RayProj + vecRayProj * dist;
  14289. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14290. return true;
  14291. }
  14292. }
  14293. // Check both Z sides unless ray is parallell to them
  14294. if (Math.Abs(vecRayProj.Z) > m_floatToleranceInCastRay)
  14295. {
  14296. for (sign = -1; sign <= 1; sign += 2)
  14297. {
  14298. dist = ((float)sign * shapeBoxMax.Z - pos1RayProj.Z) / vecRayProj.Z;
  14299. posProj = pos1RayProj + vecRayProj * dist;
  14300. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Y) <= shapeBoxMax.Y)
  14301. return true;
  14302. }
  14303. }
  14304. // No hits on bounding box so return false
  14305. return false;
  14306. }
  14307. /// <summary>
  14308. /// Helper to parse FacetedMesh for ray hits.
  14309. /// </summary>
  14310. private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  14311. {
  14312. if (mesh != null)
  14313. {
  14314. foreach (Face face in mesh.Faces)
  14315. {
  14316. for (int i = 0; i < face.Indices.Count; i += 3)
  14317. {
  14318. Tri triangle = new Tri
  14319. {
  14320. p1 = face.Vertices[face.Indices[i]].Position,
  14321. p2 = face.Vertices[face.Indices[i + 1]].Position,
  14322. p3 = face.Vertices[face.Indices[i + 2]].Position
  14323. };
  14324. AddRayInTri(triangle, rayTrans, ref rayHits);
  14325. }
  14326. }
  14327. }
  14328. }
  14329. /// <summary>
  14330. /// Helper to parse Tri (triangle) List for ray hits.
  14331. /// </summary>
  14332. private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits)
  14333. {
  14334. foreach (Tri triangle in triangles)
  14335. {
  14336. AddRayInTri(triangle, rayTrans, ref rayHits);
  14337. }
  14338. }
  14339. /// <summary>
  14340. /// Helper to add ray hit in a Tri (triangle).
  14341. /// </summary>
  14342. private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits)
  14343. {
  14344. // Check for hit in triangle
  14345. if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out Vector3 posHitProj, out Vector3 normalProj))
  14346. {
  14347. // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center
  14348. if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds)
  14349. return;
  14350. // Transform hit and normal to region coordinate system
  14351. Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart;
  14352. Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart);
  14353. // Remove duplicate hits at triangle intersections
  14354. float distance = Vector3.Distance(rayTrans.Position1Ray, posHit);
  14355. for (int i = rayHits.Count - 1; i >= 0; i--)
  14356. {
  14357. if (rayHits[i].PartId != rayTrans.PartId)
  14358. break;
  14359. if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay)
  14360. return;
  14361. }
  14362. // Build result data set
  14363. RayHit rayHit = new RayHit
  14364. {
  14365. PartId = rayTrans.PartId,
  14366. GroupId = rayTrans.GroupId,
  14367. Link = rayTrans.Link,
  14368. Position = posHit,
  14369. Normal = normal,
  14370. Distance = distance
  14371. };
  14372. rayHits.Add(rayHit);
  14373. }
  14374. }
  14375. /// <summary>
  14376. /// Helper to find ray hit in triangle
  14377. /// </summary>
  14378. bool HitRayInTri(Tri triProj, Vector3 pos1RayProj, Vector3 vecRayProj, out Vector3 posHitProj, out Vector3 normalProj)
  14379. {
  14380. float tol = m_floatToleranceInCastRay;
  14381. posHitProj = Vector3.Zero;
  14382. // Calculate triangle edge vectors
  14383. Vector3 vec1Proj = triProj.p2 - triProj.p1;
  14384. Vector3 vec2Proj = triProj.p3 - triProj.p2;
  14385. Vector3 vec3Proj = triProj.p1 - triProj.p3;
  14386. // Calculate triangle normal
  14387. normalProj = Vector3.Cross(vec1Proj, vec2Proj);
  14388. // Skip if degenerate triangle or ray parallell with triangle plane
  14389. float divisor = Vector3.Dot(vecRayProj, normalProj);
  14390. if (Math.Abs(divisor) < tol)
  14391. return false;
  14392. // Skip if exit and not configured to detect
  14393. if (divisor > tol && !m_detectExitsInCastRay)
  14394. return false;
  14395. // Skip if outside ray ends
  14396. float distanceProj = Vector3.Dot(triProj.p1 - pos1RayProj, normalProj) / divisor;
  14397. if (distanceProj < -tol || distanceProj > 1 + tol)
  14398. return false;
  14399. // Calculate hit position in triangle
  14400. posHitProj = pos1RayProj + vecRayProj * distanceProj;
  14401. // Skip if outside triangle bounding box
  14402. Vector3 triProjMin = Vector3.Min(Vector3.Min(triProj.p1, triProj.p2), triProj.p3);
  14403. Vector3 triProjMax = Vector3.Max(Vector3.Max(triProj.p1, triProj.p2), triProj.p3);
  14404. if (
  14405. posHitProj.X < triProjMin.X - tol || posHitProj.Y < triProjMin.Y - tol || posHitProj.Z < triProjMin.Z - tol ||
  14406. posHitProj.X > triProjMax.X + tol || posHitProj.Y > triProjMax.Y + tol || posHitProj.Z > triProjMax.Z + tol
  14407. )
  14408. return false;
  14409. // Skip if outside triangle
  14410. if (
  14411. Vector3.Dot(Vector3.Cross(vec1Proj, normalProj), posHitProj - triProj.p1) > tol ||
  14412. Vector3.Dot(Vector3.Cross(vec2Proj, normalProj), posHitProj - triProj.p2) > tol ||
  14413. Vector3.Dot(Vector3.Cross(vec3Proj, normalProj), posHitProj - triProj.p3) > tol
  14414. )
  14415. return false;
  14416. // Return hit
  14417. return true;
  14418. }
  14419. /// <summary>
  14420. /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box.
  14421. /// </summary>
  14422. private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper)
  14423. {
  14424. // Get bounding X-Y rectangle of terrain under ray
  14425. lower = Vector3.Min(posStart, posEnd);
  14426. upper = Vector3.Max(posStart, posEnd);
  14427. lower.X = (float)Math.Floor(lower.X);
  14428. lower.Y = (float)Math.Floor(lower.Y);
  14429. float zLower = float.MaxValue;
  14430. upper.X = (float)Math.Ceiling(upper.X);
  14431. upper.Y = (float)Math.Ceiling(upper.Y);
  14432. float zUpper = float.MinValue;
  14433. // Initialize Tri (triangle) List
  14434. List<Tri> triangles = new List<Tri>();
  14435. // Set parsing lane direction to major ray X-Y axis
  14436. Vector3 vec = posEnd - posStart;
  14437. float xAbs = Math.Abs(vec.X);
  14438. float yAbs = Math.Abs(vec.Y);
  14439. bool bigX = true;
  14440. if (yAbs > xAbs)
  14441. {
  14442. bigX = false;
  14443. vec = vec / yAbs;
  14444. }
  14445. else if (xAbs > yAbs || xAbs > 0.0f)
  14446. vec = vec / xAbs;
  14447. else
  14448. vec = new Vector3(1.0f, 1.0f, 0.0f);
  14449. // Simplify by start parsing in lower end of lane
  14450. if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f))
  14451. {
  14452. Vector3 posTemp = posStart;
  14453. posStart = posEnd;
  14454. posEnd = posTemp;
  14455. vec = vec * -1.0f;
  14456. }
  14457. // First 1x1 rectangle under ray
  14458. float xFloorOld = 0.0f;
  14459. float yFloorOld = 0.0f;
  14460. Vector3 pos = posStart;
  14461. float xFloor = (float)Math.Floor(pos.X);
  14462. float yFloor = (float)Math.Floor(pos.Y);
  14463. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14464. // Parse every remaining 1x1 rectangle under ray
  14465. while (pos != posEnd)
  14466. {
  14467. // Next 1x1 rectangle under ray
  14468. xFloorOld = xFloor;
  14469. yFloorOld = yFloor;
  14470. pos = pos + vec;
  14471. // Clip position to 1x1 rectangle border
  14472. xFloor = (float)Math.Floor(pos.X);
  14473. yFloor = (float)Math.Floor(pos.Y);
  14474. if (bigX && pos.X > xFloor)
  14475. {
  14476. pos.Y -= vec.Y * (pos.X - xFloor);
  14477. pos.X = xFloor;
  14478. }
  14479. else if (!bigX && pos.Y > yFloor)
  14480. {
  14481. pos.X -= vec.X * (pos.Y - yFloor);
  14482. pos.Y = yFloor;
  14483. }
  14484. // Last 1x1 rectangle under ray
  14485. if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y))
  14486. {
  14487. pos = posEnd;
  14488. xFloor = (float)Math.Floor(pos.X);
  14489. yFloor = (float)Math.Floor(pos.Y);
  14490. }
  14491. // Add new 1x1 rectangle in lane
  14492. if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld))
  14493. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14494. // Add last 1x1 rectangle in old lane at lane shift
  14495. if (bigX && yFloor != yFloorOld)
  14496. AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper);
  14497. if (!bigX && xFloor != xFloorOld)
  14498. AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper);
  14499. }
  14500. // Finalize bounding box Z
  14501. lower.Z = zLower;
  14502. upper.Z = zUpper;
  14503. // Done and returning Tri (triangle)List
  14504. return triangles;
  14505. }
  14506. /// <summary>
  14507. /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box.
  14508. /// </summary>
  14509. private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper)
  14510. {
  14511. int xInt = (int)xPos;
  14512. int yInt = (int)yPos;
  14513. // Corner 1 of 1x1 rectangle
  14514. int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14515. int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14516. Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14517. // Adjust bounding box
  14518. zLower = Math.Min(zLower, pos1.Z);
  14519. zUpper = Math.Max(zUpper, pos1.Z);
  14520. // Corner 2 of 1x1 rectangle
  14521. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14522. y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14523. Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14524. // Adjust bounding box
  14525. zLower = Math.Min(zLower, pos2.Z);
  14526. zUpper = Math.Max(zUpper, pos2.Z);
  14527. // Corner 3 of 1x1 rectangle
  14528. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14529. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14530. Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14531. // Adjust bounding box
  14532. zLower = Math.Min(zLower, pos3.Z);
  14533. zUpper = Math.Max(zUpper, pos3.Z);
  14534. // Corner 4 of 1x1 rectangle
  14535. x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14536. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14537. Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14538. // Adjust bounding box
  14539. zLower = Math.Min(zLower, pos4.Z);
  14540. zUpper = Math.Max(zUpper, pos4.Z);
  14541. // Add triangle 1
  14542. Tri triangle1 = new Tri
  14543. {
  14544. p1 = pos1,
  14545. p2 = pos2,
  14546. p3 = pos3
  14547. };
  14548. triangles.Add(triangle1);
  14549. // Add triangle 2
  14550. Tri triangle2 = new Tri
  14551. {
  14552. p1 = pos3,
  14553. p2 = pos4,
  14554. p3 = pos1
  14555. };
  14556. triangles.Add(triangle2);
  14557. }
  14558. /// <summary>
  14559. /// Helper to get link number for a UUID.
  14560. /// </summary>
  14561. private int UUID2LinkNumber(SceneObjectPart part, UUID id)
  14562. {
  14563. SceneObjectGroup group = part.ParentGroup;
  14564. if (group != null)
  14565. {
  14566. // Parse every link for UUID
  14567. int linkCount = group.PrimCount + group.GetSittingAvatarsCount();
  14568. for (int link = linkCount; link > 0; link--)
  14569. {
  14570. ISceneEntity entity = GetLinkEntity(part, link);
  14571. // Return link number if UUID match
  14572. if (entity != null && entity.UUID == id)
  14573. return link;
  14574. }
  14575. }
  14576. // Return link number 0 if no links or UUID matches
  14577. return 0;
  14578. }
  14579. public LSL_Integer llManageEstateAccess(int action, string avatar)
  14580. {
  14581. m_host.AddScriptLPS(1);
  14582. EstateSettings estate = World.RegionInfo.EstateSettings;
  14583. bool isAccount = false;
  14584. bool isGroup = false;
  14585. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  14586. return 0;
  14587. UUID id = new UUID();
  14588. if (!UUID.TryParse(avatar, out id))
  14589. return 0;
  14590. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, id);
  14591. isAccount = account != null ? true : false;
  14592. if (!isAccount)
  14593. {
  14594. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  14595. if (groups != null)
  14596. {
  14597. GroupRecord group = groups.GetGroupRecord(id);
  14598. isGroup = group != null ? true : false;
  14599. if (!isGroup)
  14600. return 0;
  14601. }
  14602. else
  14603. return 0;
  14604. }
  14605. switch (action)
  14606. {
  14607. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  14608. if (!isAccount) return 0;
  14609. if (estate.HasAccess(id)) return 1;
  14610. if (estate.IsBanned(id, World.GetUserFlags(id)))
  14611. estate.RemoveBan(id);
  14612. estate.AddEstateUser(id);
  14613. break;
  14614. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  14615. if (!isAccount || !estate.HasAccess(id)) return 0;
  14616. estate.RemoveEstateUser(id);
  14617. break;
  14618. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  14619. if (!isGroup) return 0;
  14620. if (estate.GroupAccess(id)) return 1;
  14621. estate.AddEstateGroup(id);
  14622. break;
  14623. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  14624. if (!isGroup || !estate.GroupAccess(id)) return 0;
  14625. estate.RemoveEstateGroup(id);
  14626. break;
  14627. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  14628. if (!isAccount) return 0;
  14629. if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
  14630. EstateBan ban = new EstateBan
  14631. {
  14632. EstateID = estate.EstateID,
  14633. BannedUserID = id
  14634. };
  14635. estate.AddBan(ban);
  14636. break;
  14637. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  14638. if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
  14639. estate.RemoveBan(id);
  14640. break;
  14641. default: return 0;
  14642. }
  14643. return 1;
  14644. }
  14645. public LSL_Integer llGetMemoryLimit()
  14646. {
  14647. m_host.AddScriptLPS(1);
  14648. // The value returned for Mono scripts in SL
  14649. return 65536;
  14650. }
  14651. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  14652. {
  14653. m_host.AddScriptLPS(1);
  14654. // Treat as an LSO script
  14655. return ScriptBaseClass.FALSE;
  14656. }
  14657. public LSL_Integer llGetSPMaxMemory()
  14658. {
  14659. m_host.AddScriptLPS(1);
  14660. // The value returned for Mono scripts in SL
  14661. return 65536;
  14662. }
  14663. public virtual LSL_Integer llGetUsedMemory()
  14664. {
  14665. m_host.AddScriptLPS(1);
  14666. // The value returned for Mono scripts in SL
  14667. return 65536;
  14668. }
  14669. public void llScriptProfiler(LSL_Integer flags)
  14670. {
  14671. m_host.AddScriptLPS(1);
  14672. // This does nothing for LSO scripts in SL
  14673. }
  14674. #region Not Implemented
  14675. //
  14676. // Listing the unimplemented lsl functions here, please move
  14677. // them from this region as they are completed
  14678. //
  14679. public void llSetSoundQueueing(int queue)
  14680. {
  14681. m_host.AddScriptLPS(1);
  14682. if (m_SoundModule != null)
  14683. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  14684. }
  14685. public void llCollisionSprite(LSL_String impact_sprite)
  14686. {
  14687. m_host.AddScriptLPS(1);
  14688. // Viewer 2.0 broke this and it's likely LL has no intention
  14689. // of fixing it. Therefore, letting this be a NOP seems appropriate.
  14690. }
  14691. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  14692. {
  14693. m_host.AddScriptLPS(1);
  14694. if (!World.Permissions.IsGod(m_host.OwnerID))
  14695. NotImplemented("llGodLikeRezObject");
  14696. AssetBase rezAsset = World.AssetService.Get(inventory);
  14697. if (rezAsset == null)
  14698. {
  14699. llSay(0, "Asset not found");
  14700. return;
  14701. }
  14702. SceneObjectGroup group = null;
  14703. try
  14704. {
  14705. string xmlData = Utils.BytesToString(rezAsset.Data);
  14706. group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
  14707. }
  14708. catch
  14709. {
  14710. llSay(0, "Asset not found");
  14711. return;
  14712. }
  14713. if (group == null)
  14714. {
  14715. llSay(0, "Asset not found");
  14716. return;
  14717. }
  14718. group.RootPart.AttachedPos = group.AbsolutePosition;
  14719. group.ResetIDs();
  14720. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  14721. World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
  14722. group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
  14723. group.ScheduleGroupForFullUpdate();
  14724. // objects rezzed with this method are die_at_edge by default.
  14725. group.RootPart.SetDieAtEdge(true);
  14726. group.ResumeScripts();
  14727. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  14728. "object_rez", new Object[] {
  14729. new LSL_String(
  14730. group.RootPart.UUID.ToString()) },
  14731. new DetectParams[0]));
  14732. }
  14733. public LSL_Key llTransferLindenDollars(LSL_Key destination, LSL_Integer amount)
  14734. {
  14735. m_host.AddScriptLPS(1);
  14736. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  14737. UUID txn = UUID.Random();
  14738. UUID toID = UUID.Zero;
  14739. string replydata = "UnKnownError";
  14740. bool bad = true;
  14741. while(true)
  14742. {
  14743. if (amount <= 0)
  14744. {
  14745. replydata = "INVALID_AMOUNT";
  14746. break;
  14747. }
  14748. if (money == null)
  14749. {
  14750. replydata = "TRANSFERS_DISABLED";
  14751. break;
  14752. }
  14753. if (m_host.OwnerID == m_host.GroupID)
  14754. {
  14755. replydata = "GROUP_OWNED";
  14756. break;
  14757. }
  14758. if (m_item == null)
  14759. {
  14760. replydata = "SERVICE_ERROR";
  14761. break;
  14762. }
  14763. if (m_item.PermsGranter == UUID.Zero)
  14764. {
  14765. replydata = "MISSING_PERMISSION_DEBIT";
  14766. break;
  14767. }
  14768. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  14769. {
  14770. replydata = "MISSING_PERMISSION_DEBIT";
  14771. break;
  14772. }
  14773. if (!UUID.TryParse(destination, out toID))
  14774. {
  14775. replydata = "INVALID_AGENT";
  14776. break;
  14777. }
  14778. bad = false;
  14779. break;
  14780. }
  14781. if(bad)
  14782. {
  14783. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14784. "transaction_result", new Object[] {
  14785. new LSL_String(txn.ToString()),
  14786. new LSL_Integer(0),
  14787. new LSL_String(replydata) },
  14788. new DetectParams[0]));
  14789. return txn.ToString();
  14790. }
  14791. //fire and forget...
  14792. Action<string> act = eventID =>
  14793. {
  14794. int replycode = 0;
  14795. try
  14796. {
  14797. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, toID);
  14798. if (account == null)
  14799. {
  14800. replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST";
  14801. return;
  14802. }
  14803. bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID,
  14804. toID, amount, txn, out string reason);
  14805. if (result)
  14806. {
  14807. replycode = 1;
  14808. replydata = destination + "," + amount.ToString();
  14809. return;
  14810. }
  14811. replydata = reason;
  14812. }
  14813. finally
  14814. {
  14815. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14816. "transaction_result", new Object[] {
  14817. new LSL_String(txn.ToString()),
  14818. new LSL_Integer(replycode),
  14819. new LSL_String(replydata) },
  14820. new DetectParams[0]));
  14821. }
  14822. };
  14823. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  14824. return txn.ToString();
  14825. }
  14826. #endregion
  14827. protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
  14828. {
  14829. //This is a special version of SetPrimParams to deal with avatars which are sitting on the linkset.
  14830. int idx = 0;
  14831. int idxStart = 0;
  14832. bool positionChanged = false;
  14833. try
  14834. {
  14835. while (idx < rules.Length)
  14836. {
  14837. ++rulesParsed;
  14838. int code = rules.GetLSLIntegerItem(idx++);
  14839. int remain = rules.Length - idx;
  14840. idxStart = idx;
  14841. switch (code)
  14842. {
  14843. case (int)ScriptBaseClass.PRIM_POSITION:
  14844. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14845. {
  14846. if (remain < 1)
  14847. return new LSL_List();
  14848. LSL_Vector v;
  14849. v = rules.GetVector3Item(idx++);
  14850. if(!av.LegacySitOffsets)
  14851. {
  14852. LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
  14853. v = v + 2 * sitOffset;
  14854. }
  14855. av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
  14856. positionChanged = true;
  14857. }
  14858. break;
  14859. case (int)ScriptBaseClass.PRIM_ROTATION:
  14860. {
  14861. if (remain < 1)
  14862. return new LSL_List();
  14863. Quaternion r;
  14864. r = rules.GetQuaternionItem(idx++);
  14865. av.Rotation = m_host.GetWorldRotation() * r;
  14866. positionChanged = true;
  14867. }
  14868. break;
  14869. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14870. {
  14871. if (remain < 1)
  14872. return new LSL_List();
  14873. LSL_Rotation r;
  14874. r = rules.GetQuaternionItem(idx++);
  14875. av.Rotation = r;
  14876. positionChanged = true;
  14877. }
  14878. break;
  14879. // parse rest doing nothing but number of parameters error check
  14880. case (int)ScriptBaseClass.PRIM_SIZE:
  14881. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14882. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14883. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14884. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  14885. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14886. case (int)ScriptBaseClass.PRIM_NAME:
  14887. case (int)ScriptBaseClass.PRIM_DESC:
  14888. if (remain < 1)
  14889. return new LSL_List();
  14890. idx++;
  14891. break;
  14892. case (int)ScriptBaseClass.PRIM_GLOW:
  14893. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14894. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14895. if (remain < 2)
  14896. return new LSL_List();
  14897. idx += 2;
  14898. break;
  14899. case (int)ScriptBaseClass.PRIM_TYPE:
  14900. if (remain < 3)
  14901. return new LSL_List();
  14902. code = (int)rules.GetLSLIntegerItem(idx++);
  14903. remain = rules.Length - idx;
  14904. switch (code)
  14905. {
  14906. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  14907. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  14908. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  14909. if (remain < 6)
  14910. return new LSL_List();
  14911. idx += 6;
  14912. break;
  14913. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  14914. if (remain < 5)
  14915. return new LSL_List();
  14916. idx += 5;
  14917. break;
  14918. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  14919. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  14920. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  14921. if (remain < 11)
  14922. return new LSL_List();
  14923. idx += 11;
  14924. break;
  14925. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  14926. if (remain < 2)
  14927. return new LSL_List();
  14928. idx += 2;
  14929. break;
  14930. }
  14931. break;
  14932. case (int)ScriptBaseClass.PRIM_COLOR:
  14933. case (int)ScriptBaseClass.PRIM_TEXT:
  14934. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  14935. case (int)ScriptBaseClass.PRIM_OMEGA:
  14936. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  14937. if (remain < 3)
  14938. return new LSL_List();
  14939. idx += 3;
  14940. break;
  14941. case (int)ScriptBaseClass.PRIM_TEXTURE:
  14942. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  14943. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  14944. if (remain < 5)
  14945. return new LSL_List();
  14946. idx += 5;
  14947. break;
  14948. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  14949. if (remain < 7)
  14950. return new LSL_List();
  14951. idx += 7;
  14952. break;
  14953. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  14954. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  14955. return new LSL_List();
  14956. return rules.GetSublist(idx, -1);
  14957. }
  14958. }
  14959. }
  14960. catch (InvalidCastException e)
  14961. {
  14962. Error(originFunc,string.Format(
  14963. " error running rule #{0}: arg #{1} {2}",
  14964. rulesParsed, idx - idxStart, e.Message));
  14965. }
  14966. finally
  14967. {
  14968. if (positionChanged)
  14969. av.SendTerseUpdateToAllClients();
  14970. }
  14971. return new LSL_List();
  14972. }
  14973. public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
  14974. {
  14975. // avatars case
  14976. // replies as SL wiki
  14977. // SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
  14978. SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
  14979. int idx = 0;
  14980. while (idx < rules.Length)
  14981. {
  14982. int code = (int)rules.GetLSLIntegerItem(idx++);
  14983. int remain = rules.Length - idx;
  14984. switch (code)
  14985. {
  14986. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14987. res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
  14988. break;
  14989. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14990. res.Add(new LSL_Integer(0));
  14991. break;
  14992. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14993. res.Add(new LSL_Integer(0));
  14994. break;
  14995. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14996. res.Add(new LSL_Integer(0));
  14997. break;
  14998. case (int)ScriptBaseClass.PRIM_POSITION:
  14999. Vector3 pos;
  15000. if (sitPart.ParentGroup.RootPart != null)
  15001. {
  15002. pos = avatar.OffsetPosition;
  15003. if(!avatar.LegacySitOffsets)
  15004. {
  15005. Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
  15006. pos -= sitOffset;
  15007. }
  15008. SceneObjectPart sitroot = sitPart.ParentGroup.RootPart;
  15009. pos = sitroot.AbsolutePosition + pos * sitroot.GetWorldRotation();
  15010. }
  15011. else
  15012. pos = avatar.AbsolutePosition;
  15013. res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
  15014. break;
  15015. case (int)ScriptBaseClass.PRIM_SIZE:
  15016. Vector3 s = avatar.Appearance.AvatarSize;
  15017. res.Add(new LSL_Vector(s.X, s.Y, s.Z));
  15018. break;
  15019. case (int)ScriptBaseClass.PRIM_ROTATION:
  15020. res.Add(new LSL_Rotation(avatar.GetWorldRotation()));
  15021. break;
  15022. case (int)ScriptBaseClass.PRIM_TYPE:
  15023. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  15024. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  15025. res.Add(new LSL_Vector(0f,1.0f,0f));
  15026. res.Add(new LSL_Float(0.0f));
  15027. res.Add(new LSL_Vector(0, 0, 0));
  15028. res.Add(new LSL_Vector(1.0f,1.0f,0f));
  15029. res.Add(new LSL_Vector(0, 0, 0));
  15030. break;
  15031. case (int)ScriptBaseClass.PRIM_TEXTURE:
  15032. if (remain < 1)
  15033. return new LSL_List();
  15034. int face = (int)rules.GetLSLIntegerItem(idx++);
  15035. if (face == ScriptBaseClass.ALL_SIDES)
  15036. {
  15037. for (face = 0; face < 21; face++)
  15038. {
  15039. res.Add(new LSL_String(""));
  15040. res.Add(new LSL_Vector(0,0,0));
  15041. res.Add(new LSL_Vector(0,0,0));
  15042. res.Add(new LSL_Float(0.0));
  15043. }
  15044. }
  15045. else
  15046. {
  15047. if (face >= 0 && face < 21)
  15048. {
  15049. res.Add(new LSL_String(""));
  15050. res.Add(new LSL_Vector(0,0,0));
  15051. res.Add(new LSL_Vector(0,0,0));
  15052. res.Add(new LSL_Float(0.0));
  15053. }
  15054. }
  15055. break;
  15056. case (int)ScriptBaseClass.PRIM_COLOR:
  15057. if (remain < 1)
  15058. return new LSL_List();
  15059. face = (int)rules.GetLSLIntegerItem(idx++);
  15060. if (face == ScriptBaseClass.ALL_SIDES)
  15061. {
  15062. for (face = 0; face < 21; face++)
  15063. {
  15064. res.Add(new LSL_Vector(0,0,0));
  15065. res.Add(new LSL_Float(0));
  15066. }
  15067. }
  15068. else
  15069. {
  15070. res.Add(new LSL_Vector(0,0,0));
  15071. res.Add(new LSL_Float(0));
  15072. }
  15073. break;
  15074. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  15075. if (remain < 1)
  15076. return new LSL_List();
  15077. face = (int)rules.GetLSLIntegerItem(idx++);
  15078. if (face == ScriptBaseClass.ALL_SIDES)
  15079. {
  15080. for (face = 0; face < 21; face++)
  15081. {
  15082. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  15083. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  15084. }
  15085. }
  15086. else
  15087. {
  15088. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  15089. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  15090. }
  15091. break;
  15092. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  15093. if (remain < 1)
  15094. return new LSL_List();
  15095. face = (int)rules.GetLSLIntegerItem(idx++);
  15096. if (face == ScriptBaseClass.ALL_SIDES)
  15097. {
  15098. for (face = 0; face < 21; face++)
  15099. {
  15100. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  15101. }
  15102. }
  15103. else
  15104. {
  15105. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  15106. }
  15107. break;
  15108. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  15109. res.Add(new LSL_Integer(0));
  15110. res.Add(new LSL_Integer(0));// softness
  15111. res.Add(new LSL_Float(0.0f)); // gravity
  15112. res.Add(new LSL_Float(0.0f)); // friction
  15113. res.Add(new LSL_Float(0.0f)); // wind
  15114. res.Add(new LSL_Float(0.0f)); // tension
  15115. res.Add(new LSL_Vector(0f,0f,0f));
  15116. break;
  15117. case (int)ScriptBaseClass.PRIM_TEXGEN:
  15118. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  15119. if (remain < 1)
  15120. return new LSL_List();
  15121. face = (int)rules.GetLSLIntegerItem(idx++);
  15122. if (face == ScriptBaseClass.ALL_SIDES)
  15123. {
  15124. for (face = 0; face < 21; face++)
  15125. {
  15126. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  15127. }
  15128. }
  15129. else
  15130. {
  15131. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  15132. }
  15133. break;
  15134. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  15135. res.Add(new LSL_Integer(0));
  15136. res.Add(new LSL_Vector(0f,0f,0f));
  15137. res.Add(new LSL_Float(0f)); // intensity
  15138. res.Add(new LSL_Float(0f)); // radius
  15139. res.Add(new LSL_Float(0f)); // falloff
  15140. break;
  15141. case (int)ScriptBaseClass.PRIM_GLOW:
  15142. if (remain < 1)
  15143. return new LSL_List();
  15144. face = (int)rules.GetLSLIntegerItem(idx++);
  15145. if (face == ScriptBaseClass.ALL_SIDES)
  15146. {
  15147. for (face = 0; face < 21; face++)
  15148. {
  15149. res.Add(new LSL_Float(0f));
  15150. }
  15151. }
  15152. else
  15153. {
  15154. res.Add(new LSL_Float(0f));
  15155. }
  15156. break;
  15157. case (int)ScriptBaseClass.PRIM_TEXT:
  15158. res.Add(new LSL_String(""));
  15159. res.Add(new LSL_Vector(0f,0f,0f));
  15160. res.Add(new LSL_Float(1.0f));
  15161. break;
  15162. case (int)ScriptBaseClass.PRIM_NAME:
  15163. res.Add(new LSL_String(avatar.Name));
  15164. break;
  15165. case (int)ScriptBaseClass.PRIM_DESC:
  15166. res.Add(new LSL_String(""));
  15167. break;
  15168. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  15169. Quaternion lrot = avatar.Rotation;
  15170. res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
  15171. break;
  15172. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  15173. Vector3 lpos = avatar.OffsetPosition;
  15174. if(!avatar.LegacySitOffsets)
  15175. {
  15176. Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
  15177. lpos -= lsitOffset;
  15178. }
  15179. res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
  15180. break;
  15181. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  15182. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  15183. return new LSL_List();
  15184. return rules.GetSublist(idx, -1);
  15185. }
  15186. }
  15187. return new LSL_List();
  15188. }
  15189. public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
  15190. {
  15191. string state = String.Empty;
  15192. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15193. {
  15194. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15195. {
  15196. state = kvp.Key;
  15197. break;
  15198. }
  15199. }
  15200. if (state == String.Empty)
  15201. {
  15202. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Invalid animation state " + animState);
  15203. return;
  15204. }
  15205. if (m_item.PermsGranter == UUID.Zero)
  15206. {
  15207. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15208. return;
  15209. }
  15210. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  15211. {
  15212. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15213. return;
  15214. }
  15215. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15216. if (presence == null)
  15217. return;
  15218. UUID animID;
  15219. animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  15220. if (animID == UUID.Zero)
  15221. {
  15222. String animupper = ((string)anim).ToUpperInvariant();
  15223. DefaultAvatarAnimations.AnimsUUIDbyName.TryGetValue(animupper, out animID);
  15224. }
  15225. if (animID == UUID.Zero)
  15226. {
  15227. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Animation not found");
  15228. return;
  15229. }
  15230. presence.SetAnimationOverride(state, animID);
  15231. }
  15232. public void llResetAnimationOverride(LSL_String animState)
  15233. {
  15234. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15235. if (presence == null)
  15236. return;
  15237. if (m_item.PermsGranter == UUID.Zero)
  15238. {
  15239. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15240. return;
  15241. }
  15242. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  15243. {
  15244. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15245. return;
  15246. }
  15247. if (animState == "ALL")
  15248. {
  15249. presence.SetAnimationOverride("ALL", UUID.Zero);
  15250. return;
  15251. }
  15252. string state = String.Empty;
  15253. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15254. {
  15255. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15256. {
  15257. state = kvp.Key;
  15258. break;
  15259. }
  15260. }
  15261. if (state == String.Empty)
  15262. {
  15263. return;
  15264. }
  15265. presence.SetAnimationOverride(state, UUID.Zero);
  15266. }
  15267. public LSL_String llGetAnimationOverride(LSL_String animState)
  15268. {
  15269. m_host.AddScriptLPS(1);
  15270. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15271. if (presence == null)
  15272. return String.Empty;
  15273. if (m_item.PermsGranter == UUID.Zero)
  15274. {
  15275. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15276. return String.Empty;
  15277. }
  15278. if ((m_item.PermsMask & (ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION)) == 0)
  15279. {
  15280. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15281. return String.Empty;
  15282. }
  15283. string state = String.Empty;
  15284. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15285. {
  15286. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15287. {
  15288. state = kvp.Key;
  15289. break;
  15290. }
  15291. }
  15292. if (state == String.Empty)
  15293. {
  15294. return String.Empty;
  15295. }
  15296. UUID animID = presence.GetAnimationOverride(state);
  15297. if (animID == UUID.Zero)
  15298. return animState;
  15299. foreach (KeyValuePair<string, UUID> kvp in DefaultAvatarAnimations.AnimsUUIDbyName)
  15300. {
  15301. if (kvp.Value == animID)
  15302. return kvp.Key.ToLower();
  15303. }
  15304. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  15305. {
  15306. if (item.AssetID == animID)
  15307. return item.Name;
  15308. }
  15309. return String.Empty;
  15310. }
  15311. public LSL_Integer llGetDayLength()
  15312. {
  15313. m_host.AddScriptLPS(1);
  15314. if (m_envModule == null)
  15315. return 14400;
  15316. return m_envModule.GetDayLength(m_host.GetWorldPosition());
  15317. }
  15318. public LSL_Integer llGetRegionDayLength()
  15319. {
  15320. m_host.AddScriptLPS(1);
  15321. if (m_envModule == null)
  15322. return 14400;
  15323. return m_envModule.GetRegionDayLength();
  15324. }
  15325. public LSL_Integer llGetDayOffset()
  15326. {
  15327. m_host.AddScriptLPS(1);
  15328. if (m_envModule == null)
  15329. return 57600;
  15330. return m_envModule.GetDayOffset(m_host.GetWorldPosition());
  15331. }
  15332. public LSL_Integer llGetRegionDayOffset()
  15333. {
  15334. m_host.AddScriptLPS(1);
  15335. if (m_envModule == null)
  15336. return 57600;
  15337. return m_envModule.GetRegionDayOffset();
  15338. }
  15339. public LSL_Vector llGetSunDirection()
  15340. {
  15341. m_host.AddScriptLPS(1);
  15342. if (m_envModule == null)
  15343. return Vector3.Zero;
  15344. return m_envModule.GetSunDir(m_host.GetWorldPosition());
  15345. }
  15346. public LSL_Vector llGetRegionSunDirection()
  15347. {
  15348. m_host.AddScriptLPS(1);
  15349. if (m_envModule == null)
  15350. return Vector3.Zero;
  15351. float z = m_host.GetWorldPosition().Z;
  15352. return m_envModule.GetRegionSunDir(z);
  15353. }
  15354. public LSL_Vector llGetMoonDirection()
  15355. {
  15356. m_host.AddScriptLPS(1);
  15357. if (m_envModule == null)
  15358. return Vector3.Zero;
  15359. return m_envModule.GetMoonDir(m_host.GetWorldPosition());
  15360. }
  15361. public LSL_Vector llGetRegionMoonDirection()
  15362. {
  15363. m_host.AddScriptLPS(1);
  15364. if (m_envModule == null)
  15365. return Vector3.Zero;
  15366. float z = m_host.GetWorldPosition().Z;
  15367. return m_envModule.GetRegionMoonDir(z);
  15368. }
  15369. public LSL_Rotation llGetSunRotation()
  15370. {
  15371. m_host.AddScriptLPS(1);
  15372. if (m_envModule == null)
  15373. return Quaternion.Identity;
  15374. return m_envModule.GetSunRot(m_host.GetWorldPosition());
  15375. }
  15376. public LSL_Rotation llGetRegionSunRotation()
  15377. {
  15378. m_host.AddScriptLPS(1);
  15379. if (m_envModule == null)
  15380. return Quaternion.Identity;
  15381. float z = m_host.GetWorldPosition().Z;
  15382. return m_envModule.GetRegionSunRot(z);
  15383. }
  15384. public LSL_Rotation llGetMoonRotation()
  15385. {
  15386. m_host.AddScriptLPS(1);
  15387. if (m_envModule == null)
  15388. return Quaternion.Identity;
  15389. return m_envModule.GetMoonRot(m_host.GetWorldPosition());
  15390. }
  15391. public LSL_Rotation llGetRegionMoonRotation()
  15392. {
  15393. m_host.AddScriptLPS(1);
  15394. if (m_envModule == null)
  15395. return Quaternion.Identity;
  15396. float z = m_host.GetWorldPosition().Z;
  15397. return m_envModule.GetRegionMoonRot(z);
  15398. }
  15399. public LSL_List llJson2List(LSL_String json)
  15400. {
  15401. m_host.AddScriptLPS(1);
  15402. if (String.IsNullOrEmpty(json))
  15403. return new LSL_List();
  15404. if(json == "[]")
  15405. return new LSL_List();
  15406. if(json == "{}")
  15407. return new LSL_List();
  15408. char first = ((string)json)[0];
  15409. if(first != '[' && first !='{')
  15410. {
  15411. // we already have a single element
  15412. LSL_List l = new LSL_List();
  15413. l.Add(json);
  15414. return l;
  15415. }
  15416. LitJson.JsonData jsdata;
  15417. try
  15418. {
  15419. jsdata = LitJson.JsonMapper.ToObject(json);
  15420. }
  15421. catch (Exception e)
  15422. {
  15423. string m = e.Message; // debug point
  15424. return json;
  15425. }
  15426. try
  15427. {
  15428. return JsonParseTop(jsdata);
  15429. }
  15430. catch (Exception e)
  15431. {
  15432. string m = e.Message; // debug point
  15433. return (LSL_String)ScriptBaseClass.JSON_INVALID;
  15434. }
  15435. }
  15436. private LSL_List JsonParseTop(LitJson.JsonData elem)
  15437. {
  15438. LSL_List retl = new LSL_List();
  15439. if(elem == null)
  15440. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15441. LitJson.JsonType elemType = elem.GetJsonType();
  15442. switch (elemType)
  15443. {
  15444. case LitJson.JsonType.Int:
  15445. retl.Add(new LSL_Integer((int)elem));
  15446. return retl;
  15447. case LitJson.JsonType.Boolean:
  15448. retl.Add((LSL_String)((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE));
  15449. return retl;
  15450. case LitJson.JsonType.Double:
  15451. retl.Add(new LSL_Float((double)elem));
  15452. return retl;
  15453. case LitJson.JsonType.None:
  15454. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15455. return retl;
  15456. case LitJson.JsonType.String:
  15457. retl.Add(new LSL_String((string)elem));
  15458. return retl;
  15459. case LitJson.JsonType.Array:
  15460. foreach (LitJson.JsonData subelem in elem)
  15461. retl.Add(JsonParseTopNodes(subelem));
  15462. return retl;
  15463. case LitJson.JsonType.Object:
  15464. IDictionaryEnumerator e = ((IOrderedDictionary)elem).GetEnumerator();
  15465. while (e.MoveNext())
  15466. {
  15467. retl.Add(new LSL_String((string)e.Key));
  15468. retl.Add(JsonParseTopNodes((LitJson.JsonData)e.Value));
  15469. }
  15470. return retl;
  15471. default:
  15472. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15473. }
  15474. }
  15475. private object JsonParseTopNodes(LitJson.JsonData elem)
  15476. {
  15477. if(elem == null)
  15478. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15479. LitJson.JsonType elemType = elem.GetJsonType();
  15480. switch (elemType)
  15481. {
  15482. case LitJson.JsonType.Int:
  15483. return (new LSL_Integer((int)elem));
  15484. case LitJson.JsonType.Boolean:
  15485. return ((bool)elem ? (LSL_String)ScriptBaseClass.JSON_TRUE : (LSL_String)ScriptBaseClass.JSON_FALSE);
  15486. case LitJson.JsonType.Double:
  15487. return (new LSL_Float((double)elem));
  15488. case LitJson.JsonType.None:
  15489. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15490. case LitJson.JsonType.String:
  15491. return (new LSL_String((string)elem));
  15492. case LitJson.JsonType.Array:
  15493. case LitJson.JsonType.Object:
  15494. string s = LitJson.JsonMapper.ToJson(elem);
  15495. return (LSL_String)s;
  15496. default:
  15497. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15498. }
  15499. }
  15500. public LSL_String llList2Json(LSL_String type, LSL_List values)
  15501. {
  15502. try
  15503. {
  15504. StringBuilder sb = new StringBuilder();
  15505. if (type == ScriptBaseClass.JSON_ARRAY)
  15506. {
  15507. sb.Append("[");
  15508. int i= 0;
  15509. foreach (object o in values.Data)
  15510. {
  15511. sb.Append(ListToJson(o));
  15512. if((i++) < values.Data.Length - 1)
  15513. sb.Append(",");
  15514. }
  15515. sb.Append("]");
  15516. return (LSL_String)sb.ToString();;
  15517. }
  15518. else if (type == ScriptBaseClass.JSON_OBJECT)
  15519. {
  15520. sb.Append("{");
  15521. for (int i = 0; i < values.Data.Length; i += 2)
  15522. {
  15523. if (!(values.Data[i] is LSL_String))
  15524. return ScriptBaseClass.JSON_INVALID;
  15525. string key = ((LSL_String)values.Data[i]).m_string;
  15526. key = EscapeForJSON(key, true);
  15527. sb.Append(key);
  15528. sb.Append(":");
  15529. sb.Append(ListToJson(values.Data[i+1]));
  15530. if(i < values.Data.Length - 2)
  15531. sb.Append(",");
  15532. }
  15533. sb.Append("}");
  15534. return (LSL_String)sb.ToString();
  15535. }
  15536. return ScriptBaseClass.JSON_INVALID;
  15537. }
  15538. catch
  15539. {
  15540. return ScriptBaseClass.JSON_INVALID;
  15541. }
  15542. }
  15543. private string ListToJson(object o)
  15544. {
  15545. if (o is LSL_Float || o is double)
  15546. {
  15547. double float_val;
  15548. if (o is double)
  15549. float_val = ((double)o);
  15550. else
  15551. float_val = ((LSL_Float)o).value;
  15552. if(double.IsInfinity(float_val))
  15553. return "\"Inf\"";
  15554. if(double.IsNaN(float_val))
  15555. return "\"NaN\"";
  15556. return ((LSL_Float)float_val).ToString();
  15557. }
  15558. if (o is LSL_Integer || o is int)
  15559. {
  15560. int i;
  15561. if (o is int)
  15562. i = ((int)o);
  15563. else
  15564. i = ((LSL_Integer)o).value;
  15565. return i.ToString();
  15566. }
  15567. if (o is LSL_Rotation)
  15568. {
  15569. StringBuilder sb = new StringBuilder(128);
  15570. sb.Append("\"");
  15571. LSL_Rotation r = (LSL_Rotation)o;
  15572. sb.Append(r.ToString());
  15573. sb.Append("\"");
  15574. return sb.ToString();
  15575. }
  15576. if (o is LSL_Vector)
  15577. {
  15578. StringBuilder sb = new StringBuilder(128);
  15579. sb.Append("\"");
  15580. LSL_Vector v = (LSL_Vector)o;
  15581. sb.Append(v.ToString());
  15582. sb.Append("\"");
  15583. return sb.ToString();
  15584. }
  15585. if (o is LSL_String || o is string)
  15586. {
  15587. string str;
  15588. if (o is string)
  15589. str = ((string)o);
  15590. else
  15591. str = ((LSL_String)o).m_string;
  15592. if(str == ScriptBaseClass.JSON_TRUE || str == "true")
  15593. return "true";
  15594. if(str == ScriptBaseClass.JSON_FALSE ||str == "false")
  15595. return "false";
  15596. if(str == ScriptBaseClass.JSON_NULL || str == "null")
  15597. return "null";
  15598. str.Trim();
  15599. if(str.Length == 0)
  15600. return "\"\"";
  15601. if (str[0] == '{')
  15602. return str;
  15603. if (str[0] == '[')
  15604. return str;
  15605. return EscapeForJSON(str, true);
  15606. }
  15607. throw new IndexOutOfRangeException();
  15608. }
  15609. private string EscapeForJSON(string s, bool AddOuter)
  15610. {
  15611. int i;
  15612. char c;
  15613. String t;
  15614. int len = s.Length;
  15615. StringBuilder sb = new StringBuilder(len + 64);
  15616. if(AddOuter)
  15617. sb.Append("\"");
  15618. for (i = 0; i < len; i++)
  15619. {
  15620. c = s[i];
  15621. switch (c)
  15622. {
  15623. case '\\':
  15624. case '"':
  15625. case '/':
  15626. sb.Append('\\');
  15627. sb.Append(c);
  15628. break;
  15629. case '\b':
  15630. sb.Append("\\b");
  15631. break;
  15632. case '\t':
  15633. sb.Append("\\t");
  15634. break;
  15635. case '\n':
  15636. sb.Append("\\n");
  15637. break;
  15638. case '\f':
  15639. sb.Append("\\f");
  15640. break;
  15641. case '\r':
  15642. sb.Append("\\r");
  15643. break;
  15644. default:
  15645. if (c < ' ')
  15646. {
  15647. t = "000" + String.Format("{0:X}", c);
  15648. sb.Append("\\u" + t.Substring(t.Length - 4));
  15649. }
  15650. else
  15651. {
  15652. sb.Append(c);
  15653. }
  15654. break;
  15655. }
  15656. }
  15657. if(AddOuter)
  15658. sb.Append("\"");
  15659. return sb.ToString();
  15660. }
  15661. public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
  15662. {
  15663. bool noSpecifiers = specifiers.Length == 0;
  15664. LitJson.JsonData workData;
  15665. try
  15666. {
  15667. if(noSpecifiers)
  15668. specifiers.Add(new LSL_Integer(0));
  15669. if(!String.IsNullOrEmpty(json))
  15670. workData = LitJson.JsonMapper.ToObject(json);
  15671. else
  15672. {
  15673. workData = new LitJson.JsonData();
  15674. workData.SetJsonType(LitJson.JsonType.Array);
  15675. }
  15676. }
  15677. catch (Exception e)
  15678. {
  15679. string m = e.Message; // debug point
  15680. return ScriptBaseClass.JSON_INVALID;
  15681. }
  15682. try
  15683. {
  15684. LitJson.JsonData replace = JsonSetSpecific(workData, specifiers, 0, value);
  15685. if(replace != null)
  15686. workData = replace;
  15687. }
  15688. catch (Exception e)
  15689. {
  15690. string m = e.Message; // debug point
  15691. return ScriptBaseClass.JSON_INVALID;
  15692. }
  15693. try
  15694. {
  15695. string r = LitJson.JsonMapper.ToJson(workData);
  15696. if(noSpecifiers)
  15697. r = r.Substring(1,r.Length -2); // strip leading and trailing brakets
  15698. return r;
  15699. }
  15700. catch (Exception e)
  15701. {
  15702. string m = e.Message; // debug point
  15703. }
  15704. return ScriptBaseClass.JSON_INVALID;
  15705. }
  15706. private LitJson.JsonData JsonSetSpecific(LitJson.JsonData elem, LSL_List specifiers, int level, LSL_String val)
  15707. {
  15708. object spec = specifiers.Data[level];
  15709. if(spec is LSL_String)
  15710. spec = ((LSL_String)spec).m_string;
  15711. else if (spec is LSL_Integer)
  15712. spec = ((LSL_Integer)spec).value;
  15713. if(!(spec is string || spec is int))
  15714. throw new IndexOutOfRangeException();
  15715. int speclen = specifiers.Data.Length - 1;
  15716. bool hasvalue = false;
  15717. LitJson.JsonData value = null;
  15718. LitJson.JsonType elemType = elem.GetJsonType();
  15719. if (elemType == LitJson.JsonType.Array)
  15720. {
  15721. if (spec is int)
  15722. {
  15723. int v = (int)spec;
  15724. int c = elem.Count;
  15725. if(v < 0 || (v != 0 && v > c))
  15726. throw new IndexOutOfRangeException();
  15727. if(v == c)
  15728. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15729. else
  15730. {
  15731. hasvalue = true;
  15732. value = elem[v];
  15733. }
  15734. }
  15735. else if (spec is string)
  15736. {
  15737. if((string)spec == ScriptBaseClass.JSON_APPEND)
  15738. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15739. else if(elem.Count < 2)
  15740. {
  15741. // our initial guess of array was wrong
  15742. LitJson.JsonData newdata = new LitJson.JsonData();
  15743. newdata.SetJsonType(LitJson.JsonType.Object);
  15744. IOrderedDictionary no = newdata as IOrderedDictionary;
  15745. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15746. return newdata;
  15747. }
  15748. }
  15749. }
  15750. else if (elemType == LitJson.JsonType.Object)
  15751. {
  15752. if (spec is string)
  15753. {
  15754. IOrderedDictionary e = elem as IOrderedDictionary;
  15755. string key = (string)spec;
  15756. if(e.Contains(key))
  15757. {
  15758. hasvalue = true;
  15759. value = (LitJson.JsonData)e[key];
  15760. }
  15761. else
  15762. e.Add(key, JsonBuildRestOfSpec(specifiers, level + 1, val));
  15763. }
  15764. else if(spec is int && (int)spec == 0)
  15765. {
  15766. //we are replacing a object by a array
  15767. LitJson.JsonData newData = new LitJson.JsonData();
  15768. newData.SetJsonType(LitJson.JsonType.Array);
  15769. newData.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15770. return newData;
  15771. }
  15772. }
  15773. else
  15774. {
  15775. LitJson.JsonData newData = JsonBuildRestOfSpec(specifiers, level, val);
  15776. return newData;
  15777. }
  15778. if (hasvalue)
  15779. {
  15780. if (level < speclen)
  15781. {
  15782. LitJson.JsonData replace = JsonSetSpecific(value, specifiers, level + 1, val);
  15783. if(replace != null)
  15784. {
  15785. if(elemType == LitJson.JsonType.Array)
  15786. {
  15787. if(spec is int)
  15788. elem[(int)spec] = replace;
  15789. else if( spec is string)
  15790. {
  15791. LitJson.JsonData newdata = new LitJson.JsonData();
  15792. newdata.SetJsonType(LitJson.JsonType.Object);
  15793. IOrderedDictionary no = newdata as IOrderedDictionary;
  15794. no.Add((string)spec, replace);
  15795. return newdata;
  15796. }
  15797. }
  15798. else if(elemType == LitJson.JsonType.Object)
  15799. {
  15800. if(spec is string)
  15801. elem[(string)spec] = replace;
  15802. else if(spec is int && (int)spec == 0)
  15803. {
  15804. LitJson.JsonData newdata = new LitJson.JsonData();
  15805. newdata.SetJsonType(LitJson.JsonType.Array);
  15806. newdata.Add(replace);
  15807. return newdata;
  15808. }
  15809. }
  15810. }
  15811. return null;
  15812. }
  15813. else if(speclen == level)
  15814. {
  15815. if(val == ScriptBaseClass.JSON_DELETE)
  15816. {
  15817. if(elemType == LitJson.JsonType.Array)
  15818. {
  15819. if(spec is int)
  15820. {
  15821. IList el = elem as IList;
  15822. el.RemoveAt((int)spec);
  15823. }
  15824. }
  15825. else if(elemType == LitJson.JsonType.Object)
  15826. {
  15827. if(spec is string)
  15828. {
  15829. IOrderedDictionary eo = elem as IOrderedDictionary;
  15830. eo.Remove((string) spec);
  15831. }
  15832. }
  15833. return null;
  15834. }
  15835. LitJson.JsonData newval = null;
  15836. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15837. newval = null;
  15838. else if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15839. newval = new LitJson.JsonData(true);
  15840. else if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15841. newval = new LitJson.JsonData(false);
  15842. else if(float.TryParse(val, out float num))
  15843. {
  15844. // assuming we are at en.us already
  15845. if(num - (int)num == 0.0f && !val.Contains("."))
  15846. newval = new LitJson.JsonData((int)num);
  15847. else
  15848. {
  15849. num = (float)Math.Round(num,6);
  15850. newval = new LitJson.JsonData((double)num);
  15851. }
  15852. }
  15853. else
  15854. {
  15855. string str = val.m_string;
  15856. newval = new LitJson.JsonData(str);
  15857. }
  15858. if(elemType == LitJson.JsonType.Array)
  15859. {
  15860. if(spec is int)
  15861. elem[(int)spec] = newval;
  15862. else if( spec is string)
  15863. {
  15864. LitJson.JsonData newdata = new LitJson.JsonData();
  15865. newdata.SetJsonType(LitJson.JsonType.Object);
  15866. IOrderedDictionary no = newdata as IOrderedDictionary;
  15867. no.Add((string)spec,newval);
  15868. return newdata;
  15869. }
  15870. }
  15871. else if(elemType == LitJson.JsonType.Object)
  15872. {
  15873. if(spec is string)
  15874. elem[(string)spec] = newval;
  15875. else if(spec is int && (int)spec == 0)
  15876. {
  15877. LitJson.JsonData newdata = new LitJson.JsonData();
  15878. newdata.SetJsonType(LitJson.JsonType.Array);
  15879. newdata.Add(newval);
  15880. return newdata;
  15881. }
  15882. }
  15883. }
  15884. }
  15885. if(val == ScriptBaseClass.JSON_DELETE)
  15886. throw new IndexOutOfRangeException();
  15887. return null;
  15888. }
  15889. private LitJson.JsonData JsonBuildRestOfSpec(LSL_List specifiers, int level, LSL_String val)
  15890. {
  15891. object spec = level >= specifiers.Data.Length ? null : specifiers.Data[level];
  15892. // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
  15893. if (spec == null)
  15894. {
  15895. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15896. return null;
  15897. if(val == ScriptBaseClass.JSON_DELETE)
  15898. throw new IndexOutOfRangeException();
  15899. if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15900. return new LitJson.JsonData(true);
  15901. if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15902. return new LitJson.JsonData(false);
  15903. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15904. return null;
  15905. if(float.TryParse(val, out float num))
  15906. {
  15907. // assuming we are at en.us already
  15908. if(num - (int)num == 0.0f && !val.Contains("."))
  15909. return new LitJson.JsonData((int)num);
  15910. else
  15911. {
  15912. num = (float)Math.Round(num,6);
  15913. return new LitJson.JsonData(num);
  15914. }
  15915. }
  15916. else
  15917. {
  15918. string str = val.m_string;
  15919. return new LitJson.JsonData(str);
  15920. }
  15921. throw new IndexOutOfRangeException();
  15922. }
  15923. if(spec is LSL_String)
  15924. spec = ((LSL_String)spec).m_string;
  15925. else if (spec is LSL_Integer)
  15926. spec = ((LSL_Integer)spec).value;
  15927. if (spec is int ||
  15928. (spec is string && ((string)spec) == ScriptBaseClass.JSON_APPEND) )
  15929. {
  15930. if(spec is int && (int)spec != 0)
  15931. throw new IndexOutOfRangeException();
  15932. LitJson.JsonData newdata = new LitJson.JsonData();
  15933. newdata.SetJsonType(LitJson.JsonType.Array);
  15934. newdata.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15935. return newdata;
  15936. }
  15937. else if (spec is string)
  15938. {
  15939. LitJson.JsonData newdata = new LitJson.JsonData();
  15940. newdata.SetJsonType(LitJson.JsonType.Object);
  15941. IOrderedDictionary no = newdata as IOrderedDictionary;
  15942. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15943. return newdata;
  15944. }
  15945. throw new IndexOutOfRangeException();
  15946. }
  15947. private bool JsonFind(LitJson.JsonData elem, LSL_List specifiers, int level, out LitJson.JsonData value)
  15948. {
  15949. value = null;
  15950. if(elem == null)
  15951. return false;
  15952. object spec;
  15953. spec = specifiers.Data[level];
  15954. bool haveVal = false;
  15955. LitJson.JsonData next = null;
  15956. if (elem.GetJsonType() == LitJson.JsonType.Array)
  15957. {
  15958. if (spec is LSL_Integer)
  15959. {
  15960. int indx = (LSL_Integer)spec;
  15961. if(indx >= 0 && indx < elem.Count)
  15962. {
  15963. haveVal = true;
  15964. next = (LitJson.JsonData)elem[indx];
  15965. }
  15966. }
  15967. }
  15968. else if (elem.GetJsonType() == LitJson.JsonType.Object)
  15969. {
  15970. if (spec is LSL_String)
  15971. {
  15972. IOrderedDictionary e = elem as IOrderedDictionary;
  15973. string key = (LSL_String)spec;
  15974. if(e.Contains(key))
  15975. {
  15976. haveVal = true;
  15977. next = (LitJson.JsonData)e[key];
  15978. }
  15979. }
  15980. }
  15981. if (haveVal)
  15982. {
  15983. if(level == specifiers.Data.Length - 1)
  15984. {
  15985. value = next;
  15986. return true;
  15987. }
  15988. level++;
  15989. if(next == null)
  15990. return false;
  15991. LitJson.JsonType nextType = next.GetJsonType();
  15992. if(nextType != LitJson.JsonType.Object && nextType != LitJson.JsonType.Array)
  15993. return false;
  15994. return JsonFind(next, specifiers, level, out value);
  15995. }
  15996. return false;
  15997. }
  15998. public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
  15999. {
  16000. if(String.IsNullOrWhiteSpace(json))
  16001. return ScriptBaseClass.JSON_INVALID;
  16002. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  16003. return ScriptBaseClass.JSON_INVALID;
  16004. char first = ((string)json)[0];
  16005. if((first != '[' && first !='{'))
  16006. {
  16007. if(specifiers.Length > 0)
  16008. return ScriptBaseClass.JSON_INVALID;
  16009. json = "[" + json + "]"; // could handle single element case.. but easier like this
  16010. specifiers.Add((LSL_Integer)0);
  16011. }
  16012. LitJson.JsonData jsonData;
  16013. try
  16014. {
  16015. jsonData = LitJson.JsonMapper.ToObject(json);
  16016. }
  16017. catch (Exception e)
  16018. {
  16019. string m = e.Message; // debug point
  16020. return ScriptBaseClass.JSON_INVALID;
  16021. }
  16022. LitJson.JsonData elem = null;
  16023. if(specifiers.Length == 0)
  16024. elem = jsonData;
  16025. else
  16026. {
  16027. if(!JsonFind(jsonData, specifiers, 0, out elem))
  16028. return ScriptBaseClass.JSON_INVALID;
  16029. }
  16030. return JsonElementToString(elem);
  16031. }
  16032. private LSL_String JsonElementToString(LitJson.JsonData elem)
  16033. {
  16034. if(elem == null)
  16035. return ScriptBaseClass.JSON_NULL;
  16036. LitJson.JsonType elemType = elem.GetJsonType();
  16037. switch(elemType)
  16038. {
  16039. case LitJson.JsonType.Array:
  16040. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  16041. case LitJson.JsonType.Boolean:
  16042. return new LSL_String((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE);
  16043. case LitJson.JsonType.Double:
  16044. double d= (double)elem;
  16045. string sd = String.Format(Culture.FormatProvider, "{0:0.0#####}",d);
  16046. return new LSL_String(sd);
  16047. case LitJson.JsonType.Int:
  16048. int i = (int)elem;
  16049. return new LSL_String(i.ToString());
  16050. case LitJson.JsonType.Long:
  16051. long l = (long)elem;
  16052. return new LSL_String(l.ToString());
  16053. case LitJson.JsonType.Object:
  16054. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  16055. case LitJson.JsonType.String:
  16056. string s = (string)elem;
  16057. return new LSL_String(s);
  16058. case LitJson.JsonType.None:
  16059. return ScriptBaseClass.JSON_NULL;
  16060. default:
  16061. return ScriptBaseClass.JSON_INVALID;
  16062. }
  16063. }
  16064. public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
  16065. {
  16066. if(String.IsNullOrWhiteSpace(json))
  16067. return ScriptBaseClass.JSON_INVALID;
  16068. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  16069. return ScriptBaseClass.JSON_INVALID;
  16070. char first = ((string)json)[0];
  16071. if((first != '[' && first !='{'))
  16072. {
  16073. if(specifiers.Length > 0)
  16074. return ScriptBaseClass.JSON_INVALID;
  16075. json = "[" + json + "]"; // could handle single element case.. but easier like this
  16076. specifiers.Add((LSL_Integer)0);
  16077. }
  16078. LitJson.JsonData jsonData;
  16079. try
  16080. {
  16081. jsonData = LitJson.JsonMapper.ToObject(json);
  16082. }
  16083. catch (Exception e)
  16084. {
  16085. string m = e.Message; // debug point
  16086. return ScriptBaseClass.JSON_INVALID;
  16087. }
  16088. LitJson.JsonData elem = null;
  16089. if(specifiers.Length == 0)
  16090. elem = jsonData;
  16091. else
  16092. {
  16093. if(!JsonFind(jsonData, specifiers, 0, out elem))
  16094. return ScriptBaseClass.JSON_INVALID;
  16095. }
  16096. if(elem == null)
  16097. return ScriptBaseClass.JSON_NULL;
  16098. LitJson.JsonType elemType = elem.GetJsonType();
  16099. switch(elemType)
  16100. {
  16101. case LitJson.JsonType.Array:
  16102. return ScriptBaseClass.JSON_ARRAY;
  16103. case LitJson.JsonType.Boolean:
  16104. return (bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
  16105. case LitJson.JsonType.Double:
  16106. case LitJson.JsonType.Int:
  16107. case LitJson.JsonType.Long:
  16108. return ScriptBaseClass.JSON_NUMBER;
  16109. case LitJson.JsonType.Object:
  16110. return ScriptBaseClass.JSON_OBJECT;
  16111. case LitJson.JsonType.String:
  16112. string s = (string)elem;
  16113. if(s == ScriptBaseClass.JSON_NULL)
  16114. return ScriptBaseClass.JSON_NULL;
  16115. if(s == ScriptBaseClass.JSON_TRUE)
  16116. return ScriptBaseClass.JSON_TRUE;
  16117. if(s == ScriptBaseClass.JSON_FALSE)
  16118. return ScriptBaseClass.JSON_FALSE;
  16119. return ScriptBaseClass.JSON_STRING;
  16120. case LitJson.JsonType.None:
  16121. return ScriptBaseClass.JSON_NULL;
  16122. default:
  16123. return ScriptBaseClass.JSON_INVALID;
  16124. }
  16125. }
  16126. }
  16127. public class NotecardCache
  16128. {
  16129. private static ExpiringCacheOS<UUID, string[]> m_Notecards = new ExpiringCacheOS<UUID, string[]>(30000);
  16130. public static void Cache(UUID assetID, byte[] text)
  16131. {
  16132. if (m_Notecards.ContainsKey(assetID, 30000))
  16133. return;
  16134. m_Notecards.AddOrUpdate(assetID, SLUtil.ParseNotecardToArray(text), 30);
  16135. }
  16136. public static bool IsCached(UUID assetID)
  16137. {
  16138. return m_Notecards.ContainsKey(assetID, 30000);
  16139. }
  16140. public static int GetLines(UUID assetID)
  16141. {
  16142. if (m_Notecards.TryGetValue(assetID, 30000, out string[] text))
  16143. return text.Length;
  16144. return -1;
  16145. }
  16146. /// <summary>
  16147. /// Get a notecard line.
  16148. /// </summary>
  16149. /// <param name="assetID"></param>
  16150. /// <param name="lineNumber">Lines start at index 0</param>
  16151. /// <returns></returns>
  16152. public static string GetLine(UUID assetID, int lineNumber)
  16153. {
  16154. if (lineNumber >= 0 && m_Notecards.TryGetValue(assetID, 30000, out string[] text))
  16155. {
  16156. if (lineNumber >= text.Length)
  16157. return "\n\n\n";
  16158. return text[lineNumber];
  16159. }
  16160. return "";
  16161. }
  16162. /// <summary>
  16163. /// Get a notecard line.
  16164. /// </summary>
  16165. /// <param name="assetID"></param>
  16166. /// <param name="lineNumber">Lines start at index 0</param>
  16167. /// <param name="maxLength">
  16168. /// Maximum length of the returned line.
  16169. /// </param>
  16170. /// <returns>
  16171. /// If the line length is longer than <paramref name="maxLength"/>,
  16172. /// the return string will be truncated.
  16173. /// </returns>
  16174. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  16175. {
  16176. string line = GetLine(assetID, lineNumber);
  16177. if (line.Length > maxLength)
  16178. return line.Substring(0, maxLength);
  16179. return line;
  16180. }
  16181. }
  16182. }