LSL_Api.cs 713 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153
  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 System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Collections.Specialized;
  31. using System.Diagnostics;
  32. using System.Drawing;
  33. using System.Drawing.Imaging;
  34. using System.Runtime.Remoting.Lifetime;
  35. using System.Text;
  36. using System.Threading;
  37. using System.Text.RegularExpressions;
  38. using System.Timers;
  39. using Nini.Config;
  40. using log4net;
  41. using OpenMetaverse;
  42. using OpenMetaverse.Assets;
  43. using OpenMetaverse.StructuredData; // LitJson is hidden on this
  44. using OpenMetaverse.Packets;
  45. using OpenMetaverse.Rendering;
  46. using OpenSim;
  47. using OpenSim.Framework;
  48. using OpenSim.Region.CoreModules;
  49. using OpenSim.Region.CoreModules.World.Land;
  50. using OpenSim.Region.CoreModules.World.Terrain;
  51. using OpenSim.Region.Framework.Interfaces;
  52. using OpenSim.Region.Framework.Scenes;
  53. using OpenSim.Region.Framework.Scenes.Serialization;
  54. using OpenSim.Region.Framework.Scenes.Animation;
  55. using OpenSim.Region.Framework.Scenes.Scripting;
  56. using OpenSim.Region.PhysicsModules.SharedBase;
  57. using OpenSim.Region.ScriptEngine.Shared;
  58. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  59. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  60. using OpenSim.Region.ScriptEngine.Interfaces;
  61. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  62. using OpenSim.Services.Interfaces;
  63. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  64. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  65. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  66. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  67. using RegionFlags = OpenSim.Framework.RegionFlags;
  68. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  69. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  70. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  71. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  72. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  73. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  74. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  75. using System.Reflection;
  76. using Timer = System.Timers.Timer;
  77. using System.Linq;
  78. using PermissionMask = OpenSim.Framework.PermissionMask;
  79. namespace OpenSim.Region.ScriptEngine.Shared.Api
  80. {
  81. // MUST be a ref type
  82. public class UserInfoCacheEntry
  83. {
  84. public int time;
  85. public UserAccount account;
  86. public PresenceInfo pinfo;
  87. }
  88. /// <summary>
  89. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  90. /// </summary>
  91. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  92. {
  93. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  94. public int LlRequestAgentDataCacheTimeoutMs { get; set; }
  95. protected IScriptEngine m_ScriptEngine;
  96. protected SceneObjectPart m_host;
  97. /// <summary>
  98. /// The item that hosts this script
  99. /// </summary>
  100. protected TaskInventoryItem m_item;
  101. protected bool throwErrorOnNotImplemented = false;
  102. protected AsyncCommandManager AsyncCommands = null;
  103. protected float m_ScriptDelayFactor = 1.0f;
  104. protected float m_ScriptDistanceFactor = 1.0f;
  105. protected float m_MinTimerInterval = 0.5f;
  106. protected float m_recoilScaleFactor = 0.0f;
  107. protected double m_timer = Util.GetTimeStampMS();
  108. protected bool m_waitingForScriptAnswer = false;
  109. protected bool m_automaticLinkPermission = false;
  110. protected IMessageTransferModule m_TransferModule = null;
  111. protected int m_notecardLineReadCharsMax = 255;
  112. protected int m_scriptConsoleChannel = 0;
  113. protected bool m_scriptConsoleChannelEnabled = false;
  114. protected bool m_debuggerSafe = false;
  115. protected IUrlModule m_UrlModule = null;
  116. protected IMaterialsModule m_materialsModule = null;
  117. protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>();
  118. protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
  119. protected int m_sleepMsOnSetTexture = 200;
  120. protected int m_sleepMsOnSetLinkTexture = 200;
  121. protected int m_sleepMsOnScaleTexture = 200;
  122. protected int m_sleepMsOnOffsetTexture = 200;
  123. protected int m_sleepMsOnRotateTexture = 200;
  124. protected int m_sleepMsOnSetPos = 200;
  125. protected int m_sleepMsOnSetRot = 200;
  126. protected int m_sleepMsOnSetLocalRot = 200;
  127. protected int m_sleepMsOnPreloadSound = 1000;
  128. protected int m_sleepMsOnMakeExplosion = 100;
  129. protected int m_sleepMsOnMakeFountain = 100;
  130. protected int m_sleepMsOnMakeSmoke = 100;
  131. protected int m_sleepMsOnMakeFire = 100;
  132. protected int m_sleepMsOnRezAtRoot = 100;
  133. protected int m_sleepMsOnInstantMessage = 2000;
  134. protected int m_sleepMsOnEmail = 20000;
  135. protected int m_sleepMsOnCreateLink = 1000;
  136. protected int m_sleepMsOnGiveInventory = 3000;
  137. protected int m_sleepMsOnRequestAgentData = 100;
  138. protected int m_sleepMsOnRequestInventoryData = 1000;
  139. protected int m_sleepMsOnSetDamage = 5000;
  140. protected int m_sleepMsOnTextBox = 1000;
  141. protected int m_sleepMsOnAdjustSoundVolume = 100;
  142. protected int m_sleepMsOnEjectFromLand = 1000;
  143. protected int m_sleepMsOnAddToLandPassList = 100;
  144. protected int m_sleepMsOnDialog = 1000;
  145. protected int m_sleepMsOnRemoteLoadScript = 3000;
  146. protected int m_sleepMsOnRemoteLoadScriptPin = 3000;
  147. protected int m_sleepMsOnOpenRemoteDataChannel = 1000;
  148. protected int m_sleepMsOnSendRemoteData = 3000;
  149. protected int m_sleepMsOnRemoteDataReply = 3000;
  150. protected int m_sleepMsOnCloseRemoteDataChannel = 1000;
  151. protected int m_sleepMsOnSetPrimitiveParams = 200;
  152. protected int m_sleepMsOnSetLinkPrimitiveParams = 200;
  153. protected int m_sleepMsOnXorBase64Strings = 300;
  154. protected int m_sleepMsOnSetParcelMusicURL = 2000;
  155. protected int m_sleepMsOnGetPrimMediaParams = 1000;
  156. protected int m_sleepMsOnGetLinkMedia = 1000;
  157. protected int m_sleepMsOnSetPrimMediaParams = 1000;
  158. protected int m_sleepMsOnSetLinkMedia = 1000;
  159. protected int m_sleepMsOnClearPrimMedia = 1000;
  160. protected int m_sleepMsOnClearLinkMedia = 1000;
  161. protected int m_sleepMsOnRequestSimulatorData = 1000;
  162. protected int m_sleepMsOnLoadURL = 10000;
  163. protected int m_sleepMsOnParcelMediaCommandList = 2000;
  164. protected int m_sleepMsOnParcelMediaQuery = 2000;
  165. protected int m_sleepMsOnModPow = 1000;
  166. protected int m_sleepMsOnSetPrimURL = 2000;
  167. protected int m_sleepMsOnRefreshPrimURL = 20000;
  168. protected int m_sleepMsOnMapDestination = 1000;
  169. protected int m_sleepMsOnAddToLandBanList = 100;
  170. protected int m_sleepMsOnRemoveFromLandPassList = 100;
  171. protected int m_sleepMsOnRemoveFromLandBanList = 100;
  172. protected int m_sleepMsOnResetLandBanList = 100;
  173. protected int m_sleepMsOnResetLandPassList = 100;
  174. protected int m_sleepMsOnGetParcelPrimOwners = 2000;
  175. protected int m_sleepMsOnGetNumberOfNotecardLines = 100;
  176. protected int m_sleepMsOnGetNotecardLine = 100;
  177. protected string m_internalObjectHost = "lsl.opensim.local";
  178. protected bool m_restrictEmail = false;
  179. protected ISoundModule m_SoundModule = null;
  180. protected float m_avatarHeightCorrection = 0.2f;
  181. protected bool m_useSimpleBoxesInGetBoundingBox = false;
  182. protected bool m_addStatsInGetBoundingBox = false;
  183. //LSL Avatar Bounding Box (lABB), lower (1) and upper (2),
  184. //standing (Std), Groundsitting (Grs), Sitting (Sit),
  185. //along X, Y and Z axes, constants (0) and coefficients (1)
  186. protected float m_lABB1StdX0 = -0.275f;
  187. protected float m_lABB2StdX0 = 0.275f;
  188. protected float m_lABB1StdY0 = -0.35f;
  189. protected float m_lABB2StdY0 = 0.35f;
  190. protected float m_lABB1StdZ0 = -0.1f;
  191. protected float m_lABB1StdZ1 = -0.5f;
  192. protected float m_lABB2StdZ0 = 0.1f;
  193. protected float m_lABB2StdZ1 = 0.5f;
  194. protected float m_lABB1GrsX0 = -0.3875f;
  195. protected float m_lABB2GrsX0 = 0.3875f;
  196. protected float m_lABB1GrsY0 = -0.5f;
  197. protected float m_lABB2GrsY0 = 0.5f;
  198. protected float m_lABB1GrsZ0 = -0.05f;
  199. protected float m_lABB1GrsZ1 = -0.375f;
  200. protected float m_lABB2GrsZ0 = 0.5f;
  201. protected float m_lABB2GrsZ1 = 0.0f;
  202. protected float m_lABB1SitX0 = -0.5875f;
  203. protected float m_lABB2SitX0 = 0.1875f;
  204. protected float m_lABB1SitY0 = -0.35f;
  205. protected float m_lABB2SitY0 = 0.35f;
  206. protected float m_lABB1SitZ0 = -0.35f;
  207. protected float m_lABB1SitZ1 = -0.375f;
  208. protected float m_lABB2SitZ0 = -0.25f;
  209. protected float m_lABB2SitZ1 = 0.25f;
  210. protected float m_primSafetyCoeffX = 2.414214f;
  211. protected float m_primSafetyCoeffY = 2.414214f;
  212. protected float m_primSafetyCoeffZ = 1.618034f;
  213. protected bool m_useCastRayV3 = false;
  214. protected float m_floatToleranceInCastRay = 0.00001f;
  215. protected float m_floatTolerance2InCastRay = 0.001f;
  216. protected DetailLevel m_primLodInCastRay = DetailLevel.Medium;
  217. protected DetailLevel m_sculptLodInCastRay = DetailLevel.Medium;
  218. protected DetailLevel m_meshLodInCastRay = DetailLevel.Highest;
  219. protected DetailLevel m_avatarLodInCastRay = DetailLevel.Medium;
  220. protected int m_maxHitsInCastRay = 16;
  221. protected int m_maxHitsPerPrimInCastRay = 16;
  222. protected int m_maxHitsPerObjectInCastRay = 16;
  223. protected bool m_detectExitsInCastRay = false;
  224. protected bool m_doAttachmentsInCastRay = false;
  225. protected int m_msThrottleInCastRay = 200;
  226. protected int m_msPerRegionInCastRay = 40;
  227. protected int m_msPerAvatarInCastRay = 10;
  228. protected int m_msMinInCastRay = 2;
  229. protected int m_msMaxInCastRay = 40;
  230. protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>();
  231. protected bool m_useMeshCacheInCastRay = true;
  232. protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>();
  233. // protected Timer m_ShoutSayTimer;
  234. protected int m_SayShoutCount = 0;
  235. DateTime m_lastSayShoutCheck;
  236. private Dictionary<string, string> MovementAnimationsForLSL =
  237. new Dictionary<string, string> {
  238. {"CROUCH", "Crouching"},
  239. {"CROUCHWALK", "CrouchWalking"},
  240. {"FALLDOWN", "Falling Down"},
  241. {"FLY", "Flying"},
  242. {"FLYSLOW", "FlyingSlow"},
  243. {"HOVER", "Hovering"},
  244. {"HOVER_UP", "Hovering Up"},
  245. {"HOVER_DOWN", "Hovering Down"},
  246. {"JUMP", "Jumping"},
  247. {"LAND", "Landing"},
  248. {"PREJUMP", "PreJumping"},
  249. {"RUN", "Running"},
  250. {"SIT","Sitting"},
  251. {"SITGROUND","Sitting on Ground"},
  252. {"STAND", "Standing"},
  253. {"STANDUP", "Standing Up"},
  254. {"STRIDE","Striding"},
  255. {"SOFT_LAND", "Soft Landing"},
  256. {"TURNLEFT", "Turning Left"},
  257. {"TURNRIGHT", "Turning Right"},
  258. {"WALK", "Walking"}
  259. };
  260. //An array of HTTP/1.1 headers that are not allowed to be used
  261. //as custom headers by llHTTPRequest.
  262. private string[] HttpStandardHeaders =
  263. {
  264. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  265. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  266. "Connection", "Content-Encoding", "Content-Language",
  267. "Content-Length", "Content-Location", "Content-MD5",
  268. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  269. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  270. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  271. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  272. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  273. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  274. "Vary", "Via", "Warning", "WWW-Authenticate"
  275. };
  276. public void Initialize(
  277. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  278. {
  279. m_lastSayShoutCheck = DateTime.UtcNow;
  280. m_ScriptEngine = scriptEngine;
  281. m_host = host;
  282. m_item = item;
  283. m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
  284. LoadConfig();
  285. m_TransferModule =
  286. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  287. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  288. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  289. m_materialsModule = m_ScriptEngine.World.RequestModuleInterface<IMaterialsModule>();
  290. AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  291. }
  292. /// <summary>
  293. /// Load configuration items that affect script, object and run-time behavior. */
  294. /// </summary>
  295. private void LoadConfig()
  296. {
  297. LlRequestAgentDataCacheTimeoutMs = 20000;
  298. IConfig seConfig = m_ScriptEngine.Config;
  299. if (seConfig != null)
  300. {
  301. m_ScriptDelayFactor =
  302. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  303. m_ScriptDistanceFactor =
  304. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  305. m_MinTimerInterval =
  306. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  307. m_automaticLinkPermission =
  308. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  309. m_notecardLineReadCharsMax =
  310. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  311. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  312. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  313. // it by this factor. May be zero to turn off recoil all together.
  314. m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  315. }
  316. if (m_notecardLineReadCharsMax > 65535)
  317. m_notecardLineReadCharsMax = 65535;
  318. // load limits for particular subsystems.
  319. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  320. if (seConfigSource != null)
  321. {
  322. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  323. if (lslConfig != null)
  324. {
  325. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  326. m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection);
  327. m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox);
  328. m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox);
  329. m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0);
  330. m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0);
  331. m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0);
  332. m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0);
  333. m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0);
  334. m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1);
  335. m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0);
  336. m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1);
  337. m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0);
  338. m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0);
  339. m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0);
  340. m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0);
  341. m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0);
  342. m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1);
  343. m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0);
  344. m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1);
  345. m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0);
  346. m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0);
  347. m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0);
  348. m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0);
  349. m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0);
  350. m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1);
  351. m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0);
  352. m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1);
  353. m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX);
  354. m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY);
  355. m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ);
  356. m_useCastRayV3 = lslConfig.GetBoolean("UseLlCastRayV3", m_useCastRayV3);
  357. m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay);
  358. m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay);
  359. m_primLodInCastRay = (DetailLevel)lslConfig.GetInt("PrimDetailLevelInLlCastRay", (int)m_primLodInCastRay);
  360. m_sculptLodInCastRay = (DetailLevel)lslConfig.GetInt("SculptDetailLevelInLlCastRay", (int)m_sculptLodInCastRay);
  361. m_meshLodInCastRay = (DetailLevel)lslConfig.GetInt("MeshDetailLevelInLlCastRay", (int)m_meshLodInCastRay);
  362. m_avatarLodInCastRay = (DetailLevel)lslConfig.GetInt("AvatarDetailLevelInLlCastRay", (int)m_avatarLodInCastRay);
  363. m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay);
  364. m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay);
  365. m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay);
  366. m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay);
  367. m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay);
  368. m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay);
  369. m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay);
  370. m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay);
  371. m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay);
  372. m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay);
  373. m_useMeshCacheInCastRay = lslConfig.GetBoolean("UseMeshCacheInLlCastRay", m_useMeshCacheInCastRay);
  374. }
  375. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  376. if (smtpConfig != null)
  377. {
  378. // there's an smtp config, so load in the snooze time.
  379. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  380. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  381. }
  382. }
  383. m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000;
  384. }
  385. public override Object InitializeLifetimeService()
  386. {
  387. ILease lease = (ILease)base.InitializeLifetimeService();
  388. if (lease.CurrentState == LeaseState.Initial)
  389. {
  390. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  391. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  392. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  393. }
  394. return lease;
  395. }
  396. protected SceneObjectPart MonitoringObject()
  397. {
  398. UUID m = m_host.ParentGroup.MonitoringObject;
  399. if (m == UUID.Zero)
  400. return null;
  401. SceneObjectPart p = m_ScriptEngine.World.GetSceneObjectPart(m);
  402. if (p == null)
  403. m_host.ParentGroup.MonitoringObject = UUID.Zero;
  404. return p;
  405. }
  406. protected virtual void ScriptSleep(int delay)
  407. {
  408. delay = (int)(delay * m_ScriptDelayFactor);
  409. if (delay < 10)
  410. return;
  411. Sleep(delay);
  412. }
  413. protected virtual void Sleep(int delay)
  414. {
  415. if (m_item == null) // Some unit tests don't set this
  416. Thread.Sleep(delay);
  417. else
  418. m_ScriptEngine.SleepScript(m_item.ItemID, delay);
  419. }
  420. /// <summary>
  421. /// Check for co-operative termination.
  422. /// </summary>
  423. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  424. public Scene World
  425. {
  426. get { return m_ScriptEngine.World; }
  427. }
  428. [DebuggerNonUserCode]
  429. public void state(string newState)
  430. {
  431. m_ScriptEngine.SetState(m_item.ItemID, newState);
  432. }
  433. /// <summary>
  434. /// Reset the named script. The script must be present
  435. /// in the same prim.
  436. /// </summary>
  437. [DebuggerNonUserCode]
  438. public void llResetScript()
  439. {
  440. m_host.AddScriptLPS(1);
  441. // We need to tell the URL module, if we hav one, to release
  442. // the allocated URLs
  443. if (m_UrlModule != null)
  444. m_UrlModule.ScriptRemoved(m_item.ItemID);
  445. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  446. }
  447. public void llResetOtherScript(string name)
  448. {
  449. UUID item;
  450. if ((item = GetScriptByName(name)) == UUID.Zero)
  451. {
  452. m_host.AddScriptLPS(1);
  453. Error("llResetOtherScript", "Can't find script '" + name + "'");
  454. return;
  455. }
  456. if(item == m_item.ItemID)
  457. llResetScript();
  458. else
  459. {
  460. m_host.AddScriptLPS(1);
  461. m_ScriptEngine.ResetScript(item);
  462. }
  463. }
  464. public LSL_Integer llGetScriptState(string name)
  465. {
  466. UUID item;
  467. m_host.AddScriptLPS(1);
  468. if ((item = GetScriptByName(name)) != UUID.Zero)
  469. {
  470. return m_ScriptEngine.GetScriptState(item) ?1:0;
  471. }
  472. Error("llGetScriptState", "Can't find script '" + name + "'");
  473. // If we didn't find it, then it's safe to
  474. // assume it is not running.
  475. return 0;
  476. }
  477. public void llSetScriptState(string name, int run)
  478. {
  479. UUID item;
  480. m_host.AddScriptLPS(1);
  481. // These functions are supposed to be robust,
  482. // so get the state one step at a time.
  483. if ((item = GetScriptByName(name)) != UUID.Zero)
  484. {
  485. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true, item == m_item.ItemID);
  486. }
  487. else
  488. {
  489. Error("llSetScriptState", "Can't find script '" + name + "'");
  490. }
  491. }
  492. public List<ScenePresence> GetLinkAvatars(int linkType)
  493. {
  494. List<ScenePresence> ret = new List<ScenePresence>();
  495. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  496. return ret;
  497. // List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
  498. // this needs check
  499. List<ScenePresence> avs = m_host.ParentGroup.GetSittingAvatars();
  500. switch (linkType)
  501. {
  502. case ScriptBaseClass.LINK_SET:
  503. return avs;
  504. case ScriptBaseClass.LINK_ROOT:
  505. return ret;
  506. case ScriptBaseClass.LINK_ALL_OTHERS:
  507. return avs;
  508. case ScriptBaseClass.LINK_ALL_CHILDREN:
  509. return avs;
  510. case ScriptBaseClass.LINK_THIS:
  511. return ret;
  512. default:
  513. if (linkType < 0)
  514. return ret;
  515. int partCount = m_host.ParentGroup.GetPartCount();
  516. if (linkType <= partCount)
  517. {
  518. return ret;
  519. }
  520. else
  521. {
  522. linkType = linkType - partCount;
  523. if (linkType > avs.Count)
  524. {
  525. return ret;
  526. }
  527. else
  528. {
  529. ret.Add(avs[linkType-1]);
  530. return ret;
  531. }
  532. }
  533. }
  534. }
  535. /// <summary>
  536. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  537. /// </summary>
  538. /// <remarks>
  539. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  540. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  541. /// The ScenePresences receive linknums in the order in which they sat.
  542. /// </remarks>
  543. /// <returns>
  544. /// The link entity. null if not found.
  545. /// </returns>
  546. /// <param name='part'></param>
  547. /// <param name='linknum'>
  548. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  549. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  550. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  551. /// positive integer is given in this case then null is returned.
  552. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  553. /// of entities, then the entity which corresponds to that linknum is returned.
  554. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  555. /// null is returned.
  556. /// </param>
  557. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  558. {
  559. if (linknum < 0)
  560. {
  561. if (linknum == ScriptBaseClass.LINK_THIS)
  562. return part;
  563. else
  564. return null;
  565. }
  566. int actualPrimCount = part.ParentGroup.PrimCount;
  567. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  568. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  569. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  570. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  571. if (linknum == 0)
  572. {
  573. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  574. return part;
  575. return null;
  576. }
  577. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  578. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  579. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  580. {
  581. if (sittingAvatars.Count > 0)
  582. return part.ParentGroup.RootPart;
  583. else
  584. return null;
  585. }
  586. else if (linknum <= adjustedPrimCount)
  587. {
  588. if (linknum <= actualPrimCount)
  589. {
  590. return part.ParentGroup.GetLinkNumPart(linknum);
  591. }
  592. else
  593. {
  594. return sittingAvatars[linknum - actualPrimCount - 1];
  595. }
  596. }
  597. else
  598. {
  599. return null;
  600. }
  601. }
  602. public List<SceneObjectPart> GetLinkParts(int linkType)
  603. {
  604. return GetLinkParts(m_host, linkType);
  605. }
  606. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  607. {
  608. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  609. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  610. return ret;
  611. switch (linkType)
  612. {
  613. case ScriptBaseClass.LINK_SET:
  614. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  615. case ScriptBaseClass.LINK_ROOT:
  616. ret.Add(part.ParentGroup.RootPart);
  617. return ret;
  618. case ScriptBaseClass.LINK_ALL_OTHERS:
  619. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  620. if (ret.Contains(part))
  621. ret.Remove(part);
  622. return ret;
  623. case ScriptBaseClass.LINK_ALL_CHILDREN:
  624. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  625. if (ret.Contains(part.ParentGroup.RootPart))
  626. ret.Remove(part.ParentGroup.RootPart);
  627. return ret;
  628. case ScriptBaseClass.LINK_THIS:
  629. ret.Add(part);
  630. return ret;
  631. default:
  632. if (linkType < 0)
  633. return ret;
  634. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  635. if (target == null)
  636. return ret;
  637. ret.Add(target);
  638. return ret;
  639. }
  640. }
  641. public List<ISceneEntity> GetLinkEntities(int linkType)
  642. {
  643. return GetLinkEntities(m_host, linkType);
  644. }
  645. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  646. {
  647. List<ISceneEntity> ret;
  648. switch (linkType)
  649. {
  650. case ScriptBaseClass.LINK_SET:
  651. return new List<ISceneEntity>(part.ParentGroup.Parts);
  652. case ScriptBaseClass.LINK_ROOT:
  653. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  654. case ScriptBaseClass.LINK_ALL_OTHERS:
  655. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  656. if (ret.Contains(part))
  657. ret.Remove(part);
  658. return ret;
  659. case ScriptBaseClass.LINK_ALL_CHILDREN:
  660. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  661. if (ret.Contains(part.ParentGroup.RootPart))
  662. ret.Remove(part.ParentGroup.RootPart);
  663. List<ScenePresence> avs = part.ParentGroup.GetSittingAvatars();
  664. if(avs!= null && avs.Count > 0)
  665. ret.AddRange(avs);
  666. return ret;
  667. case ScriptBaseClass.LINK_THIS:
  668. return new List<ISceneEntity>() { part };
  669. default:
  670. if (linkType < 0)
  671. return new List<ISceneEntity>();
  672. ISceneEntity target = GetLinkEntity(part, linkType);
  673. if (target == null)
  674. return new List<ISceneEntity>();
  675. return new List<ISceneEntity>() { target };
  676. }
  677. }
  678. //These are the implementations of the various ll-functions used by the LSL scripts.
  679. public LSL_Float llSin(double f)
  680. {
  681. m_host.AddScriptLPS(1);
  682. return (double)Math.Sin(f);
  683. }
  684. public LSL_Float llCos(double f)
  685. {
  686. m_host.AddScriptLPS(1);
  687. return (double)Math.Cos(f);
  688. }
  689. public LSL_Float llTan(double f)
  690. {
  691. m_host.AddScriptLPS(1);
  692. return (double)Math.Tan(f);
  693. }
  694. public LSL_Float llAtan2(double x, double y)
  695. {
  696. m_host.AddScriptLPS(1);
  697. return (double)Math.Atan2(x, y);
  698. }
  699. public LSL_Float llSqrt(double f)
  700. {
  701. m_host.AddScriptLPS(1);
  702. return (double)Math.Sqrt(f);
  703. }
  704. public LSL_Float llPow(double fbase, double fexponent)
  705. {
  706. m_host.AddScriptLPS(1);
  707. return (double)Math.Pow(fbase, fexponent);
  708. }
  709. public LSL_Integer llAbs(int i)
  710. {
  711. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  712. m_host.AddScriptLPS(1);
  713. if (i == Int32.MinValue)
  714. return i;
  715. else
  716. return (int)Math.Abs(i);
  717. }
  718. public LSL_Float llFabs(double f)
  719. {
  720. m_host.AddScriptLPS(1);
  721. return (double)Math.Abs(f);
  722. }
  723. public LSL_Float llFrand(double mag)
  724. {
  725. m_host.AddScriptLPS(1);
  726. lock (Util.RandomClass)
  727. {
  728. return Util.RandomClass.NextDouble() * mag;
  729. }
  730. }
  731. public LSL_Integer llFloor(double f)
  732. {
  733. m_host.AddScriptLPS(1);
  734. return (int)Math.Floor(f);
  735. }
  736. public LSL_Integer llCeil(double f)
  737. {
  738. m_host.AddScriptLPS(1);
  739. return (int)Math.Ceiling(f);
  740. }
  741. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  742. public LSL_Integer llRound(double f)
  743. {
  744. m_host.AddScriptLPS(1);
  745. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  746. }
  747. //This next group are vector operations involving squaring and square root. ckrinke
  748. public LSL_Float llVecMag(LSL_Vector v)
  749. {
  750. m_host.AddScriptLPS(1);
  751. return LSL_Vector.Mag(v);
  752. }
  753. public LSL_Vector llVecNorm(LSL_Vector v)
  754. {
  755. m_host.AddScriptLPS(1);
  756. return LSL_Vector.Norm(v);
  757. }
  758. private double VecDist(LSL_Vector a, LSL_Vector b)
  759. {
  760. double dx = a.x - b.x;
  761. double dy = a.y - b.y;
  762. double dz = a.z - b.z;
  763. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  764. }
  765. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  766. {
  767. m_host.AddScriptLPS(1);
  768. return VecDist(a, b);
  769. }
  770. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  771. // Utility function for llRot2Euler
  772. public LSL_Vector llRot2Euler(LSL_Rotation q1)
  773. {
  774. m_host.AddScriptLPS(1);
  775. LSL_Vector eul = new LSL_Vector();
  776. double sqw = q1.s*q1.s;
  777. double sqx = q1.x*q1.x;
  778. double sqy = q1.z*q1.z;
  779. double sqz = q1.y*q1.y;
  780. double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  781. double test = q1.x*q1.z + q1.y*q1.s;
  782. if (test > 0.4999*unit) { // singularity at north pole
  783. eul.z = 2 * Math.Atan2(q1.x,q1.s);
  784. eul.y = Math.PI/2;
  785. eul.x = 0;
  786. return eul;
  787. }
  788. if (test < -0.4999*unit) { // singularity at south 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. eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
  795. eul.y = Math.Asin(2*test/unit);
  796. eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
  797. return eul;
  798. }
  799. /* From wiki:
  800. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  801. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  802. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  803. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  804. */
  805. /* How we arrived at this llEuler2Rot
  806. *
  807. * Experiment in SL to determine conventions:
  808. * llEuler2Rot(<PI,0,0>)=<1,0,0,0>
  809. * llEuler2Rot(<0,PI,0>)=<0,1,0,0>
  810. * llEuler2Rot(<0,0,PI>)=<0,0,1,0>
  811. *
  812. * Important facts about Quaternions
  813. * - multiplication is non-commutative (a*b != b*a)
  814. * - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
  815. *
  816. * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
  817. * Qx = c1+i*s1
  818. * Qy = c2+j*s2;
  819. * Qz = c3+k*s3;
  820. *
  821. * Rotations applied in order (from above) Z, Y, X
  822. * Q = (Qz * Qy) * Qx
  823. * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
  824. * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
  825. * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
  826. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3+ik*s1*c2*s3+jk*c1*s2*s3+kk*s1*s2*s3
  827. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3 -j*s1*c2*s3 +i*c1*s2*s3 -s1*s2*s3
  828. * regroup: x=i*(s1*c2*c3+c1*s2*s3)
  829. * y=j*(c1*s2*c3-s1*c2*s3)
  830. * z=k*(s1*s2*c3+c1*c2*s3)
  831. * s= c1*c2*c3-s1*s2*s3
  832. *
  833. * This implementation agrees with the functions found here:
  834. * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
  835. * And with the results in SL.
  836. *
  837. * It's also possible to calculate llEuler2Rot by direct multiplication of
  838. * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
  839. * from the wiki).
  840. * Apparently in some cases this is better from a numerical precision perspective?
  841. */
  842. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  843. {
  844. m_host.AddScriptLPS(1);
  845. double x,y,z,s;
  846. v.x *= 0.5;
  847. v.y *= 0.5;
  848. v.z *= 0.5;
  849. double c1 = Math.Cos(v.x);
  850. double c2 = Math.Cos(v.y);
  851. double c1c2 = c1 * c2;
  852. double s1 = Math.Sin(v.x);
  853. double s2 = Math.Sin(v.y);
  854. double s1s2 = s1 * s2;
  855. double c1s2 = c1 * s2;
  856. double s1c2 = s1 * c2;
  857. double c3 = Math.Cos(v.z);
  858. double s3 = Math.Sin(v.z);
  859. x = s1c2 * c3 + c1s2 * s3;
  860. y = c1s2 * c3 - s1c2 * s3;
  861. z = s1s2 * c3 + c1c2 * s3;
  862. s = c1c2 * c3 - s1s2 * s3;
  863. return new LSL_Rotation(x, y, z, s);
  864. }
  865. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  866. {
  867. m_host.AddScriptLPS(1);
  868. double s;
  869. double tr = fwd.x + left.y + up.z + 1.0;
  870. if (tr >= 1.0)
  871. {
  872. s = 0.5 / Math.Sqrt(tr);
  873. return new LSL_Rotation(
  874. (left.z - up.y) * s,
  875. (up.x - fwd.z) * s,
  876. (fwd.y - left.x) * s,
  877. 0.25 / s);
  878. }
  879. else
  880. {
  881. double max = (left.y > up.z) ? left.y : up.z;
  882. if (max < fwd.x)
  883. {
  884. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  885. double x = s * 0.5;
  886. s = 0.5 / s;
  887. return new LSL_Rotation(
  888. x,
  889. (fwd.y + left.x) * s,
  890. (up.x + fwd.z) * s,
  891. (left.z - up.y) * s);
  892. }
  893. else if (max == left.y)
  894. {
  895. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  896. double y = s * 0.5;
  897. s = 0.5 / s;
  898. return new LSL_Rotation(
  899. (fwd.y + left.x) * s,
  900. y,
  901. (left.z + up.y) * s,
  902. (up.x - fwd.z) * s);
  903. }
  904. else
  905. {
  906. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  907. double z = s * 0.5;
  908. s = 0.5 / s;
  909. return new LSL_Rotation(
  910. (up.x + fwd.z) * s,
  911. (left.z + up.y) * s,
  912. z,
  913. (fwd.y - left.x) * s);
  914. }
  915. }
  916. }
  917. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  918. {
  919. m_host.AddScriptLPS(1);
  920. double x, y, z, m;
  921. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  922. // m is always greater than zero
  923. // if m is not equal to 1 then Rotation needs to be normalized
  924. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  925. {
  926. m = 1.0 / Math.Sqrt(m);
  927. r.x *= m;
  928. r.y *= m;
  929. r.z *= m;
  930. r.s *= m;
  931. }
  932. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  933. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  934. y = 2 * (r.x * r.y + r.z * r.s);
  935. z = 2 * (r.x * r.z - r.y * r.s);
  936. return (new LSL_Vector(x, y, z));
  937. }
  938. public LSL_Vector llRot2Left(LSL_Rotation r)
  939. {
  940. m_host.AddScriptLPS(1);
  941. double x, y, z, m;
  942. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  943. // m is always greater than zero
  944. // if m is not equal to 1 then Rotation needs to be normalized
  945. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  946. {
  947. m = 1.0 / Math.Sqrt(m);
  948. r.x *= m;
  949. r.y *= m;
  950. r.z *= m;
  951. r.s *= m;
  952. }
  953. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  954. x = 2 * (r.x * r.y - r.z * r.s);
  955. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  956. z = 2 * (r.x * r.s + r.y * r.z);
  957. return (new LSL_Vector(x, y, z));
  958. }
  959. public LSL_Vector llRot2Up(LSL_Rotation r)
  960. {
  961. m_host.AddScriptLPS(1);
  962. double x, y, z, m;
  963. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  964. // m is always greater than zero
  965. // if m is not equal to 1 then Rotation needs to be normalized
  966. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  967. {
  968. m = 1.0 / Math.Sqrt(m);
  969. r.x *= m;
  970. r.y *= m;
  971. r.z *= m;
  972. r.s *= m;
  973. }
  974. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  975. x = 2 * (r.x * r.z + r.y * r.s);
  976. y = 2 * (-r.x * r.s + r.y * r.z);
  977. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  978. return (new LSL_Vector(x, y, z));
  979. }
  980. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  981. {
  982. //A and B should both be normalized
  983. m_host.AddScriptLPS(1);
  984. /* This method is more accurate than the SL one, and thus causes problems
  985. for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
  986. double dotProduct = LSL_Vector.Dot(a, b);
  987. LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
  988. double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
  989. double angle = Math.Acos(dotProduct / magProduct);
  990. LSL_Vector axis = LSL_Vector.Norm(crossProduct);
  991. double s = Math.Sin(angle / 2);
  992. double x = axis.x * s;
  993. double y = axis.y * s;
  994. double z = axis.z * s;
  995. double w = Math.Cos(angle / 2);
  996. if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
  997. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  998. return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
  999. */
  1000. // This method mimics the 180 errors found in SL
  1001. // See www.euclideanspace.com... angleBetween
  1002. LSL_Vector vec_a = a;
  1003. LSL_Vector vec_b = b;
  1004. // Eliminate zero length
  1005. LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
  1006. LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
  1007. if (vec_a_mag < 0.00001 ||
  1008. vec_b_mag < 0.00001)
  1009. {
  1010. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  1011. }
  1012. // Normalize
  1013. vec_a = llVecNorm(vec_a);
  1014. vec_b = llVecNorm(vec_b);
  1015. // Calculate axis and rotation angle
  1016. LSL_Vector axis = vec_a % vec_b;
  1017. LSL_Float cos_theta = vec_a * vec_b;
  1018. // Check if parallel
  1019. if (cos_theta > 0.99999)
  1020. {
  1021. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  1022. }
  1023. // Check if anti-parallel
  1024. else if (cos_theta < -0.99999)
  1025. {
  1026. LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
  1027. if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
  1028. return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
  1029. }
  1030. else // other rotation
  1031. {
  1032. LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
  1033. axis = llVecNorm(axis);
  1034. double x, y, z, s, t;
  1035. s = Math.Cos(theta);
  1036. t = Math.Sin(theta);
  1037. x = axis.x * t;
  1038. y = axis.y * t;
  1039. z = axis.z * t;
  1040. return new LSL_Rotation(x,y,z,s);
  1041. }
  1042. }
  1043. public void llWhisper(int channelID, string text)
  1044. {
  1045. m_host.AddScriptLPS(1);
  1046. if (text.Length > 1023)
  1047. text = text.Substring(0, 1023);
  1048. World.SimChat(Utils.StringToBytes(text),
  1049. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1050. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1051. if (wComm != null)
  1052. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  1053. }
  1054. private void CheckSayShoutTime()
  1055. {
  1056. DateTime now = DateTime.UtcNow;
  1057. if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
  1058. {
  1059. m_lastSayShoutCheck = now;
  1060. m_SayShoutCount = 0;
  1061. }
  1062. else
  1063. m_SayShoutCount++;
  1064. }
  1065. public void llSay(int channelID, string text)
  1066. {
  1067. m_host.AddScriptLPS(1);
  1068. if (channelID == 0)
  1069. // m_SayShoutCount++;
  1070. CheckSayShoutTime();
  1071. if (m_SayShoutCount >= 11)
  1072. ScriptSleep(2000);
  1073. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  1074. {
  1075. Console.WriteLine(text);
  1076. }
  1077. else
  1078. {
  1079. if (text.Length > 1023)
  1080. text = text.Substring(0, 1023);
  1081. World.SimChat(Utils.StringToBytes(text),
  1082. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1083. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1084. if (wComm != null)
  1085. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  1086. }
  1087. }
  1088. public void llShout(int channelID, string text)
  1089. {
  1090. m_host.AddScriptLPS(1);
  1091. if (channelID == 0)
  1092. // m_SayShoutCount++;
  1093. CheckSayShoutTime();
  1094. if (m_SayShoutCount >= 11)
  1095. ScriptSleep(2000);
  1096. if (text.Length > 1023)
  1097. text = text.Substring(0, 1023);
  1098. World.SimChat(Utils.StringToBytes(text),
  1099. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1100. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1101. if (wComm != null)
  1102. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  1103. }
  1104. public void llRegionSay(int channelID, string text)
  1105. {
  1106. if (channelID == 0)
  1107. {
  1108. Error("llRegionSay", "Cannot use on channel 0");
  1109. return;
  1110. }
  1111. if (text.Length > 1023)
  1112. text = text.Substring(0, 1023);
  1113. m_host.AddScriptLPS(1);
  1114. // debug channel is also sent to avatars
  1115. if (channelID == ScriptBaseClass.DEBUG_CHANNEL)
  1116. {
  1117. World.SimChat(Utils.StringToBytes(text),
  1118. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1119. }
  1120. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1121. if (wComm != null)
  1122. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  1123. }
  1124. public void llRegionSayTo(string target, int channel, string msg)
  1125. {
  1126. if (msg.Length > 1023)
  1127. msg = msg.Substring(0, 1023);
  1128. m_host.AddScriptLPS(1);
  1129. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  1130. return;
  1131. UUID TargetID;
  1132. UUID.TryParse(target, out TargetID);
  1133. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1134. if (wComm != null)
  1135. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  1136. }
  1137. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  1138. {
  1139. m_host.AddScriptLPS(1);
  1140. UUID keyID;
  1141. UUID.TryParse(ID, out keyID);
  1142. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1143. if (wComm != null)
  1144. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  1145. else
  1146. return -1;
  1147. }
  1148. public void llListenControl(int number, int active)
  1149. {
  1150. m_host.AddScriptLPS(1);
  1151. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1152. if (wComm != null)
  1153. wComm.ListenControl(m_item.ItemID, number, active);
  1154. }
  1155. public void llListenRemove(int number)
  1156. {
  1157. m_host.AddScriptLPS(1);
  1158. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1159. if (wComm != null)
  1160. wComm.ListenRemove(m_item.ItemID, number);
  1161. }
  1162. public void llSensor(string name, string id, int type, double range, double arc)
  1163. {
  1164. m_host.AddScriptLPS(1);
  1165. UUID keyID = UUID.Zero;
  1166. UUID.TryParse(id, out keyID);
  1167. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  1168. }
  1169. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  1170. {
  1171. m_host.AddScriptLPS(1);
  1172. UUID keyID = UUID.Zero;
  1173. UUID.TryParse(id, out keyID);
  1174. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  1175. }
  1176. public void llSensorRemove()
  1177. {
  1178. m_host.AddScriptLPS(1);
  1179. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  1180. }
  1181. public string resolveName(UUID objecUUID)
  1182. {
  1183. // try avatar username surname
  1184. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, objecUUID);
  1185. if (account != null)
  1186. {
  1187. string avatarname = account.Name;
  1188. return avatarname;
  1189. }
  1190. // try an scene object
  1191. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  1192. if (SOP != null)
  1193. {
  1194. string objectname = SOP.Name;
  1195. return objectname;
  1196. }
  1197. EntityBase SensedObject;
  1198. World.Entities.TryGetValue(objecUUID, out SensedObject);
  1199. if (SensedObject == null)
  1200. {
  1201. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  1202. if (groups != null)
  1203. {
  1204. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  1205. if (gr != null)
  1206. return gr.GroupName;
  1207. }
  1208. return String.Empty;
  1209. }
  1210. return SensedObject.Name;
  1211. }
  1212. public LSL_String llDetectedName(int number)
  1213. {
  1214. m_host.AddScriptLPS(1);
  1215. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1216. if (detectedParams == null)
  1217. return String.Empty;
  1218. return detectedParams.Name;
  1219. }
  1220. public LSL_Key llDetectedKey(int number)
  1221. {
  1222. m_host.AddScriptLPS(1);
  1223. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1224. if (detectedParams == null)
  1225. return String.Empty;
  1226. return detectedParams.Key.ToString();
  1227. }
  1228. public LSL_Key llDetectedOwner(int number)
  1229. {
  1230. m_host.AddScriptLPS(1);
  1231. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1232. if (detectedParams == null)
  1233. return String.Empty;
  1234. return detectedParams.Owner.ToString();
  1235. }
  1236. public LSL_Integer llDetectedType(int number)
  1237. {
  1238. m_host.AddScriptLPS(1);
  1239. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1240. if (detectedParams == null)
  1241. return 0;
  1242. return new LSL_Integer(detectedParams.Type);
  1243. }
  1244. public LSL_Vector llDetectedPos(int number)
  1245. {
  1246. m_host.AddScriptLPS(1);
  1247. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1248. if (detectedParams == null)
  1249. return new LSL_Vector();
  1250. return detectedParams.Position;
  1251. }
  1252. public LSL_Vector llDetectedVel(int number)
  1253. {
  1254. m_host.AddScriptLPS(1);
  1255. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1256. if (detectedParams == null)
  1257. return new LSL_Vector();
  1258. return detectedParams.Velocity;
  1259. }
  1260. public LSL_Vector llDetectedGrab(int number)
  1261. {
  1262. m_host.AddScriptLPS(1);
  1263. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1264. if (parms == null)
  1265. return new LSL_Vector(0, 0, 0);
  1266. return parms.OffsetPos;
  1267. }
  1268. public LSL_Rotation llDetectedRot(int number)
  1269. {
  1270. m_host.AddScriptLPS(1);
  1271. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1272. if (detectedParams == null)
  1273. return new LSL_Rotation();
  1274. return detectedParams.Rotation;
  1275. }
  1276. public LSL_Integer llDetectedGroup(int number)
  1277. {
  1278. m_host.AddScriptLPS(1);
  1279. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1280. if (detectedParams == null)
  1281. return new LSL_Integer(0);
  1282. if (m_host.GroupID == detectedParams.Group)
  1283. return new LSL_Integer(1);
  1284. return new LSL_Integer(0);
  1285. }
  1286. public LSL_Integer llDetectedLinkNumber(int number)
  1287. {
  1288. m_host.AddScriptLPS(1);
  1289. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1290. if (parms == null)
  1291. return new LSL_Integer(0);
  1292. return new LSL_Integer(parms.LinkNum);
  1293. }
  1294. /// <summary>
  1295. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1296. /// </summary>
  1297. public LSL_Vector llDetectedTouchBinormal(int index)
  1298. {
  1299. m_host.AddScriptLPS(1);
  1300. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1301. if (detectedParams == null)
  1302. return new LSL_Vector();
  1303. return detectedParams.TouchBinormal;
  1304. }
  1305. /// <summary>
  1306. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1307. /// </summary>
  1308. public LSL_Integer llDetectedTouchFace(int index)
  1309. {
  1310. m_host.AddScriptLPS(1);
  1311. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1312. if (detectedParams == null)
  1313. return new LSL_Integer(-1);
  1314. return new LSL_Integer(detectedParams.TouchFace);
  1315. }
  1316. /// <summary>
  1317. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1318. /// </summary>
  1319. public LSL_Vector llDetectedTouchNormal(int index)
  1320. {
  1321. m_host.AddScriptLPS(1);
  1322. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1323. if (detectedParams == null)
  1324. return new LSL_Vector();
  1325. return detectedParams.TouchNormal;
  1326. }
  1327. /// <summary>
  1328. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1329. /// </summary>
  1330. public LSL_Vector llDetectedTouchPos(int index)
  1331. {
  1332. m_host.AddScriptLPS(1);
  1333. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1334. if (detectedParams == null)
  1335. return new LSL_Vector();
  1336. return detectedParams.TouchPos;
  1337. }
  1338. /// <summary>
  1339. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1340. /// </summary>
  1341. public LSL_Vector llDetectedTouchST(int index)
  1342. {
  1343. m_host.AddScriptLPS(1);
  1344. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1345. if (detectedParams == null)
  1346. return new LSL_Vector(-1.0, -1.0, 0.0);
  1347. return detectedParams.TouchST;
  1348. }
  1349. /// <summary>
  1350. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1351. /// </summary>
  1352. public LSL_Vector llDetectedTouchUV(int index)
  1353. {
  1354. m_host.AddScriptLPS(1);
  1355. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1356. if (detectedParams == null)
  1357. return new LSL_Vector(-1.0, -1.0, 0.0);
  1358. return detectedParams.TouchUV;
  1359. }
  1360. [DebuggerNonUserCode]
  1361. public virtual void llDie()
  1362. {
  1363. m_host.AddScriptLPS(1);
  1364. if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
  1365. }
  1366. public LSL_Float llGround(LSL_Vector offset)
  1367. {
  1368. m_host.AddScriptLPS(1);
  1369. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1370. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1371. LSL_Vector vsn = llGroundNormal(offset);
  1372. // Clamp to valid position
  1373. if (pos.X < 0)
  1374. pos.X = 0;
  1375. else if (pos.X >= World.Heightmap.Width)
  1376. pos.X = World.Heightmap.Width - 1;
  1377. if (pos.Y < 0)
  1378. pos.Y = 0;
  1379. else if (pos.Y >= World.Heightmap.Height)
  1380. pos.Y = World.Heightmap.Height - 1;
  1381. //Get the height for the integer coordinates from the Heightmap
  1382. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1383. //Calculate the difference between the actual coordinates and the integer coordinates
  1384. float xdiff = pos.X - (float)((int)pos.X);
  1385. float ydiff = pos.Y - (float)((int)pos.Y);
  1386. //Use the equation of the tangent plane to adjust the height to account for slope
  1387. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1388. }
  1389. public LSL_Float llCloud(LSL_Vector offset)
  1390. {
  1391. m_host.AddScriptLPS(1);
  1392. float cloudCover = 0f;
  1393. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1394. if (module != null)
  1395. {
  1396. Vector3 pos = m_host.GetWorldPosition();
  1397. int x = (int)(pos.X + offset.x);
  1398. int y = (int)(pos.Y + offset.y);
  1399. cloudCover = module.CloudCover(x, y, 0);
  1400. }
  1401. return cloudCover;
  1402. }
  1403. public LSL_Vector llWind(LSL_Vector offset)
  1404. {
  1405. m_host.AddScriptLPS(1);
  1406. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1407. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1408. if (module != null)
  1409. {
  1410. Vector3 pos = m_host.GetWorldPosition();
  1411. int x = (int)(pos.X + offset.x);
  1412. int y = (int)(pos.Y + offset.y);
  1413. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1414. wind.x = windSpeed.X;
  1415. wind.y = windSpeed.Y;
  1416. }
  1417. return wind;
  1418. }
  1419. public void llSetStatus(int status, int value)
  1420. {
  1421. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  1422. return;
  1423. m_host.AddScriptLPS(1);
  1424. int statusrotationaxis = 0;
  1425. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1426. {
  1427. if (value != 0)
  1428. {
  1429. SceneObjectGroup group = m_host.ParentGroup;
  1430. bool allow = true;
  1431. int maxprims = World.m_linksetPhysCapacity;
  1432. bool checkShape = (maxprims > 0 && group.PrimCount > maxprims);
  1433. foreach (SceneObjectPart part in group.Parts)
  1434. {
  1435. if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  1436. continue;
  1437. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1438. {
  1439. allow = false;
  1440. break;
  1441. }
  1442. if (checkShape)
  1443. {
  1444. if (--maxprims < 0)
  1445. {
  1446. allow = false;
  1447. break;
  1448. }
  1449. }
  1450. }
  1451. if (!allow)
  1452. return;
  1453. if (m_host.ParentGroup.RootPart.PhysActor != null &&
  1454. m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
  1455. return;
  1456. m_host.ScriptSetPhysicsStatus(true);
  1457. }
  1458. else
  1459. {
  1460. m_host.ScriptSetPhysicsStatus(false);
  1461. }
  1462. }
  1463. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1464. {
  1465. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1466. }
  1467. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1468. {
  1469. m_host.AddFlag(PrimFlags.CastShadows);
  1470. }
  1471. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1472. {
  1473. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1474. }
  1475. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1476. {
  1477. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1478. }
  1479. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1480. {
  1481. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1482. }
  1483. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1484. m_host.BlockGrab = value != 0;
  1485. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1486. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1487. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1488. {
  1489. if (value != 0)
  1490. m_host.SetDieAtEdge(true);
  1491. else
  1492. m_host.SetDieAtEdge(false);
  1493. }
  1494. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1495. {
  1496. if (value != 0)
  1497. m_host.SetReturnAtEdge(true);
  1498. else
  1499. m_host.SetReturnAtEdge(false);
  1500. }
  1501. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1502. {
  1503. if (value != 0)
  1504. m_host.SetStatusSandbox(true);
  1505. else
  1506. m_host.SetStatusSandbox(false);
  1507. }
  1508. if (statusrotationaxis != 0)
  1509. {
  1510. m_host.SetAxisRotation(statusrotationaxis, value);
  1511. }
  1512. }
  1513. private bool IsPhysical()
  1514. {
  1515. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1516. }
  1517. public LSL_Integer llGetStatus(int status)
  1518. {
  1519. m_host.AddScriptLPS(1);
  1520. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1521. switch (status)
  1522. {
  1523. case ScriptBaseClass.STATUS_PHYSICS:
  1524. return IsPhysical() ? 1 : 0;
  1525. case ScriptBaseClass.STATUS_PHANTOM:
  1526. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1527. {
  1528. return 1;
  1529. }
  1530. return 0;
  1531. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1532. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1533. {
  1534. return 1;
  1535. }
  1536. return 0;
  1537. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1538. return m_host.BlockGrab ? 1 : 0;
  1539. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1540. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1541. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1542. if (m_host.GetDieAtEdge())
  1543. return 1;
  1544. else
  1545. return 0;
  1546. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1547. if (m_host.GetReturnAtEdge())
  1548. return 1;
  1549. else
  1550. return 0;
  1551. case ScriptBaseClass.STATUS_ROTATE_X:
  1552. // if (m_host.GetAxisRotation(2) != 0)
  1553. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1554. return 1;
  1555. else
  1556. return 0;
  1557. case ScriptBaseClass.STATUS_ROTATE_Y:
  1558. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1559. return 1;
  1560. else
  1561. return 0;
  1562. case ScriptBaseClass.STATUS_ROTATE_Z:
  1563. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1564. return 1;
  1565. else
  1566. return 0;
  1567. case ScriptBaseClass.STATUS_SANDBOX:
  1568. if (m_host.GetStatusSandbox())
  1569. return 1;
  1570. else
  1571. return 0;
  1572. }
  1573. return 0;
  1574. }
  1575. public LSL_Integer llScaleByFactor(double scaling_factor)
  1576. {
  1577. m_host.AddScriptLPS(1);
  1578. SceneObjectGroup group = m_host.ParentGroup;
  1579. if(scaling_factor < 1e-6)
  1580. return ScriptBaseClass.FALSE;
  1581. if(scaling_factor > 1e6)
  1582. return ScriptBaseClass.FALSE;
  1583. if (group == null || group.IsDeleted || group.inTransit)
  1584. return ScriptBaseClass.FALSE;
  1585. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  1586. return ScriptBaseClass.FALSE;
  1587. if (group.RootPart.KeyframeMotion != null)
  1588. return ScriptBaseClass.FALSE;
  1589. if(group.GroupResize(scaling_factor))
  1590. return ScriptBaseClass.TRUE;
  1591. else
  1592. return ScriptBaseClass.FALSE;
  1593. }
  1594. public LSL_Float llGetMaxScaleFactor()
  1595. {
  1596. m_host.AddScriptLPS(1);
  1597. SceneObjectGroup group = m_host.ParentGroup;
  1598. if (group == null || group.IsDeleted || group.inTransit)
  1599. return 1.0f;
  1600. return (LSL_Float)group.GetMaxGroupResizeScale();
  1601. }
  1602. public LSL_Float llGetMinScaleFactor()
  1603. {
  1604. m_host.AddScriptLPS(1);
  1605. SceneObjectGroup group = m_host.ParentGroup;
  1606. if (group == null || group.IsDeleted || group.inTransit)
  1607. return 1.0f;
  1608. return (LSL_Float)group.GetMinGroupResizeScale();
  1609. }
  1610. public void llSetScale(LSL_Vector scale)
  1611. {
  1612. m_host.AddScriptLPS(1);
  1613. SetScale(m_host, scale);
  1614. }
  1615. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1616. {
  1617. // TODO: this needs to trigger a persistance save as well
  1618. if (part == null || part.ParentGroup.IsDeleted)
  1619. return;
  1620. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1621. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1622. if (pa != null && pa.IsPhysical)
  1623. {
  1624. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1625. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1626. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1627. }
  1628. else
  1629. {
  1630. // If not physical, then we clamp the scale to the non-physical min/max
  1631. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1632. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1633. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1634. }
  1635. Vector3 tmp = part.Scale;
  1636. tmp.X = (float)scale.x;
  1637. tmp.Y = (float)scale.y;
  1638. tmp.Z = (float)scale.z;
  1639. part.Scale = tmp;
  1640. part.SendFullUpdateToAllClients();
  1641. }
  1642. public LSL_Vector llGetScale()
  1643. {
  1644. m_host.AddScriptLPS(1);
  1645. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1646. }
  1647. public void llSetClickAction(int action)
  1648. {
  1649. m_host.AddScriptLPS(1);
  1650. m_host.ClickAction = (byte)action;
  1651. m_host.ParentGroup.HasGroupChanged = true;
  1652. m_host.ScheduleFullUpdate();
  1653. return;
  1654. }
  1655. public void llSetColor(LSL_Vector color, int face)
  1656. {
  1657. m_host.AddScriptLPS(1);
  1658. SetColor(m_host, color, face);
  1659. }
  1660. protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
  1661. {
  1662. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1663. return;
  1664. m_host.SetFaceColorAlpha(face, color, null);
  1665. }
  1666. public void llSetContentType(LSL_Key reqid, LSL_Integer type)
  1667. {
  1668. m_host.AddScriptLPS(1);
  1669. if (m_UrlModule == null)
  1670. return;
  1671. UUID id;
  1672. if(!UUID.TryParse(reqid, out id))
  1673. return;
  1674. // Make sure the content type is text/plain to start with
  1675. m_UrlModule.HttpContentType(id, "text/plain");
  1676. // Is the object owner online and in the region
  1677. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1678. if (agent == null || agent.IsChildAgent || agent.IsDeleted)
  1679. return; // Fail if the owner is not in the same region
  1680. // Is it the embeded browser?
  1681. string userAgent = m_UrlModule.GetHttpHeader(id, "user-agent");
  1682. if (userAgent.IndexOf("SecondLife") < 0)
  1683. return; // Not the embedded browser. Is this check good enough?
  1684. // Use the IP address of the client and check against the request
  1685. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1686. // as the owner is in the region. Same as SL!
  1687. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1688. if (string.IsNullOrEmpty(logonFromIPAddress))
  1689. return;
  1690. string requestFromIPAddress = m_UrlModule.GetHttpHeader(id, "x-remote-ip");
  1691. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1692. if (requestFromIPAddress == null)
  1693. return;
  1694. requestFromIPAddress = requestFromIPAddress.Trim();
  1695. // If the request isnt from the same IP address then the request cannot be from the owner
  1696. if (!requestFromIPAddress.Equals(logonFromIPAddress))
  1697. return;
  1698. switch (type)
  1699. {
  1700. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1701. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1702. break;
  1703. case ScriptBaseClass.CONTENT_TYPE_XML:
  1704. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1705. break;
  1706. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1707. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1708. break;
  1709. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1710. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1711. break;
  1712. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1713. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1714. break;
  1715. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1716. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1717. break;
  1718. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1719. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1720. break;
  1721. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1722. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1723. break;
  1724. default:
  1725. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1726. break;
  1727. }
  1728. }
  1729. public void SetTexGen(SceneObjectPart part, int face,int style)
  1730. {
  1731. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1732. return;
  1733. Primitive.TextureEntry tex = part.Shape.Textures;
  1734. MappingType textype;
  1735. textype = MappingType.Default;
  1736. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1737. textype = MappingType.Planar;
  1738. int nsides = GetNumberOfSides(part);
  1739. if (face >= 0 && face < nsides)
  1740. {
  1741. tex.CreateFace((uint) face);
  1742. tex.FaceTextures[face].TexMapType = textype;
  1743. part.UpdateTextureEntry(tex);
  1744. return;
  1745. }
  1746. else if (face == ScriptBaseClass.ALL_SIDES)
  1747. {
  1748. for (uint i = 0; i < nsides; i++)
  1749. {
  1750. if (tex.FaceTextures[i] != null)
  1751. {
  1752. tex.FaceTextures[i].TexMapType = textype;
  1753. }
  1754. }
  1755. tex.DefaultTexture.TexMapType = textype;
  1756. part.UpdateTextureEntry(tex);
  1757. return;
  1758. }
  1759. }
  1760. public void SetGlow(SceneObjectPart part, int face, float glow)
  1761. {
  1762. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1763. return;
  1764. Primitive.TextureEntry tex = part.Shape.Textures;
  1765. int nsides = GetNumberOfSides(part);
  1766. if (face >= 0 && face < nsides)
  1767. {
  1768. tex.CreateFace((uint) face);
  1769. tex.FaceTextures[face].Glow = glow;
  1770. part.UpdateTextureEntry(tex);
  1771. return;
  1772. }
  1773. else if (face == ScriptBaseClass.ALL_SIDES)
  1774. {
  1775. for (uint i = 0; i < nsides; i++)
  1776. {
  1777. if (tex.FaceTextures[i] != null)
  1778. {
  1779. tex.FaceTextures[i].Glow = glow;
  1780. }
  1781. }
  1782. tex.DefaultTexture.Glow = glow;
  1783. part.UpdateTextureEntry(tex);
  1784. return;
  1785. }
  1786. }
  1787. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1788. {
  1789. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1790. return;
  1791. Shininess sval = new Shininess();
  1792. switch (shiny)
  1793. {
  1794. case 0:
  1795. sval = Shininess.None;
  1796. break;
  1797. case 1:
  1798. sval = Shininess.Low;
  1799. break;
  1800. case 2:
  1801. sval = Shininess.Medium;
  1802. break;
  1803. case 3:
  1804. sval = Shininess.High;
  1805. break;
  1806. default:
  1807. sval = Shininess.None;
  1808. break;
  1809. }
  1810. int nsides = GetNumberOfSides(part);
  1811. Primitive.TextureEntry tex = part.Shape.Textures;
  1812. if (face >= 0 && face < nsides)
  1813. {
  1814. tex.CreateFace((uint) face);
  1815. tex.FaceTextures[face].Shiny = sval;
  1816. tex.FaceTextures[face].Bump = bump;
  1817. part.UpdateTextureEntry(tex);
  1818. return;
  1819. }
  1820. else if (face == ScriptBaseClass.ALL_SIDES)
  1821. {
  1822. for (uint i = 0; i < nsides; i++)
  1823. {
  1824. if (tex.FaceTextures[i] != null)
  1825. {
  1826. tex.FaceTextures[i].Shiny = sval;
  1827. tex.FaceTextures[i].Bump = bump;
  1828. }
  1829. }
  1830. tex.DefaultTexture.Shiny = sval;
  1831. tex.DefaultTexture.Bump = bump;
  1832. part.UpdateTextureEntry(tex);
  1833. return;
  1834. }
  1835. }
  1836. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1837. {
  1838. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1839. return;
  1840. int nsides = GetNumberOfSides(part);
  1841. Primitive.TextureEntry tex = part.Shape.Textures;
  1842. if (face >= 0 && face < nsides)
  1843. {
  1844. tex.CreateFace((uint) face);
  1845. tex.FaceTextures[face].Fullbright = bright;
  1846. part.UpdateTextureEntry(tex);
  1847. return;
  1848. }
  1849. else if (face == ScriptBaseClass.ALL_SIDES)
  1850. {
  1851. for (uint i = 0; i < nsides; i++)
  1852. {
  1853. if (tex.FaceTextures[i] != null)
  1854. {
  1855. tex.FaceTextures[i].Fullbright = bright;
  1856. }
  1857. }
  1858. tex.DefaultTexture.Fullbright = bright;
  1859. part.UpdateTextureEntry(tex);
  1860. return;
  1861. }
  1862. }
  1863. public LSL_Float llGetAlpha(int face)
  1864. {
  1865. m_host.AddScriptLPS(1);
  1866. return GetAlpha(m_host, face);
  1867. }
  1868. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1869. {
  1870. Primitive.TextureEntry tex = part.Shape.Textures;
  1871. int nsides = GetNumberOfSides(part);
  1872. if (face == ScriptBaseClass.ALL_SIDES)
  1873. {
  1874. int i;
  1875. double sum = 0.0;
  1876. for (i = 0 ; i < nsides; i++)
  1877. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1878. return sum;
  1879. }
  1880. if (face >= 0 && face < nsides)
  1881. {
  1882. return (double)tex.GetFace((uint)face).RGBA.A;
  1883. }
  1884. return 0.0;
  1885. }
  1886. public void llSetAlpha(double alpha, int face)
  1887. {
  1888. m_host.AddScriptLPS(1);
  1889. SetAlpha(m_host, alpha, face);
  1890. }
  1891. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1892. {
  1893. m_host.AddScriptLPS(1);
  1894. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1895. if (parts.Count > 0)
  1896. {
  1897. try
  1898. {
  1899. foreach (SceneObjectPart part in parts)
  1900. SetAlpha(part, alpha, face);
  1901. }
  1902. finally { }
  1903. }
  1904. }
  1905. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1906. {
  1907. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1908. return;
  1909. Primitive.TextureEntry tex = part.Shape.Textures;
  1910. int nsides = GetNumberOfSides(part);
  1911. Color4 texcolor;
  1912. if (face >= 0 && face < nsides)
  1913. {
  1914. texcolor = tex.CreateFace((uint)face).RGBA;
  1915. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1916. tex.FaceTextures[face].RGBA = texcolor;
  1917. part.UpdateTextureEntry(tex);
  1918. return;
  1919. }
  1920. else if (face == ScriptBaseClass.ALL_SIDES)
  1921. {
  1922. for (int i = 0; i < nsides; i++)
  1923. {
  1924. if (tex.FaceTextures[i] != null)
  1925. {
  1926. texcolor = tex.FaceTextures[i].RGBA;
  1927. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1928. tex.FaceTextures[i].RGBA = texcolor;
  1929. }
  1930. }
  1931. // In some cases, the default texture can be null, eg when every face
  1932. // has a unique texture
  1933. if (tex.DefaultTexture != null)
  1934. {
  1935. texcolor = tex.DefaultTexture.RGBA;
  1936. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1937. tex.DefaultTexture.RGBA = texcolor;
  1938. }
  1939. part.UpdateTextureEntry(tex);
  1940. return;
  1941. }
  1942. }
  1943. /// <summary>
  1944. /// Set flexi parameters of a part.
  1945. ///
  1946. /// FIXME: Much of this code should probably be within the part itself.
  1947. /// </summary>
  1948. /// <param name="part"></param>
  1949. /// <param name="flexi"></param>
  1950. /// <param name="softness"></param>
  1951. /// <param name="gravity"></param>
  1952. /// <param name="friction"></param>
  1953. /// <param name="wind"></param>
  1954. /// <param name="tension"></param>
  1955. /// <param name="Force"></param>
  1956. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1957. float wind, float tension, LSL_Vector Force)
  1958. {
  1959. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1960. return;
  1961. if (flexi)
  1962. {
  1963. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1964. // work once the prim is already flexi
  1965. part.Shape.FlexiSoftness = softness;
  1966. part.Shape.FlexiGravity = gravity;
  1967. part.Shape.FlexiDrag = friction;
  1968. part.Shape.FlexiWind = wind;
  1969. part.Shape.FlexiTension = tension;
  1970. part.Shape.FlexiForceX = (float)Force.x;
  1971. part.Shape.FlexiForceY = (float)Force.y;
  1972. part.Shape.FlexiForceZ = (float)Force.z;
  1973. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  1974. }
  1975. else
  1976. {
  1977. // Other values not set, they do not seem to be sent to the viewer
  1978. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  1979. part.Shape.PathCurve = (byte)Extrusion.Straight;
  1980. part.Shape.FlexiEntry = false;
  1981. }
  1982. part.ParentGroup.HasGroupChanged = true;
  1983. part.ScheduleFullUpdate();
  1984. }
  1985. /// <summary>
  1986. /// Set a light point on a part
  1987. /// </summary>
  1988. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1989. ///
  1990. /// <param name="part"></param>
  1991. /// <param name="light"></param>
  1992. /// <param name="color"></param>
  1993. /// <param name="intensity"></param>
  1994. /// <param name="radius"></param>
  1995. /// <param name="falloff"></param>
  1996. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1997. {
  1998. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1999. return;
  2000. if (light)
  2001. {
  2002. part.Shape.LightEntry = true;
  2003. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  2004. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  2005. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  2006. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  2007. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  2008. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  2009. }
  2010. else
  2011. {
  2012. part.Shape.LightEntry = false;
  2013. }
  2014. part.ParentGroup.HasGroupChanged = true;
  2015. part.ScheduleFullUpdate();
  2016. }
  2017. public LSL_Vector llGetColor(int face)
  2018. {
  2019. m_host.AddScriptLPS(1);
  2020. return GetColor(m_host, face);
  2021. }
  2022. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  2023. {
  2024. Primitive.TextureEntry tex = part.Shape.Textures;
  2025. Color4 texcolor;
  2026. LSL_Vector rgb = new LSL_Vector();
  2027. int nsides = GetNumberOfSides(part);
  2028. if (face == ScriptBaseClass.ALL_SIDES)
  2029. {
  2030. int i;
  2031. for (i = 0; i < nsides; i++)
  2032. {
  2033. texcolor = tex.GetFace((uint)i).RGBA;
  2034. rgb.x += texcolor.R;
  2035. rgb.y += texcolor.G;
  2036. rgb.z += texcolor.B;
  2037. }
  2038. float invnsides = 1.0f / (float)nsides;
  2039. rgb.x *= invnsides;
  2040. rgb.y *= invnsides;
  2041. rgb.z *= invnsides;
  2042. return rgb;
  2043. }
  2044. if (face >= 0 && face < nsides)
  2045. {
  2046. texcolor = tex.GetFace((uint)face).RGBA;
  2047. rgb.x = texcolor.R;
  2048. rgb.y = texcolor.G;
  2049. rgb.z = texcolor.B;
  2050. return rgb;
  2051. }
  2052. else
  2053. {
  2054. return new LSL_Vector();
  2055. }
  2056. }
  2057. public void llSetTexture(string texture, int face)
  2058. {
  2059. m_host.AddScriptLPS(1);
  2060. SetTexture(m_host, texture, face);
  2061. ScriptSleep(m_sleepMsOnSetTexture);
  2062. }
  2063. public void llSetLinkTexture(int linknumber, string texture, int face)
  2064. {
  2065. m_host.AddScriptLPS(1);
  2066. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  2067. if (parts.Count > 0)
  2068. {
  2069. try
  2070. {
  2071. foreach (SceneObjectPart part in parts)
  2072. SetTexture(part, texture, face);
  2073. }
  2074. finally { }
  2075. }
  2076. ScriptSleep(m_sleepMsOnSetLinkTexture);
  2077. }
  2078. protected void SetTexture(SceneObjectPart part, string texture, int face)
  2079. {
  2080. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2081. return;
  2082. UUID textureID = new UUID();
  2083. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2084. if (textureID == UUID.Zero)
  2085. {
  2086. if (!UUID.TryParse(texture, out textureID))
  2087. return;
  2088. }
  2089. Primitive.TextureEntry tex = part.Shape.Textures;
  2090. int nsides = GetNumberOfSides(part);
  2091. if (face >= 0 && face < nsides)
  2092. {
  2093. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2094. texface.TextureID = textureID;
  2095. tex.FaceTextures[face] = texface;
  2096. part.UpdateTextureEntry(tex);
  2097. return;
  2098. }
  2099. else if (face == ScriptBaseClass.ALL_SIDES)
  2100. {
  2101. for (uint i = 0; i < nsides; i++)
  2102. {
  2103. if (tex.FaceTextures[i] != null)
  2104. {
  2105. tex.FaceTextures[i].TextureID = textureID;
  2106. }
  2107. }
  2108. tex.DefaultTexture.TextureID = textureID;
  2109. part.UpdateTextureEntry(tex);
  2110. return;
  2111. }
  2112. }
  2113. public void llScaleTexture(double u, double v, int face)
  2114. {
  2115. m_host.AddScriptLPS(1);
  2116. ScaleTexture(m_host, u, v, face);
  2117. ScriptSleep(m_sleepMsOnScaleTexture);
  2118. }
  2119. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  2120. {
  2121. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2122. return;
  2123. Primitive.TextureEntry tex = part.Shape.Textures;
  2124. int nsides = GetNumberOfSides(part);
  2125. if (face >= 0 && face < nsides)
  2126. {
  2127. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2128. texface.RepeatU = (float)u;
  2129. texface.RepeatV = (float)v;
  2130. tex.FaceTextures[face] = texface;
  2131. part.UpdateTextureEntry(tex);
  2132. return;
  2133. }
  2134. if (face == ScriptBaseClass.ALL_SIDES)
  2135. {
  2136. for (int i = 0; i < nsides; i++)
  2137. {
  2138. if (tex.FaceTextures[i] != null)
  2139. {
  2140. tex.FaceTextures[i].RepeatU = (float)u;
  2141. tex.FaceTextures[i].RepeatV = (float)v;
  2142. }
  2143. }
  2144. tex.DefaultTexture.RepeatU = (float)u;
  2145. tex.DefaultTexture.RepeatV = (float)v;
  2146. part.UpdateTextureEntry(tex);
  2147. return;
  2148. }
  2149. }
  2150. public void llOffsetTexture(double u, double v, int face)
  2151. {
  2152. m_host.AddScriptLPS(1);
  2153. OffsetTexture(m_host, u, v, face);
  2154. ScriptSleep(m_sleepMsOnOffsetTexture);
  2155. }
  2156. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  2157. {
  2158. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2159. return;
  2160. Primitive.TextureEntry tex = part.Shape.Textures;
  2161. int nsides = GetNumberOfSides(part);
  2162. if (face >= 0 && face < nsides)
  2163. {
  2164. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2165. texface.OffsetU = (float)u;
  2166. texface.OffsetV = (float)v;
  2167. tex.FaceTextures[face] = texface;
  2168. part.UpdateTextureEntry(tex);
  2169. return;
  2170. }
  2171. if (face == ScriptBaseClass.ALL_SIDES)
  2172. {
  2173. for (int i = 0; i < nsides; i++)
  2174. {
  2175. if (tex.FaceTextures[i] != null)
  2176. {
  2177. tex.FaceTextures[i].OffsetU = (float)u;
  2178. tex.FaceTextures[i].OffsetV = (float)v;
  2179. }
  2180. }
  2181. tex.DefaultTexture.OffsetU = (float)u;
  2182. tex.DefaultTexture.OffsetV = (float)v;
  2183. part.UpdateTextureEntry(tex);
  2184. return;
  2185. }
  2186. }
  2187. public void llRotateTexture(double rotation, int face)
  2188. {
  2189. m_host.AddScriptLPS(1);
  2190. RotateTexture(m_host, rotation, face);
  2191. ScriptSleep(m_sleepMsOnRotateTexture);
  2192. }
  2193. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  2194. {
  2195. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2196. return;
  2197. Primitive.TextureEntry tex = part.Shape.Textures;
  2198. int nsides = GetNumberOfSides(part);
  2199. if (face >= 0 && face < nsides)
  2200. {
  2201. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2202. texface.Rotation = (float)rotation;
  2203. tex.FaceTextures[face] = texface;
  2204. part.UpdateTextureEntry(tex);
  2205. return;
  2206. }
  2207. if (face == ScriptBaseClass.ALL_SIDES)
  2208. {
  2209. for (int i = 0; i < nsides; i++)
  2210. {
  2211. if (tex.FaceTextures[i] != null)
  2212. {
  2213. tex.FaceTextures[i].Rotation = (float)rotation;
  2214. }
  2215. }
  2216. tex.DefaultTexture.Rotation = (float)rotation;
  2217. part.UpdateTextureEntry(tex);
  2218. return;
  2219. }
  2220. }
  2221. public LSL_String llGetTexture(int face)
  2222. {
  2223. m_host.AddScriptLPS(1);
  2224. return GetTexture(m_host, face);
  2225. }
  2226. protected LSL_String GetTexture(SceneObjectPart part, int face)
  2227. {
  2228. Primitive.TextureEntry tex = part.Shape.Textures;
  2229. int nsides = GetNumberOfSides(part);
  2230. if (face == ScriptBaseClass.ALL_SIDES)
  2231. {
  2232. face = 0;
  2233. }
  2234. if (face >= 0 && face < nsides)
  2235. {
  2236. Primitive.TextureEntryFace texface;
  2237. texface = tex.GetFace((uint)face);
  2238. string texture = texface.TextureID.ToString();
  2239. lock (part.TaskInventory)
  2240. {
  2241. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  2242. {
  2243. if (inv.Value.AssetID == texface.TextureID)
  2244. {
  2245. texture = inv.Value.Name.ToString();
  2246. break;
  2247. }
  2248. }
  2249. }
  2250. return texture;
  2251. }
  2252. else
  2253. {
  2254. return UUID.Zero.ToString();
  2255. }
  2256. }
  2257. public void llSetPos(LSL_Vector pos)
  2258. {
  2259. m_host.AddScriptLPS(1);
  2260. SetPos(m_host, pos, true);
  2261. ScriptSleep(m_sleepMsOnSetPos);
  2262. }
  2263. /// <summary>
  2264. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  2265. /// 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.
  2266. /// 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.
  2267. /// </summary>
  2268. /// <param name="pos"></param>
  2269. /// <returns>1 if successful, 0 otherwise.</returns>
  2270. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  2271. {
  2272. m_host.AddScriptLPS(1);
  2273. // BEGIN WORKAROUND
  2274. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  2275. //
  2276. // This workaround is to prevent silent failure of this function.
  2277. // According to the specification on the SL Wiki, providing a position outside of the
  2278. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  2279. {
  2280. return 0;
  2281. }
  2282. // END WORK AROUND
  2283. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  2284. IsPhysical() ||
  2285. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  2286. (
  2287. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  2288. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  2289. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  2290. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  2291. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  2292. )
  2293. )
  2294. {
  2295. return 0;
  2296. }
  2297. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  2298. // 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.
  2299. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  2300. LandData here = World.GetLandData(objectPos);
  2301. LandData there = World.GetLandData(pos);
  2302. // 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.
  2303. bool sameParcel = here.GlobalID == there.GlobalID;
  2304. if (!sameParcel && !World.Permissions.CanRezObject(
  2305. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  2306. {
  2307. return 0;
  2308. }
  2309. SetPos(m_host.ParentGroup.RootPart, pos, false);
  2310. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  2311. }
  2312. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2313. // note linked setpos is capped "differently"
  2314. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  2315. {
  2316. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  2317. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  2318. else
  2319. return end;
  2320. }
  2321. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
  2322. {
  2323. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2324. return fromPos;
  2325. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2326. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2327. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2328. if (part.ParentGroup.RootPart == part)
  2329. {
  2330. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2331. targetPos.z = ground;
  2332. }
  2333. if (adjust)
  2334. return SetPosAdjust(fromPos, targetPos);
  2335. return targetPos;
  2336. }
  2337. /// <summary>
  2338. /// set object position, optionally capping the distance.
  2339. /// </summary>
  2340. /// <param name="part"></param>
  2341. /// <param name="targetPos"></param>
  2342. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  2343. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  2344. {
  2345. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted || part.ParentGroup.inTransit)
  2346. return;
  2347. LSL_Vector currentPos = GetPartLocalPos(part);
  2348. LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
  2349. if (part.ParentGroup.RootPart == part)
  2350. {
  2351. SceneObjectGroup parent = part.ParentGroup;
  2352. if (!parent.IsAttachment && !World.Permissions.CanObjectEntry(parent, false, (Vector3)toPos))
  2353. return;
  2354. parent.UpdateGroupPosition((Vector3)toPos);
  2355. }
  2356. else
  2357. {
  2358. part.OffsetPosition = (Vector3)toPos;
  2359. // SceneObjectGroup parent = part.ParentGroup;
  2360. // parent.HasGroupChanged = true;
  2361. // parent.ScheduleGroupForTerseUpdate();
  2362. part.ScheduleTerseUpdate();
  2363. }
  2364. }
  2365. public LSL_Vector llGetPos()
  2366. {
  2367. m_host.AddScriptLPS(1);
  2368. return m_host.GetWorldPosition();
  2369. }
  2370. public LSL_Vector llGetLocalPos()
  2371. {
  2372. m_host.AddScriptLPS(1);
  2373. return GetPartLocalPos(m_host);
  2374. }
  2375. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  2376. {
  2377. m_host.AddScriptLPS(1);
  2378. Vector3 pos;
  2379. if (!part.IsRoot)
  2380. {
  2381. pos = part.OffsetPosition;
  2382. }
  2383. else
  2384. {
  2385. if (part.ParentGroup.IsAttachment)
  2386. pos = part.AttachedPos;
  2387. else
  2388. pos = part.AbsolutePosition;
  2389. }
  2390. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2391. return new LSL_Vector(pos);
  2392. }
  2393. public void llSetRot(LSL_Rotation rot)
  2394. {
  2395. m_host.AddScriptLPS(1);
  2396. // try to let this work as in SL...
  2397. if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
  2398. {
  2399. // special case: If we are root, rotate complete SOG to new rotation
  2400. SetRot(m_host, rot);
  2401. }
  2402. else
  2403. {
  2404. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2405. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2406. if (rootPart != null) // better safe than sorry
  2407. {
  2408. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2409. }
  2410. }
  2411. ScriptSleep(m_sleepMsOnSetRot);
  2412. }
  2413. public void llSetLocalRot(LSL_Rotation rot)
  2414. {
  2415. m_host.AddScriptLPS(1);
  2416. SetRot(m_host, rot);
  2417. ScriptSleep(m_sleepMsOnSetLocalRot);
  2418. }
  2419. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2420. {
  2421. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2422. return;
  2423. bool isroot = (part == part.ParentGroup.RootPart);
  2424. bool isphys;
  2425. PhysicsActor pa = part.PhysActor;
  2426. // keep using physactor ideia of isphysical
  2427. // it should be SOP ideia of that
  2428. // not much of a issue with ubOde
  2429. if (pa != null && pa.IsPhysical)
  2430. isphys = true;
  2431. else
  2432. isphys = false;
  2433. // SL doesn't let scripts rotate root of physical linksets
  2434. if (isroot && isphys)
  2435. return;
  2436. part.UpdateRotation(rot);
  2437. // Update rotation does not move the object in the physics engine if it's a non physical linkset
  2438. // so do a nasty update of parts positions if is a root part rotation
  2439. if (isroot && pa != null) // with if above implies non physical root part
  2440. {
  2441. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2442. }
  2443. else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
  2444. {
  2445. // List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
  2446. List<ScenePresence> sittingavas = part.ParentGroup.GetSittingAvatars();
  2447. if (sittingavas.Count > 0)
  2448. {
  2449. foreach (ScenePresence av in sittingavas)
  2450. {
  2451. if (isroot || part.LocalId == av.ParentID)
  2452. av.SendTerseUpdateToAllClients();
  2453. }
  2454. }
  2455. }
  2456. }
  2457. /// <summary>
  2458. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2459. /// </summary>
  2460. public LSL_Rotation llGetRot()
  2461. {
  2462. // unlinked or root prim then use llRootRotation
  2463. // see llRootRotaion for references.
  2464. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2465. {
  2466. return llGetRootRotation();
  2467. }
  2468. m_host.AddScriptLPS(1);
  2469. Quaternion q = m_host.GetWorldRotation();
  2470. if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
  2471. {
  2472. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2473. if (avatar != null)
  2474. {
  2475. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2476. q = avatar.CameraRotation * q; // Mouselook
  2477. else
  2478. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2479. }
  2480. }
  2481. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2482. }
  2483. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2484. {
  2485. Quaternion q;
  2486. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2487. {
  2488. if (part.ParentGroup.AttachmentPoint != 0)
  2489. {
  2490. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2491. if (avatar != null)
  2492. {
  2493. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2494. q = avatar.CameraRotation; // Mouselook
  2495. else
  2496. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2497. }
  2498. else
  2499. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2500. }
  2501. else
  2502. q = part.ParentGroup.GroupRotation; // just the group rotation
  2503. return new LSL_Rotation(q);
  2504. }
  2505. q = part.GetWorldRotation();
  2506. if (part.ParentGroup.AttachmentPoint != 0)
  2507. {
  2508. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2509. if (avatar != null)
  2510. {
  2511. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2512. q = avatar.CameraRotation * q; // Mouselook
  2513. else
  2514. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2515. }
  2516. }
  2517. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2518. }
  2519. public LSL_Rotation llGetLocalRot()
  2520. {
  2521. return GetPartLocalRot(m_host);
  2522. }
  2523. private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
  2524. {
  2525. m_host.AddScriptLPS(1);
  2526. Quaternion rot = part.RotationOffset;
  2527. return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
  2528. }
  2529. public void llSetForce(LSL_Vector force, int local)
  2530. {
  2531. m_host.AddScriptLPS(1);
  2532. if (!m_host.ParentGroup.IsDeleted)
  2533. {
  2534. if (local != 0)
  2535. force *= llGetRot();
  2536. m_host.ParentGroup.RootPart.SetForce(force);
  2537. }
  2538. }
  2539. public LSL_Vector llGetForce()
  2540. {
  2541. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2542. m_host.AddScriptLPS(1);
  2543. if (!m_host.ParentGroup.IsDeleted)
  2544. {
  2545. force = m_host.ParentGroup.RootPart.GetForce();
  2546. }
  2547. return force;
  2548. }
  2549. public void llSetVelocity(LSL_Vector vel, int local)
  2550. {
  2551. m_host.AddScriptLPS(1);
  2552. m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
  2553. }
  2554. public void llSetAngularVelocity(LSL_Vector avel, int local)
  2555. {
  2556. m_host.AddScriptLPS(1);
  2557. m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
  2558. }
  2559. public LSL_Integer llTarget(LSL_Vector position, double range)
  2560. {
  2561. m_host.AddScriptLPS(1);
  2562. return m_host.ParentGroup.registerTargetWaypoint(position,
  2563. (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(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, int 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 normlaization 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(string destination, int amount)
  2975. {
  2976. Util.FireAndForget(x =>
  2977. {
  2978. m_host.AddScriptLPS(1);
  2979. if (m_item.PermsGranter == UUID.Zero)
  2980. return;
  2981. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  2982. {
  2983. Error("llGiveMoney", "No permissions to give money");
  2984. return;
  2985. }
  2986. UUID toID = new UUID();
  2987. if (!UUID.TryParse(destination, out toID))
  2988. {
  2989. Error("llGiveMoney", "Bad key in llGiveMoney");
  2990. return;
  2991. }
  2992. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  2993. if (money == null)
  2994. {
  2995. NotImplemented("llGiveMoney");
  2996. return;
  2997. }
  2998. string reason;
  2999. money.ObjectGiveMoney(
  3000. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount,UUID.Zero, out reason);
  3001. }, null, "LSL_Api.llGiveMoney");
  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. 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(string name, string id, int accept)
  3183. {
  3184. m_host.AddScriptLPS(1);
  3185. m_host.CollisionFilter.Clear();
  3186. UUID objectID;
  3187. if (!UUID.TryParse(id, out objectID))
  3188. objectID = UUID.Zero;
  3189. if (objectID == UUID.Zero && name == "")
  3190. return;
  3191. m_host.CollisionFilter.Add(accept,objectID.ToString() + name);
  3192. }
  3193. public void llTakeControls(int controls, int accept, int pass_on)
  3194. {
  3195. if (m_item.PermsGranter != UUID.Zero)
  3196. {
  3197. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3198. if (presence != null)
  3199. {
  3200. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3201. {
  3202. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  3203. }
  3204. }
  3205. }
  3206. m_host.AddScriptLPS(1);
  3207. }
  3208. public void llReleaseControls()
  3209. {
  3210. m_host.AddScriptLPS(1);
  3211. if (m_item.PermsGranter != UUID.Zero)
  3212. {
  3213. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3214. if (presence != null)
  3215. {
  3216. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3217. {
  3218. // Unregister controls from Presence
  3219. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  3220. // Remove Take Control permission.
  3221. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3222. }
  3223. }
  3224. }
  3225. }
  3226. public void llReleaseURL(string url)
  3227. {
  3228. m_host.AddScriptLPS(1);
  3229. if (m_UrlModule != null)
  3230. m_UrlModule.ReleaseURL(url);
  3231. }
  3232. /// <summary>
  3233. /// Attach the object containing this script to the avatar that owns it.
  3234. /// </summary>
  3235. /// <param name='attachmentPoint'>
  3236. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  3237. /// </param>
  3238. /// <returns>true if the attach suceeded, false if it did not</returns>
  3239. public bool AttachToAvatar(int attachmentPoint)
  3240. {
  3241. SceneObjectGroup grp = m_host.ParentGroup;
  3242. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  3243. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3244. if (attachmentsModule != null)
  3245. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  3246. else
  3247. return false;
  3248. }
  3249. /// <summary>
  3250. /// Detach the object containing this script from the avatar it is attached to.
  3251. /// </summary>
  3252. /// <remarks>
  3253. /// Nothing happens if the object is not attached.
  3254. /// </remarks>
  3255. public void DetachFromAvatar()
  3256. {
  3257. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  3258. }
  3259. private void DetachWrapper(object o)
  3260. {
  3261. if (World.AttachmentsModule != null)
  3262. {
  3263. SceneObjectPart host = (SceneObjectPart)o;
  3264. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  3265. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  3266. }
  3267. }
  3268. public void llAttachToAvatar(LSL_Integer attachmentPoint)
  3269. {
  3270. m_host.AddScriptLPS(1);
  3271. if (m_item.PermsGranter != m_host.OwnerID)
  3272. return;
  3273. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3274. AttachToAvatar(attachmentPoint);
  3275. }
  3276. public void llAttachToAvatarTemp(LSL_Integer attachmentPoint)
  3277. {
  3278. IAttachmentsModule attachmentsModule = World.RequestModuleInterface<IAttachmentsModule>();
  3279. if (attachmentsModule == null)
  3280. return;
  3281. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) == 0)
  3282. return;
  3283. SceneObjectGroup grp = m_host.ParentGroup;
  3284. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3285. return;
  3286. ScenePresence target;
  3287. if (!World.TryGetScenePresence(m_item.PermsGranter, out target))
  3288. return;
  3289. if (target.UUID != grp.OwnerID)
  3290. {
  3291. uint effectivePerms = grp.EffectiveOwnerPerms;
  3292. if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
  3293. return;
  3294. grp.SetOwner(target.UUID, target.ControllingClient.ActiveGroupId);
  3295. if (World.Permissions.PropagatePermissions())
  3296. {
  3297. foreach (SceneObjectPart child in grp.Parts)
  3298. {
  3299. child.Inventory.ChangeInventoryOwner(target.UUID);
  3300. child.TriggerScriptChangedEvent(Changed.OWNER);
  3301. child.ApplyNextOwnerPermissions();
  3302. }
  3303. grp.InvalidateEffectivePerms();
  3304. }
  3305. grp.RootPart.ObjectSaleType = 0;
  3306. grp.RootPart.SalePrice = 10;
  3307. grp.HasGroupChanged = true;
  3308. grp.RootPart.SendPropertiesToClient(target.ControllingClient);
  3309. grp.RootPart.ScheduleFullUpdate();
  3310. }
  3311. attachmentsModule.AttachObject(target, grp, (uint)attachmentPoint, false, false, true);
  3312. }
  3313. public void llDetachFromAvatar()
  3314. {
  3315. m_host.AddScriptLPS(1);
  3316. if (m_host.ParentGroup.AttachmentPoint == 0)
  3317. return;
  3318. if (m_item.PermsGranter != m_host.OwnerID)
  3319. return;
  3320. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3321. DetachFromAvatar();
  3322. }
  3323. public void llTakeCamera(string avatar)
  3324. {
  3325. m_host.AddScriptLPS(1);
  3326. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  3327. }
  3328. public void llReleaseCamera(string avatar)
  3329. {
  3330. m_host.AddScriptLPS(1);
  3331. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  3332. }
  3333. public LSL_Key llGetOwner()
  3334. {
  3335. m_host.AddScriptLPS(1);
  3336. return m_host.OwnerID.ToString();
  3337. }
  3338. public void llInstantMessage(string user, string message)
  3339. {
  3340. m_host.AddScriptLPS(1);
  3341. UUID result;
  3342. if (!UUID.TryParse(user, out 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. msg.fromAgentID = new Guid(m_host.OwnerID.ToString()); // fromAgentID.Guid;
  3359. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  3360. msg.imSessionID = new Guid(m_host.UUID.ToString()); // This is the item we're mucking with here
  3361. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  3362. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  3363. if (message != null && message.Length > 1024)
  3364. msg.message = message.Substring(0, 1024);
  3365. else
  3366. msg.message = message;
  3367. msg.dialog = (byte)19; // MessageFromObject
  3368. msg.fromGroup = false;// fromGroup;
  3369. msg.offline = (byte)0; //offline;
  3370. msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
  3371. msg.Position = new Vector3(m_host.AbsolutePosition);
  3372. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  3373. Vector3 pos = m_host.AbsolutePosition;
  3374. msg.binaryBucket
  3375. = Util.StringToBytes256(
  3376. "{0}/{1}/{2}/{3}",
  3377. World.RegionInfo.RegionName,
  3378. (int)Math.Floor(pos.X),
  3379. (int)Math.Floor(pos.Y),
  3380. (int)Math.Floor(pos.Z));
  3381. if (m_TransferModule != null)
  3382. {
  3383. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3384. }
  3385. ScriptSleep(m_sleepMsOnInstantMessage);
  3386. }
  3387. public void llEmail(string address, string subject, string message)
  3388. {
  3389. m_host.AddScriptLPS(1);
  3390. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3391. if (emailModule == null)
  3392. {
  3393. Error("llEmail", "Email module not configured");
  3394. return;
  3395. }
  3396. //Restrict email destination to the avatars registered email address?
  3397. //The restriction only applies if the destination address is not local.
  3398. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  3399. {
  3400. UserAccount account =
  3401. World.UserAccountService.GetUserAccount(
  3402. World.RegionInfo.ScopeID,
  3403. m_host.OwnerID);
  3404. if (account == null)
  3405. {
  3406. Error("llEmail", "Can't find user account for '" + m_host.OwnerID.ToString() + "'");
  3407. return;
  3408. }
  3409. if (String.IsNullOrEmpty(account.Email))
  3410. {
  3411. Error("llEmail", "User account has not registered an email address.");
  3412. return;
  3413. }
  3414. address = account.Email;
  3415. }
  3416. emailModule.SendEmail(m_host.UUID, address, subject, message);
  3417. ScriptSleep(m_sleepMsOnEmail);
  3418. }
  3419. public void llGetNextEmail(string address, string subject)
  3420. {
  3421. m_host.AddScriptLPS(1);
  3422. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3423. if (emailModule == null)
  3424. {
  3425. Error("llGetNextEmail", "Email module not configured");
  3426. return;
  3427. }
  3428. Email email;
  3429. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  3430. if (email == null)
  3431. return;
  3432. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  3433. new EventParams("email",
  3434. new Object[] {
  3435. new LSL_String(email.time),
  3436. new LSL_String(email.sender),
  3437. new LSL_String(email.subject),
  3438. new LSL_String(email.message),
  3439. new LSL_Integer(email.numLeft)},
  3440. new DetectParams[0]));
  3441. }
  3442. public LSL_Key llGetKey()
  3443. {
  3444. m_host.AddScriptLPS(1);
  3445. return m_host.UUID.ToString();
  3446. }
  3447. public LSL_Key llGenerateKey()
  3448. {
  3449. m_host.AddScriptLPS(1);
  3450. return UUID.Random().ToString();
  3451. }
  3452. public void llSetBuoyancy(double buoyancy)
  3453. {
  3454. m_host.AddScriptLPS(1);
  3455. if (!m_host.ParentGroup.IsDeleted)
  3456. {
  3457. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  3458. }
  3459. }
  3460. /// <summary>
  3461. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  3462. /// </summary>
  3463. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  3464. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  3465. /// <param name="tau">Number of seconds over which to reach target</param>
  3466. public void llSetHoverHeight(double height, int water, double tau)
  3467. {
  3468. m_host.AddScriptLPS(1);
  3469. PIDHoverType hoverType = PIDHoverType.Ground;
  3470. if (water != 0)
  3471. {
  3472. hoverType = PIDHoverType.GroundAndWater;
  3473. }
  3474. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  3475. }
  3476. public void llStopHover()
  3477. {
  3478. m_host.AddScriptLPS(1);
  3479. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3480. }
  3481. public void llMinEventDelay(double delay)
  3482. {
  3483. m_host.AddScriptLPS(1);
  3484. try
  3485. {
  3486. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3487. }
  3488. catch (NotImplementedException)
  3489. {
  3490. // Currently not implemented in DotNetEngine only XEngine
  3491. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3492. }
  3493. }
  3494. public void llSoundPreload(string sound)
  3495. {
  3496. m_host.AddScriptLPS(1);
  3497. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3498. }
  3499. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3500. {
  3501. m_host.AddScriptLPS(1);
  3502. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3503. // set the rotation of the object, copy that behavior
  3504. SceneObjectGroup sog = m_host.ParentGroup;
  3505. if(sog == null || sog.IsDeleted)
  3506. return;
  3507. if (strength == 0 || !sog.UsesPhysics || sog.IsAttachment)
  3508. {
  3509. llSetLocalRot(target);
  3510. }
  3511. else
  3512. {
  3513. sog.RotLookAt(target, (float)strength, (float)damping);
  3514. }
  3515. }
  3516. public LSL_Integer llStringLength(string str)
  3517. {
  3518. m_host.AddScriptLPS(1);
  3519. if (str.Length > 0)
  3520. {
  3521. return str.Length;
  3522. }
  3523. else
  3524. {
  3525. return 0;
  3526. }
  3527. }
  3528. public void llStartAnimation(string anim)
  3529. {
  3530. m_host.AddScriptLPS(1);
  3531. if (m_item.PermsGranter == UUID.Zero)
  3532. return;
  3533. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3534. {
  3535. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3536. if (presence != null)
  3537. {
  3538. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3539. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3540. if (animID == UUID.Zero)
  3541. presence.Animator.AddAnimation(anim, m_host.UUID);
  3542. else
  3543. presence.Animator.AddAnimation(animID, m_host.UUID);
  3544. }
  3545. }
  3546. }
  3547. public void llStopAnimation(string anim)
  3548. {
  3549. m_host.AddScriptLPS(1);
  3550. if (m_item.PermsGranter == UUID.Zero)
  3551. return;
  3552. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3553. {
  3554. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3555. if (presence != null)
  3556. {
  3557. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3558. if (animID == UUID.Zero)
  3559. presence.Animator.RemoveAnimation(anim);
  3560. else
  3561. presence.Animator.RemoveAnimation(animID, true);
  3562. }
  3563. }
  3564. }
  3565. public void llStartObjectAnimation(string anim)
  3566. {
  3567. m_host.AddScriptLPS(1);
  3568. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3569. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3570. if (animID == UUID.Zero)
  3571. return;
  3572. m_host.AddAnimation(animID, anim);
  3573. }
  3574. public void llStopObjectAnimation(string anim)
  3575. {
  3576. m_host.AddScriptLPS(1);
  3577. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim, AssetType.Animation);
  3578. if (animID != UUID.Zero)
  3579. m_host.RemoveAnimation(animID);
  3580. }
  3581. public LSL_List llGetObjectAnimationNames()
  3582. {
  3583. m_host.AddScriptLPS(1);
  3584. LSL_List ret = new LSL_List();
  3585. if(m_host.AnimationsNames == null || m_host.AnimationsNames.Count == 0)
  3586. return ret;
  3587. foreach (string name in m_host.AnimationsNames.Values)
  3588. ret.Add(new LSL_String(name));
  3589. return ret;
  3590. }
  3591. public void llPointAt(LSL_Vector pos)
  3592. {
  3593. m_host.AddScriptLPS(1);
  3594. }
  3595. public void llStopPointAt()
  3596. {
  3597. m_host.AddScriptLPS(1);
  3598. }
  3599. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3600. {
  3601. m_host.AddScriptLPS(1);
  3602. TargetOmega(m_host, axis, spinrate, gain);
  3603. }
  3604. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3605. {
  3606. PhysicsActor pa = part.PhysActor;
  3607. if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d )
  3608. spinrate = 0.0d;
  3609. part.UpdateAngularVelocity(axis * spinrate);
  3610. }
  3611. public LSL_Integer llGetStartParameter()
  3612. {
  3613. m_host.AddScriptLPS(1);
  3614. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3615. }
  3616. public void llRequestPermissions(string agent, int perm)
  3617. {
  3618. UUID agentID;
  3619. if (!UUID.TryParse(agent, out agentID))
  3620. return;
  3621. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3622. {
  3623. llReleaseControls();
  3624. m_item.PermsGranter = UUID.Zero;
  3625. m_item.PermsMask = 0;
  3626. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3627. "run_time_permissions", new Object[] {
  3628. new LSL_Integer(0) },
  3629. new DetectParams[0]));
  3630. return;
  3631. }
  3632. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3633. llReleaseControls();
  3634. m_host.AddScriptLPS(1);
  3635. int implicitPerms = 0;
  3636. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3637. {
  3638. // When attached, certain permissions are implicit if requested from owner
  3639. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3640. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3641. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3642. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3643. ScriptBaseClass.PERMISSION_ATTACH |
  3644. ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS;
  3645. }
  3646. else
  3647. {
  3648. if (m_host.ParentGroup.GetSittingAvatars().SingleOrDefault(sp => sp.UUID == agentID) != null)
  3649. {
  3650. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3651. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3652. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3653. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3654. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3655. }
  3656. else
  3657. {
  3658. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3659. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3660. }
  3661. if (World.GetExtraSetting("auto_grant_all_perms") == "true")
  3662. {
  3663. implicitPerms = perm;
  3664. }
  3665. }
  3666. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3667. {
  3668. m_host.TaskInventory.LockItemsForWrite(true);
  3669. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3670. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3671. m_host.TaskInventory.LockItemsForWrite(false);
  3672. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3673. "run_time_permissions", new Object[] {
  3674. new LSL_Integer(perm) },
  3675. new DetectParams[0]));
  3676. return;
  3677. }
  3678. ScenePresence presence = World.GetScenePresence(agentID);
  3679. if (presence != null)
  3680. {
  3681. // If permissions are being requested from an NPC and were not implicitly granted above then
  3682. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3683. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3684. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3685. {
  3686. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3687. {
  3688. lock (m_host.TaskInventory)
  3689. {
  3690. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3691. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3692. }
  3693. m_ScriptEngine.PostScriptEvent(
  3694. m_item.ItemID,
  3695. new EventParams(
  3696. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3697. }
  3698. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3699. // the question!
  3700. return;
  3701. }
  3702. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3703. if (ownerName == String.Empty)
  3704. ownerName = "(hippos)";
  3705. if (!m_waitingForScriptAnswer)
  3706. {
  3707. m_host.TaskInventory.LockItemsForWrite(true);
  3708. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3709. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3710. m_host.TaskInventory.LockItemsForWrite(false);
  3711. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3712. m_waitingForScriptAnswer=true;
  3713. }
  3714. presence.ControllingClient.SendScriptQuestion(
  3715. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3716. return;
  3717. }
  3718. // Requested agent is not in range, refuse perms
  3719. m_ScriptEngine.PostScriptEvent(
  3720. m_item.ItemID,
  3721. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3722. }
  3723. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3724. {
  3725. if (taskID != m_host.UUID)
  3726. return;
  3727. client.OnScriptAnswer -= handleScriptAnswer;
  3728. m_waitingForScriptAnswer = false;
  3729. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3730. llReleaseControls();
  3731. m_host.TaskInventory.LockItemsForWrite(true);
  3732. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3733. m_host.TaskInventory.LockItemsForWrite(false);
  3734. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3735. "run_time_permissions", new Object[] {
  3736. new LSL_Integer(answer) },
  3737. new DetectParams[0]));
  3738. }
  3739. public LSL_Key llGetPermissionsKey()
  3740. {
  3741. m_host.AddScriptLPS(1);
  3742. return m_item.PermsGranter.ToString();
  3743. }
  3744. public LSL_Integer llGetPermissions()
  3745. {
  3746. m_host.AddScriptLPS(1);
  3747. int perms = m_item.PermsMask;
  3748. if (m_automaticLinkPermission)
  3749. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3750. return perms;
  3751. }
  3752. public LSL_Integer llGetLinkNumber()
  3753. {
  3754. m_host.AddScriptLPS(1);
  3755. if (m_host.ParentGroup.PrimCount > 1)
  3756. {
  3757. return m_host.LinkNum;
  3758. }
  3759. else
  3760. {
  3761. return 0;
  3762. }
  3763. }
  3764. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3765. {
  3766. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3767. if (parts.Count > 0)
  3768. {
  3769. try
  3770. {
  3771. foreach (SceneObjectPart part in parts)
  3772. part.SetFaceColorAlpha(face, color, null);
  3773. }
  3774. finally { }
  3775. }
  3776. }
  3777. public void llCreateLink(LSL_String target, LSL_Integer parent)
  3778. {
  3779. m_host.AddScriptLPS(1);
  3780. UUID targetID;
  3781. if (!UUID.TryParse(target, out targetID))
  3782. return;
  3783. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3784. && !m_automaticLinkPermission)
  3785. {
  3786. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3787. return;
  3788. }
  3789. CreateLink(target, parent);
  3790. }
  3791. public void CreateLink(string target, int parent)
  3792. {
  3793. UUID targetID;
  3794. if (!UUID.TryParse(target, out targetID))
  3795. return;
  3796. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
  3797. if (targetPart == null)
  3798. return;
  3799. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3800. return; // Fail silently if attached
  3801. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3802. return;
  3803. SceneObjectGroup parentPrim = null, childPrim = null;
  3804. if (parent != 0)
  3805. {
  3806. parentPrim = m_host.ParentGroup;
  3807. childPrim = targetPart.ParentGroup;
  3808. }
  3809. else
  3810. {
  3811. parentPrim = targetPart.ParentGroup;
  3812. childPrim = m_host.ParentGroup;
  3813. }
  3814. // Required for linking
  3815. childPrim.RootPart.ClearUpdateSchedule();
  3816. parentPrim.LinkToGroup(childPrim, true);
  3817. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3818. parentPrim.RootPart.CreateSelected = true;
  3819. parentPrim.HasGroupChanged = true;
  3820. parentPrim.ScheduleGroupForFullUpdate();
  3821. IClientAPI client = null;
  3822. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3823. if (sp != null)
  3824. client = sp.ControllingClient;
  3825. if (client != null)
  3826. parentPrim.SendPropertiesToClient(client);
  3827. ScriptSleep(m_sleepMsOnCreateLink);
  3828. }
  3829. public void llBreakLink(int linknum)
  3830. {
  3831. m_host.AddScriptLPS(1);
  3832. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3833. && !m_automaticLinkPermission)
  3834. {
  3835. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3836. return;
  3837. }
  3838. BreakLink(linknum);
  3839. }
  3840. public void BreakLink(int linknum)
  3841. {
  3842. if (linknum < ScriptBaseClass.LINK_THIS)
  3843. return;
  3844. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3845. if (parentPrim.AttachmentPoint != 0)
  3846. return; // Fail silently if attached
  3847. SceneObjectPart childPrim = null;
  3848. switch (linknum)
  3849. {
  3850. case ScriptBaseClass.LINK_ROOT:
  3851. break;
  3852. case ScriptBaseClass.LINK_SET:
  3853. case ScriptBaseClass.LINK_ALL_OTHERS:
  3854. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3855. case ScriptBaseClass.LINK_THIS:
  3856. foreach (SceneObjectPart part in parentPrim.Parts)
  3857. {
  3858. if (part.UUID != m_host.UUID)
  3859. {
  3860. childPrim = part;
  3861. break;
  3862. }
  3863. }
  3864. break;
  3865. default:
  3866. childPrim = parentPrim.GetLinkNumPart(linknum);
  3867. if (childPrim.UUID == m_host.UUID)
  3868. childPrim = null;
  3869. break;
  3870. }
  3871. if (linknum == ScriptBaseClass.LINK_ROOT)
  3872. {
  3873. // Restructuring Multiple Prims.
  3874. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3875. parts.Remove(parentPrim.RootPart);
  3876. if (parts.Count > 0)
  3877. {
  3878. try
  3879. {
  3880. foreach (SceneObjectPart part in parts)
  3881. {
  3882. parentPrim.DelinkFromGroup(part.LocalId, true);
  3883. }
  3884. }
  3885. finally { }
  3886. }
  3887. parentPrim.HasGroupChanged = true;
  3888. parentPrim.ScheduleGroupForFullUpdate();
  3889. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3890. if (parts.Count > 0)
  3891. {
  3892. SceneObjectPart newRoot = parts[0];
  3893. parts.Remove(newRoot);
  3894. try
  3895. {
  3896. foreach (SceneObjectPart part in parts)
  3897. {
  3898. part.ClearUpdateSchedule();
  3899. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3900. }
  3901. }
  3902. finally { }
  3903. newRoot.ParentGroup.HasGroupChanged = true;
  3904. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3905. }
  3906. }
  3907. else
  3908. {
  3909. if (childPrim == null)
  3910. return;
  3911. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3912. parentPrim.HasGroupChanged = true;
  3913. parentPrim.ScheduleGroupForFullUpdate();
  3914. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3915. }
  3916. }
  3917. public void llBreakAllLinks()
  3918. {
  3919. m_host.AddScriptLPS(1);
  3920. TaskInventoryItem item = m_item;
  3921. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3922. && !m_automaticLinkPermission)
  3923. {
  3924. Error("llBreakAllLinks","Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3925. return;
  3926. }
  3927. BreakAllLinks();
  3928. }
  3929. public void BreakAllLinks()
  3930. {
  3931. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3932. if (parentPrim.AttachmentPoint != 0)
  3933. return; // Fail silently if attached
  3934. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3935. parts.Remove(parentPrim.RootPart);
  3936. foreach (SceneObjectPart part in parts)
  3937. {
  3938. parentPrim.DelinkFromGroup(part.LocalId, true);
  3939. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3940. }
  3941. parentPrim.HasGroupChanged = true;
  3942. parentPrim.ScheduleGroupForFullUpdate();
  3943. }
  3944. public LSL_Key llGetLinkKey(int linknum)
  3945. {
  3946. m_host.AddScriptLPS(1);
  3947. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3948. if (part != null)
  3949. {
  3950. return part.UUID.ToString();
  3951. }
  3952. else
  3953. {
  3954. if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
  3955. {
  3956. linknum -= (m_host.ParentGroup.PrimCount) + 1;
  3957. if (linknum < 0)
  3958. return UUID.Zero.ToString();
  3959. List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
  3960. if (avatars.Count > linknum)
  3961. {
  3962. return avatars[linknum].UUID.ToString();
  3963. }
  3964. }
  3965. return UUID.Zero.ToString();
  3966. }
  3967. }
  3968. /// <summary>
  3969. /// Returns the name of the child prim or seated avatar matching the
  3970. /// specified link number.
  3971. /// </summary>
  3972. /// <param name="linknum">
  3973. /// The number of a link in the linkset or a link-related constant.
  3974. /// </param>
  3975. /// <returns>
  3976. /// The name determined to match the specified link number.
  3977. /// </returns>
  3978. /// <remarks>
  3979. /// The rules governing the returned name are not simple. The only
  3980. /// time a blank name is returned is if the target prim has a blank
  3981. /// name. If no prim with the given link number can be found then
  3982. /// usually NULL_KEY is returned but there are exceptions.
  3983. ///
  3984. /// In a single unlinked prim, A call with 0 returns the name, all
  3985. /// other values for link number return NULL_KEY
  3986. ///
  3987. /// In link sets it is more complicated.
  3988. ///
  3989. /// If the script is in the root prim:-
  3990. /// A zero link number returns NULL_KEY.
  3991. /// Positive link numbers return the name of the prim, or NULL_KEY
  3992. /// if a prim does not exist at that position.
  3993. /// Negative link numbers return the name of the first child prim.
  3994. ///
  3995. /// If the script is in a child prim:-
  3996. /// Link numbers 0 or 1 return the name of the root prim.
  3997. /// Positive link numbers return the name of the prim or NULL_KEY
  3998. /// if a prim does not exist at that position.
  3999. /// Negative numbers return the name of the root prim.
  4000. ///
  4001. /// References
  4002. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  4003. /// Mentions NULL_KEY being returned
  4004. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  4005. /// Mentions using the LINK_* constants, some of which are negative
  4006. /// </remarks>
  4007. public LSL_String llGetLinkName(int linknum)
  4008. {
  4009. m_host.AddScriptLPS(1);
  4010. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  4011. if (entity != null)
  4012. return entity.Name;
  4013. else
  4014. return ScriptBaseClass.NULL_KEY;
  4015. }
  4016. public LSL_Integer llGetInventoryNumber(int type)
  4017. {
  4018. m_host.AddScriptLPS(1);
  4019. int count = 0;
  4020. m_host.TaskInventory.LockItemsForRead(true);
  4021. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4022. {
  4023. if (inv.Value.Type == type || type == -1)
  4024. {
  4025. count = count + 1;
  4026. }
  4027. }
  4028. m_host.TaskInventory.LockItemsForRead(false);
  4029. return count;
  4030. }
  4031. public LSL_String llGetInventoryName(int type, int number)
  4032. {
  4033. m_host.AddScriptLPS(1);
  4034. ArrayList keys = new ArrayList();
  4035. m_host.TaskInventory.LockItemsForRead(true);
  4036. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4037. {
  4038. if (inv.Value.Type == type || type == -1)
  4039. {
  4040. keys.Add(inv.Value.Name);
  4041. }
  4042. }
  4043. m_host.TaskInventory.LockItemsForRead(false);
  4044. if (keys.Count == 0)
  4045. {
  4046. return String.Empty;
  4047. }
  4048. keys.Sort();
  4049. if (keys.Count > number)
  4050. {
  4051. return (string)keys[number];
  4052. }
  4053. return String.Empty;
  4054. }
  4055. public LSL_Float llGetEnergy()
  4056. {
  4057. m_host.AddScriptLPS(1);
  4058. // TODO: figure out real energy value
  4059. return 1.0f;
  4060. }
  4061. public void llGiveInventory(string destination, string inventory)
  4062. {
  4063. m_host.AddScriptLPS(1);
  4064. UUID destId = UUID.Zero;
  4065. if (!UUID.TryParse(destination, out destId))
  4066. {
  4067. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  4068. return;
  4069. }
  4070. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  4071. if (item == null)
  4072. {
  4073. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  4074. return;
  4075. }
  4076. UUID objId = item.ItemID;
  4077. // check if destination is an object
  4078. if (World.GetSceneObjectPart(destId) != null)
  4079. {
  4080. // destination is an object
  4081. World.MoveTaskInventoryItem(destId, m_host, objId);
  4082. }
  4083. else
  4084. {
  4085. ScenePresence presence = World.GetScenePresence(destId);
  4086. if (presence == null)
  4087. {
  4088. UserAccount account =
  4089. World.UserAccountService.GetUserAccount(
  4090. World.RegionInfo.ScopeID,
  4091. destId);
  4092. if (account == null)
  4093. {
  4094. GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
  4095. if(info == null || info.Online == false)
  4096. {
  4097. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  4098. return;
  4099. }
  4100. }
  4101. }
  4102. // destination is an avatar
  4103. string message;
  4104. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message);
  4105. if (agentItem == null)
  4106. {
  4107. llSay(0, message);
  4108. return;
  4109. }
  4110. byte[] bucket = new byte[1];
  4111. bucket[0] = (byte)item.Type;
  4112. //byte[] objBytes = agentItem.ID.GetBytes();
  4113. //Array.Copy(objBytes, 0, bucket, 1, 16);
  4114. GridInstantMessage msg = new GridInstantMessage(World,
  4115. m_host.OwnerID, m_host.Name, destId,
  4116. (byte)InstantMessageDialog.TaskInventoryOffered,
  4117. false, item.Name+". "+m_host.Name+" is located at "+
  4118. World.RegionInfo.RegionName+" "+
  4119. m_host.AbsolutePosition.ToString(),
  4120. agentItem.ID, true, m_host.AbsolutePosition,
  4121. bucket, true);
  4122. ScenePresence sp;
  4123. if (World.TryGetScenePresence(destId, out sp))
  4124. {
  4125. sp.ControllingClient.SendInstantMessage(msg);
  4126. }
  4127. else
  4128. {
  4129. if (m_TransferModule != null)
  4130. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  4131. }
  4132. //This delay should only occur when giving inventory to avatars.
  4133. ScriptSleep(m_sleepMsOnGiveInventory);
  4134. }
  4135. }
  4136. [DebuggerNonUserCode]
  4137. public void llRemoveInventory(string name)
  4138. {
  4139. m_host.AddScriptLPS(1);
  4140. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4141. if (item == null)
  4142. return;
  4143. if (item.ItemID == m_item.ItemID)
  4144. throw new ScriptDeleteException();
  4145. else
  4146. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  4147. }
  4148. public void llSetText(string text, LSL_Vector color, double alpha)
  4149. {
  4150. m_host.AddScriptLPS(1);
  4151. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  4152. byte[] data;
  4153. data = Util.StringToBytes256(text);
  4154. text = Util.UTF8.GetString(data);
  4155. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  4156. }
  4157. public LSL_Float llWater(LSL_Vector offset)
  4158. {
  4159. m_host.AddScriptLPS(1);
  4160. return World.RegionInfo.RegionSettings.WaterHeight;
  4161. }
  4162. public void llPassTouches(int pass)
  4163. {
  4164. m_host.AddScriptLPS(1);
  4165. if (pass != 0)
  4166. m_host.PassTouches = true;
  4167. else
  4168. m_host.PassTouches = false;
  4169. }
  4170. public LSL_Key llRequestAgentData(string id, int data)
  4171. {
  4172. m_host.AddScriptLPS(1);
  4173. UUID uuid;
  4174. if (UUID.TryParse(id, out uuid))
  4175. {
  4176. PresenceInfo pinfo = null;
  4177. UserAccount account;
  4178. UserInfoCacheEntry ce;
  4179. if (!m_userInfoCache.TryGetValue(uuid, out ce))
  4180. {
  4181. account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  4182. if (account == null)
  4183. {
  4184. m_userInfoCache[uuid] = null; // Cache negative
  4185. return UUID.Zero.ToString();
  4186. }
  4187. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4188. if (pinfos != null && pinfos.Length > 0)
  4189. {
  4190. foreach (PresenceInfo p in pinfos)
  4191. {
  4192. if (p.RegionID != UUID.Zero)
  4193. {
  4194. pinfo = p;
  4195. }
  4196. }
  4197. }
  4198. ce = new UserInfoCacheEntry();
  4199. ce.time = Util.EnvironmentTickCount();
  4200. ce.account = account;
  4201. ce.pinfo = pinfo;
  4202. m_userInfoCache[uuid] = ce;
  4203. }
  4204. else
  4205. {
  4206. if (ce == null)
  4207. return UUID.Zero.ToString();
  4208. account = ce.account;
  4209. pinfo = ce.pinfo;
  4210. }
  4211. if (Util.EnvironmentTickCount() < ce.time ||
  4212. (Util.EnvironmentTickCount() - ce.time) >= LlRequestAgentDataCacheTimeoutMs)
  4213. {
  4214. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4215. if (pinfos != null && pinfos.Length > 0)
  4216. {
  4217. foreach (PresenceInfo p in pinfos)
  4218. {
  4219. if (p.RegionID != UUID.Zero)
  4220. {
  4221. pinfo = p;
  4222. }
  4223. }
  4224. }
  4225. else
  4226. pinfo = null;
  4227. ce.time = Util.EnvironmentTickCount();
  4228. ce.pinfo = pinfo;
  4229. }
  4230. string reply = String.Empty;
  4231. switch (data)
  4232. {
  4233. case ScriptBaseClass.DATA_ONLINE: // DATA_ONLINE (0|1)
  4234. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  4235. reply = "1";
  4236. else
  4237. reply = "0";
  4238. break;
  4239. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4240. reply = account.FirstName + " " + account.LastName;
  4241. break;
  4242. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4243. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  4244. born = born.AddSeconds(account.Created);
  4245. reply = born.ToString("yyyy-MM-dd");
  4246. break;
  4247. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4248. reply = "0,0,0,0,0,0";
  4249. break;
  4250. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4251. reply = account.UserLevel.ToString();
  4252. break;
  4253. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4254. reply = "0";
  4255. break;
  4256. default:
  4257. return UUID.Zero.ToString(); // Raise no event
  4258. }
  4259. UUID rq = UUID.Random();
  4260. UUID tid = AsyncCommands.
  4261. DataserverPlugin.RegisterRequest(m_host.LocalId,
  4262. m_item.ItemID, rq.ToString());
  4263. AsyncCommands.
  4264. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  4265. ScriptSleep(m_sleepMsOnRequestAgentData);
  4266. return tid.ToString();
  4267. }
  4268. else
  4269. {
  4270. Error("llRequestAgentData","Invalid UUID passed to llRequestAgentData.");
  4271. }
  4272. return "";
  4273. }
  4274. public LSL_Key llRequestInventoryData(string name)
  4275. {
  4276. m_host.AddScriptLPS(1);
  4277. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  4278. {
  4279. if (item.Type == 3 && item.Name == name)
  4280. {
  4281. UUID tid = AsyncCommands.
  4282. DataserverPlugin.RegisterRequest(m_host.LocalId,
  4283. m_item.ItemID, item.AssetID.ToString());
  4284. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4285. World.AssetService.Get(item.AssetID.ToString(), this,
  4286. delegate(string i, object sender, AssetBase a)
  4287. {
  4288. AssetLandmark lm = new AssetLandmark(a);
  4289. float rx = (uint)(lm.RegionHandle >> 32);
  4290. float ry = (uint)lm.RegionHandle;
  4291. region = lm.Position + new Vector3(rx, ry, 0) - region;
  4292. string reply = region.ToString();
  4293. AsyncCommands.
  4294. DataserverPlugin.DataserverReply(i.ToString(),
  4295. reply);
  4296. });
  4297. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4298. return tid.ToString();
  4299. }
  4300. }
  4301. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4302. return String.Empty;
  4303. }
  4304. public void llSetDamage(double damage)
  4305. {
  4306. m_host.AddScriptLPS(1);
  4307. m_host.ParentGroup.Damage = (float)damage;
  4308. }
  4309. public void llTeleportAgentHome(string agent)
  4310. {
  4311. m_host.AddScriptLPS(1);
  4312. UUID agentId = new UUID();
  4313. if (UUID.TryParse(agent, out agentId))
  4314. {
  4315. ScenePresence presence = World.GetScenePresence(agentId);
  4316. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4317. {
  4318. // agent must not be a god
  4319. if (presence.GodController.UserLevel >= 200) return;
  4320. // agent must be over the owners land
  4321. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  4322. {
  4323. if (!World.TeleportClientHome(agentId, presence.ControllingClient))
  4324. {
  4325. // They can't be teleported home for some reason
  4326. GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
  4327. if (regionInfo != null)
  4328. {
  4329. World.RequestTeleportLocation(
  4330. presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
  4331. (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
  4332. }
  4333. }
  4334. }
  4335. }
  4336. }
  4337. ScriptSleep(m_sleepMsOnSetDamage);
  4338. }
  4339. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4340. {
  4341. m_host.AddScriptLPS(1);
  4342. UUID agentId = new UUID();
  4343. if (UUID.TryParse(agent, out agentId))
  4344. {
  4345. ScenePresence presence = World.GetScenePresence(agentId);
  4346. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4347. {
  4348. if (destination == String.Empty)
  4349. destination = World.RegionInfo.RegionName;
  4350. if (m_item.PermsGranter == agentId)
  4351. {
  4352. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4353. {
  4354. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4355. }
  4356. }
  4357. // agent must be wearing the object
  4358. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  4359. {
  4360. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4361. }
  4362. else
  4363. {
  4364. // agent must not be a god
  4365. if (presence.IsViewerUIGod) return;
  4366. // agent must be over the owners land
  4367. ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  4368. ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  4369. if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
  4370. {
  4371. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4372. }
  4373. }
  4374. }
  4375. }
  4376. }
  4377. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4378. {
  4379. m_host.AddScriptLPS(1);
  4380. UUID agentId = new UUID();
  4381. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  4382. if (UUID.TryParse(agent, out agentId))
  4383. {
  4384. // This function is owner only!
  4385. if (m_host.OwnerID != agentId)
  4386. return;
  4387. ScenePresence presence = World.GetScenePresence(agentId);
  4388. if (presence == null || presence.PresenceType == PresenceType.Npc)
  4389. return;
  4390. // Can't TP sitting avatars
  4391. if (presence.ParentID != 0) // Sitting
  4392. return;
  4393. if (m_item.PermsGranter == agentId)
  4394. {
  4395. // If attached using llAttachToAvatarTemp, cowardly refuse
  4396. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
  4397. return;
  4398. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4399. {
  4400. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4401. }
  4402. }
  4403. }
  4404. }
  4405. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  4406. {
  4407. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  4408. // The destinaion is not an asset ID and also doesn't name a landmark.
  4409. // Use it as a sim name
  4410. if (assetID == UUID.Zero)
  4411. {
  4412. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4413. return;
  4414. }
  4415. AssetBase lma = World.AssetService.Get(assetID.ToString());
  4416. if (lma == null)
  4417. return;
  4418. if (lma.Type != (sbyte)AssetType.Landmark)
  4419. return;
  4420. AssetLandmark lm = new AssetLandmark(lma);
  4421. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4422. }
  4423. public void llTextBox(string agent, string message, int chatChannel)
  4424. {
  4425. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  4426. if (dm == null)
  4427. return;
  4428. m_host.AddScriptLPS(1);
  4429. UUID av = new UUID();
  4430. if (!UUID.TryParse(agent,out av))
  4431. {
  4432. Error("llTextBox", "First parameter must be a key");
  4433. return;
  4434. }
  4435. if (message == string.Empty)
  4436. {
  4437. Error("llTextBox", "Empty message");
  4438. }
  4439. else if (Encoding.UTF8.GetByteCount(message) > 512)
  4440. {
  4441. Error("llTextBox", "Message longer than 512 bytes");
  4442. }
  4443. else
  4444. {
  4445. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  4446. ScriptSleep(m_sleepMsOnTextBox);
  4447. }
  4448. }
  4449. public void llModifyLand(int action, int brush)
  4450. {
  4451. m_host.AddScriptLPS(1);
  4452. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  4453. if (tm != null)
  4454. {
  4455. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action, m_host.OwnerID);
  4456. }
  4457. }
  4458. public void llCollisionSound(string impact_sound, double impact_volume)
  4459. {
  4460. m_host.AddScriptLPS(1);
  4461. if(impact_sound == "")
  4462. {
  4463. m_host.CollisionSoundVolume = (float)impact_volume;
  4464. m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
  4465. m_host.CollisionSoundType = -1; // disable all sounds
  4466. m_host.aggregateScriptEvents();
  4467. return;
  4468. }
  4469. // TODO: Parameter check logic required.
  4470. UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  4471. if(soundId != UUID.Zero)
  4472. {
  4473. m_host.CollisionSound = soundId;
  4474. m_host.CollisionSoundVolume = (float)impact_volume;
  4475. m_host.CollisionSoundType = 1;
  4476. }
  4477. else
  4478. m_host.CollisionSoundType = -1;
  4479. m_host.aggregateScriptEvents();
  4480. }
  4481. public LSL_String llGetAnimation(string id)
  4482. {
  4483. // This should only return a value if the avatar is in the same region
  4484. m_host.AddScriptLPS(1);
  4485. UUID avatar = (UUID)id;
  4486. ScenePresence presence = World.GetScenePresence(avatar);
  4487. if (presence == null)
  4488. return "";
  4489. if (m_host.RegionHandle == presence.RegionHandle)
  4490. {
  4491. if (presence != null)
  4492. {
  4493. // if (presence.SitGround)
  4494. // return "Sitting on Ground";
  4495. // if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
  4496. // return "Sitting";
  4497. string movementAnimation = presence.Animator.CurrentMovementAnimation;
  4498. string lslMovementAnimation;
  4499. if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out lslMovementAnimation))
  4500. return lslMovementAnimation;
  4501. }
  4502. }
  4503. return String.Empty;
  4504. }
  4505. public void llMessageLinked(int linknumber, int num, string msg, string id)
  4506. {
  4507. m_host.AddScriptLPS(1);
  4508. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4509. UUID partItemID;
  4510. foreach (SceneObjectPart part in parts)
  4511. {
  4512. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  4513. {
  4514. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  4515. {
  4516. partItemID = item.ItemID;
  4517. int linkNumber = m_host.LinkNum;
  4518. if (m_host.ParentGroup.PrimCount == 1)
  4519. linkNumber = 0;
  4520. object[] resobj = new object[]
  4521. {
  4522. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  4523. };
  4524. m_ScriptEngine.PostScriptEvent(partItemID,
  4525. new EventParams("link_message",
  4526. resobj, new DetectParams[0]));
  4527. }
  4528. }
  4529. }
  4530. }
  4531. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  4532. {
  4533. m_host.AddScriptLPS(1);
  4534. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  4535. bool pushAllowed = false;
  4536. bool pusheeIsAvatar = false;
  4537. UUID targetID = UUID.Zero;
  4538. if (!UUID.TryParse(target,out targetID))
  4539. return;
  4540. ScenePresence pusheeav = null;
  4541. Vector3 PusheePos = Vector3.Zero;
  4542. SceneObjectPart pusheeob = null;
  4543. ScenePresence avatar = World.GetScenePresence(targetID);
  4544. if (avatar != null)
  4545. {
  4546. pusheeIsAvatar = true;
  4547. // Pushee doesn't have a physics actor
  4548. if (avatar.PhysicsActor == null)
  4549. return;
  4550. // Pushee is in GodMode this pushing object isn't owned by them
  4551. if (avatar.IsViewerUIGod && m_host.OwnerID != targetID)
  4552. return;
  4553. pusheeav = avatar;
  4554. // Find pushee position
  4555. // Pushee Linked?
  4556. SceneObjectPart sitPart = pusheeav.ParentPart;
  4557. if (sitPart != null)
  4558. PusheePos = sitPart.AbsolutePosition;
  4559. else
  4560. PusheePos = pusheeav.AbsolutePosition;
  4561. }
  4562. if (!pusheeIsAvatar)
  4563. {
  4564. // not an avatar so push is not affected by parcel flags
  4565. pusheeob = World.GetSceneObjectPart((UUID)target);
  4566. // We can't find object
  4567. if (pusheeob == null)
  4568. return;
  4569. // Object not pushable. Not an attachment and has no physics component
  4570. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  4571. return;
  4572. PusheePos = pusheeob.AbsolutePosition;
  4573. pushAllowed = true;
  4574. }
  4575. else
  4576. {
  4577. if (pushrestricted)
  4578. {
  4579. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4580. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  4581. if (targetlandObj == null)
  4582. return;
  4583. // Need provisions for Group Owned here
  4584. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4585. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  4586. {
  4587. pushAllowed = true;
  4588. }
  4589. }
  4590. else
  4591. {
  4592. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4593. if (targetlandObj == null)
  4594. {
  4595. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4596. pushAllowed = true;
  4597. }
  4598. else
  4599. {
  4600. // Parcel push restriction
  4601. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4602. {
  4603. // Need provisions for Group Owned here
  4604. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4605. targetlandObj.LandData.IsGroupOwned ||
  4606. m_host.OwnerID == targetID)
  4607. {
  4608. pushAllowed = true;
  4609. }
  4610. //ParcelFlags.RestrictPushObject
  4611. //pushAllowed = true;
  4612. }
  4613. else
  4614. {
  4615. // Parcel isn't push restricted
  4616. pushAllowed = true;
  4617. }
  4618. }
  4619. }
  4620. }
  4621. if (pushAllowed)
  4622. {
  4623. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4624. float distance_term = distance * distance * distance; // Script Energy
  4625. // use total object mass and not part
  4626. float pusher_mass = m_host.ParentGroup.GetMass();
  4627. float PUSH_ATTENUATION_DISTANCE = 17f;
  4628. float PUSH_ATTENUATION_SCALE = 5f;
  4629. float distance_attenuation = 1f;
  4630. if (distance > PUSH_ATTENUATION_DISTANCE)
  4631. {
  4632. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4633. distance_attenuation = 1f / normalized_units;
  4634. }
  4635. Vector3 applied_linear_impulse = impulse;
  4636. {
  4637. float impulse_length = applied_linear_impulse.Length();
  4638. float desired_energy = impulse_length * pusher_mass;
  4639. if (desired_energy > 0f)
  4640. desired_energy += distance_term;
  4641. float scaling_factor = 1f;
  4642. scaling_factor *= distance_attenuation;
  4643. applied_linear_impulse *= scaling_factor;
  4644. }
  4645. if (pusheeIsAvatar)
  4646. {
  4647. if (pusheeav != null)
  4648. {
  4649. PhysicsActor pa = pusheeav.PhysicsActor;
  4650. if (pa != null)
  4651. {
  4652. if (local != 0)
  4653. {
  4654. // applied_linear_impulse *= m_host.GetWorldRotation();
  4655. applied_linear_impulse *= pusheeav.GetWorldRotation();
  4656. }
  4657. pa.AddForce(applied_linear_impulse, true);
  4658. }
  4659. }
  4660. }
  4661. else
  4662. {
  4663. if (pusheeob != null)
  4664. {
  4665. if (pusheeob.PhysActor != null)
  4666. {
  4667. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4668. }
  4669. }
  4670. }
  4671. }
  4672. }
  4673. public void llPassCollisions(int pass)
  4674. {
  4675. m_host.AddScriptLPS(1);
  4676. if (pass == 0)
  4677. {
  4678. m_host.PassCollisions = false;
  4679. }
  4680. else
  4681. {
  4682. m_host.PassCollisions = true;
  4683. }
  4684. }
  4685. public LSL_String llGetScriptName()
  4686. {
  4687. m_host.AddScriptLPS(1);
  4688. return m_item.Name != null ? m_item.Name : String.Empty;
  4689. }
  4690. public LSL_Integer llGetLinkNumberOfSides(int link)
  4691. {
  4692. m_host.AddScriptLPS(1);
  4693. SceneObjectPart linkedPart;
  4694. if (link == ScriptBaseClass.LINK_ROOT)
  4695. linkedPart = m_host.ParentGroup.RootPart;
  4696. else if (link == ScriptBaseClass.LINK_THIS)
  4697. linkedPart = m_host;
  4698. else
  4699. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4700. return GetNumberOfSides(linkedPart);
  4701. }
  4702. public LSL_Integer llGetNumberOfSides()
  4703. {
  4704. m_host.AddScriptLPS(1);
  4705. return m_host.GetNumberOfSides();
  4706. }
  4707. protected int GetNumberOfSides(SceneObjectPart part)
  4708. {
  4709. return part.GetNumberOfSides();
  4710. }
  4711. /* The new / changed functions were tested with the following LSL script:
  4712. default
  4713. {
  4714. state_entry()
  4715. {
  4716. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4717. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4718. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4719. // convert back and forth between quaternion <-> vector and angle
  4720. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4721. llOwnerSay("Old rotation was: "+(string) rot);
  4722. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4723. llSetRot(rot); // to check the parameters in the prim
  4724. }
  4725. }
  4726. */
  4727. // Xantor 29/apr/2008
  4728. // Returns rotation described by rotating angle radians about axis.
  4729. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4730. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4731. {
  4732. m_host.AddScriptLPS(1);
  4733. double x, y, z, s, t;
  4734. s = Math.Cos(angle * 0.5);
  4735. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4736. axis = LSL_Vector.Norm(axis);
  4737. x = axis.x * t;
  4738. y = axis.y * t;
  4739. z = axis.z * t;
  4740. return new LSL_Rotation(x,y,z,s);
  4741. }
  4742. /// <summary>
  4743. /// Returns the axis of rotation for a quaternion
  4744. /// </summary>
  4745. /// <returns></returns>
  4746. /// <param name='rot'></param>
  4747. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4748. {
  4749. m_host.AddScriptLPS(1);
  4750. rot.Normalize();
  4751. double s = Math.Sqrt(1 - rot.s * rot.s);
  4752. if (s < 1e-8)
  4753. return new LSL_Vector(0, 0, 0);
  4754. double invS = 1.0 / s;
  4755. if (rot.s < 0)
  4756. invS = -invS;
  4757. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4758. }
  4759. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4760. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4761. {
  4762. m_host.AddScriptLPS(1);
  4763. rot.Normalize();
  4764. double angle = 2 * Math.Acos(rot.s);
  4765. if (angle > Math.PI)
  4766. angle = 2 * Math.PI - angle;
  4767. return angle;
  4768. }
  4769. public LSL_Float llAcos(double val)
  4770. {
  4771. m_host.AddScriptLPS(1);
  4772. return (double)Math.Acos(val);
  4773. }
  4774. public LSL_Float llAsin(double val)
  4775. {
  4776. m_host.AddScriptLPS(1);
  4777. return (double)Math.Asin(val);
  4778. }
  4779. // jcochran 5/jan/2012
  4780. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4781. {
  4782. m_host.AddScriptLPS(1);
  4783. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4784. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4785. double aa_bb = aa * bb;
  4786. if (aa_bb == 0) return 0.0;
  4787. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4788. double quotient = (ab * ab) / aa_bb;
  4789. if (quotient >= 1.0) return 0.0;
  4790. return Math.Acos(2 * quotient - 1);
  4791. }
  4792. public LSL_Key llGetInventoryKey(string name)
  4793. {
  4794. m_host.AddScriptLPS(1);
  4795. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4796. if (item == null)
  4797. return UUID.Zero.ToString();
  4798. if ((item.CurrentPermissions
  4799. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4800. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4801. {
  4802. return item.AssetID.ToString();
  4803. }
  4804. return UUID.Zero.ToString();
  4805. }
  4806. public void llAllowInventoryDrop(int add)
  4807. {
  4808. m_host.AddScriptLPS(1);
  4809. if (add != 0)
  4810. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4811. else
  4812. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4813. // Update the object flags
  4814. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4815. }
  4816. public LSL_Vector llGetSunDirection()
  4817. {
  4818. m_host.AddScriptLPS(1);
  4819. LSL_Vector SunDoubleVector3;
  4820. Vector3 SunFloatVector3;
  4821. // sunPosition estate setting is set in OpenSim.Region.CoreModules.SunModule
  4822. // have to convert from Vector3 (float) to LSL_Vector (double)
  4823. SunFloatVector3 = World.RegionInfo.RegionSettings.SunVector;
  4824. SunDoubleVector3.x = (double)SunFloatVector3.X;
  4825. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  4826. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  4827. return SunDoubleVector3;
  4828. }
  4829. public LSL_Vector llGetTextureOffset(int face)
  4830. {
  4831. m_host.AddScriptLPS(1);
  4832. return GetTextureOffset(m_host, face);
  4833. }
  4834. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4835. {
  4836. Primitive.TextureEntry tex = part.Shape.Textures;
  4837. LSL_Vector offset = new LSL_Vector();
  4838. if (face == ScriptBaseClass.ALL_SIDES)
  4839. {
  4840. face = 0;
  4841. }
  4842. if (face >= 0 && face < GetNumberOfSides(part))
  4843. {
  4844. offset.x = tex.GetFace((uint)face).OffsetU;
  4845. offset.y = tex.GetFace((uint)face).OffsetV;
  4846. offset.z = 0.0;
  4847. return offset;
  4848. }
  4849. else
  4850. {
  4851. return offset;
  4852. }
  4853. }
  4854. public LSL_Vector llGetTextureScale(int side)
  4855. {
  4856. m_host.AddScriptLPS(1);
  4857. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4858. LSL_Vector scale;
  4859. if (side == -1)
  4860. {
  4861. side = 0;
  4862. }
  4863. scale.x = tex.GetFace((uint)side).RepeatU;
  4864. scale.y = tex.GetFace((uint)side).RepeatV;
  4865. scale.z = 0.0;
  4866. return scale;
  4867. }
  4868. public LSL_Float llGetTextureRot(int face)
  4869. {
  4870. m_host.AddScriptLPS(1);
  4871. return GetTextureRot(m_host, face);
  4872. }
  4873. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4874. {
  4875. Primitive.TextureEntry tex = part.Shape.Textures;
  4876. if (face == -1)
  4877. {
  4878. face = 0;
  4879. }
  4880. if (face >= 0 && face < GetNumberOfSides(part))
  4881. {
  4882. return tex.GetFace((uint)face).Rotation;
  4883. }
  4884. else
  4885. {
  4886. return 0.0;
  4887. }
  4888. }
  4889. public LSL_Integer llSubStringIndex(string source, string pattern)
  4890. {
  4891. m_host.AddScriptLPS(1);
  4892. return source.IndexOf(pattern);
  4893. }
  4894. public LSL_Key llGetOwnerKey(string id)
  4895. {
  4896. m_host.AddScriptLPS(1);
  4897. UUID key = new UUID();
  4898. if (UUID.TryParse(id, out key))
  4899. {
  4900. try
  4901. {
  4902. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4903. if (obj == null)
  4904. return id; // the key is for an agent so just return the key
  4905. else
  4906. return obj.OwnerID.ToString();
  4907. }
  4908. catch (KeyNotFoundException)
  4909. {
  4910. return id; // The Object/Agent not in the region so just return the key
  4911. }
  4912. }
  4913. else
  4914. {
  4915. return UUID.Zero.ToString();
  4916. }
  4917. }
  4918. public LSL_Vector llGetCenterOfMass()
  4919. {
  4920. m_host.AddScriptLPS(1);
  4921. return new LSL_Vector(m_host.GetCenterOfMass());
  4922. }
  4923. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4924. {
  4925. m_host.AddScriptLPS(1);
  4926. if (stride <= 0)
  4927. {
  4928. stride = 1;
  4929. }
  4930. return src.Sort(stride, ascending);
  4931. }
  4932. public LSL_Integer llGetListLength(LSL_List src)
  4933. {
  4934. m_host.AddScriptLPS(1);
  4935. return src.Length;
  4936. }
  4937. public LSL_Integer llList2Integer(LSL_List src, int index)
  4938. {
  4939. m_host.AddScriptLPS(1);
  4940. if (index < 0)
  4941. index = src.Length + index;
  4942. if (index >= src.Length || index < 0)
  4943. return 0;
  4944. object item = src.Data[index];
  4945. // Vectors & Rotations always return zero in SL, but
  4946. // keys don't always return zero, it seems to be a bit complex.
  4947. if (item is LSL_Vector || item is LSL_Rotation)
  4948. return 0;
  4949. try
  4950. {
  4951. if (item is LSL_Integer)
  4952. return (LSL_Integer)item;
  4953. else if (item is LSL_Float)
  4954. return Convert.ToInt32(((LSL_Float)item).value);;
  4955. return new LSL_Integer(item.ToString());
  4956. }
  4957. catch (FormatException)
  4958. {
  4959. return 0;
  4960. }
  4961. }
  4962. public LSL_Float llList2Float(LSL_List src, int index)
  4963. {
  4964. m_host.AddScriptLPS(1);
  4965. if (index < 0)
  4966. index = src.Length + index;
  4967. if (index >= src.Length || index < 0)
  4968. return 0;
  4969. object item = src.Data[index];
  4970. // Vectors & Rotations always return zero in SL
  4971. if(item is LSL_Vector || item is LSL_Rotation)
  4972. return 0;
  4973. // valid keys seem to get parsed as integers then converted to floats
  4974. if (item is LSL_Key)
  4975. {
  4976. UUID uuidt;
  4977. string s = item.ToString();
  4978. if(UUID.TryParse(s, out uuidt))
  4979. return Convert.ToDouble(new LSL_Integer(s).value);
  4980. // we can't do this because a string is also a LSL_Key for now :(
  4981. // else
  4982. // return 0;
  4983. }
  4984. try
  4985. {
  4986. if (item is LSL_Integer)
  4987. return Convert.ToDouble(((LSL_Integer)item).value);
  4988. else if (item is LSL_Float)
  4989. return Convert.ToDouble(((LSL_Float)item).value);
  4990. else if (item is LSL_String)
  4991. {
  4992. string str = ((LSL_String)item).m_string;
  4993. Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
  4994. if (m != Match.Empty)
  4995. {
  4996. str = m.Value;
  4997. double d = 0.0;
  4998. if (!Double.TryParse(str, out d))
  4999. return 0.0;
  5000. return d;
  5001. }
  5002. return 0.0;
  5003. }
  5004. return Convert.ToDouble(item);
  5005. }
  5006. catch (FormatException)
  5007. {
  5008. return 0.0;
  5009. }
  5010. }
  5011. public LSL_String llList2String(LSL_List src, int index)
  5012. {
  5013. m_host.AddScriptLPS(1);
  5014. if (index < 0)
  5015. index = src.Length + index;
  5016. if (index >= src.Length || index < 0)
  5017. return String.Empty;
  5018. return src.Data[index].ToString();
  5019. }
  5020. public LSL_Key llList2Key(LSL_List src, int index)
  5021. {
  5022. m_host.AddScriptLPS(1);
  5023. if (index < 0)
  5024. index = src.Length + index;
  5025. if (index >= src.Length || index < 0)
  5026. return String.Empty;
  5027. object item = src.Data[index];
  5028. // SL spits out an empty string for types other than key & string
  5029. // At the time of patching, LSL_Key is currently LSL_String,
  5030. // so the OR check may be a little redundant, but it's being done
  5031. // for completion and should LSL_Key ever be implemented
  5032. // as it's own struct
  5033. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  5034. // type 'obj' and wrongly returns ""
  5035. if (!(item is LSL_String ||
  5036. item is LSL_Key ||
  5037. item.ToString() == "00000000-0000-0000-0000-000000000000"))
  5038. {
  5039. return String.Empty;
  5040. }
  5041. return item.ToString();
  5042. }
  5043. public LSL_Vector llList2Vector(LSL_List src, int index)
  5044. {
  5045. m_host.AddScriptLPS(1);
  5046. if (index < 0)
  5047. index = src.Length + index;
  5048. if (index >= src.Length || index < 0)
  5049. return new LSL_Vector(0, 0, 0);
  5050. object item = src.Data[index];
  5051. if (item.GetType() == typeof(LSL_Vector))
  5052. return (LSL_Vector)item;
  5053. // SL spits always out ZERO_VECTOR for anything other than
  5054. // strings or vectors. Although keys always return ZERO_VECTOR,
  5055. // it is currently difficult to make the distinction between
  5056. // a string, a key as string and a string that by coincidence
  5057. // is a string, so we're going to leave that up to the
  5058. // LSL_Vector constructor.
  5059. if(item is LSL_Vector)
  5060. return (LSL_Vector) item;
  5061. if (item is LSL_String)
  5062. return new LSL_Vector(item.ToString());
  5063. return new LSL_Vector(0, 0, 0);
  5064. }
  5065. public LSL_Rotation llList2Rot(LSL_List src, int index)
  5066. {
  5067. m_host.AddScriptLPS(1);
  5068. if (index < 0)
  5069. index = src.Length + index;
  5070. if (index >= src.Length || index < 0)
  5071. return new LSL_Rotation(0, 0, 0, 1);
  5072. object item = src.Data[index];
  5073. // SL spits always out ZERO_ROTATION for anything other than
  5074. // strings or vectors. Although keys always return ZERO_ROTATION,
  5075. // it is currently difficult to make the distinction between
  5076. // a string, a key as string and a string that by coincidence
  5077. // is a string, so we're going to leave that up to the
  5078. // LSL_Rotation constructor.
  5079. if (item.GetType() == typeof(LSL_Rotation))
  5080. return (LSL_Rotation)item;
  5081. if (item is LSL_String)
  5082. return new LSL_Rotation(src.Data[index].ToString());
  5083. return new LSL_Rotation(0, 0, 0, 1);
  5084. }
  5085. public LSL_List llList2List(LSL_List src, int start, int end)
  5086. {
  5087. m_host.AddScriptLPS(1);
  5088. return src.GetSublist(start, end);
  5089. }
  5090. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  5091. {
  5092. return src.DeleteSublist(start, end);
  5093. }
  5094. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  5095. {
  5096. m_host.AddScriptLPS(1);
  5097. if (index < 0)
  5098. {
  5099. index = src.Length + index;
  5100. }
  5101. if (index >= src.Length)
  5102. {
  5103. return 0;
  5104. }
  5105. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  5106. return 1;
  5107. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  5108. return 2;
  5109. if (src.Data[index] is LSL_String || src.Data[index] is String)
  5110. {
  5111. UUID tuuid;
  5112. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  5113. {
  5114. return 4;
  5115. }
  5116. else
  5117. {
  5118. return 3;
  5119. }
  5120. }
  5121. if (src.Data[index] is LSL_Vector)
  5122. return 5;
  5123. if (src.Data[index] is LSL_Rotation)
  5124. return 6;
  5125. if (src.Data[index] is LSL_List)
  5126. return 7;
  5127. return 0;
  5128. }
  5129. /// <summary>
  5130. /// Process the supplied list and return the
  5131. /// content of the list formatted as a comma
  5132. /// separated list. There is a space after
  5133. /// each comma.
  5134. /// </summary>
  5135. public LSL_String llList2CSV(LSL_List src)
  5136. {
  5137. m_host.AddScriptLPS(1);
  5138. return string.Join(", ",
  5139. (new List<object>(src.Data)).ConvertAll<string>(o =>
  5140. {
  5141. return o.ToString();
  5142. }).ToArray());
  5143. }
  5144. /// <summary>
  5145. /// The supplied string is scanned for commas
  5146. /// and converted into a list. Commas are only
  5147. /// effective if they are encountered outside
  5148. /// of '<' '>' delimiters. Any whitespace
  5149. /// before or after an element is trimmed.
  5150. /// </summary>
  5151. public LSL_List llCSV2List(string src)
  5152. {
  5153. LSL_List result = new LSL_List();
  5154. int parens = 0;
  5155. int start = 0;
  5156. int length = 0;
  5157. m_host.AddScriptLPS(1);
  5158. for (int i = 0; i < src.Length; i++)
  5159. {
  5160. switch (src[i])
  5161. {
  5162. case '<':
  5163. parens++;
  5164. length++;
  5165. break;
  5166. case '>':
  5167. if (parens > 0)
  5168. parens--;
  5169. length++;
  5170. break;
  5171. case ',':
  5172. if (parens == 0)
  5173. {
  5174. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5175. start += length+1;
  5176. length = 0;
  5177. }
  5178. else
  5179. {
  5180. length++;
  5181. }
  5182. break;
  5183. default:
  5184. length++;
  5185. break;
  5186. }
  5187. }
  5188. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5189. return result;
  5190. }
  5191. /// <summary>
  5192. /// Randomizes the list, be arbitrarily reordering
  5193. /// sublists of stride elements. As the stride approaches
  5194. /// the size of the list, the options become very
  5195. /// limited.
  5196. /// </summary>
  5197. /// <remarks>
  5198. /// This could take a while for very large list
  5199. /// sizes.
  5200. /// </remarks>
  5201. public LSL_List llListRandomize(LSL_List src, int stride)
  5202. {
  5203. LSL_List result;
  5204. BetterRandom rand = new BetterRandom();
  5205. int chunkk;
  5206. int[] chunks;
  5207. m_host.AddScriptLPS(1);
  5208. if (stride <= 0)
  5209. {
  5210. stride = 1;
  5211. }
  5212. // Stride MUST be a factor of the list length
  5213. // If not, then return the src list. This also
  5214. // traps those cases where stride > length.
  5215. if (src.Length != stride && src.Length % stride == 0)
  5216. {
  5217. chunkk = src.Length/stride;
  5218. chunks = new int[chunkk];
  5219. for (int i = 0; i < chunkk; i++)
  5220. {
  5221. chunks[i] = i;
  5222. }
  5223. // Knuth shuffle the chunkk index
  5224. for (int i = chunkk - 1; i > 0; i--)
  5225. {
  5226. // Elect an unrandomized chunk to swap
  5227. int index = rand.Next(i + 1);
  5228. // and swap position with first unrandomized chunk
  5229. int tmp = chunks[i];
  5230. chunks[i] = chunks[index];
  5231. chunks[index] = tmp;
  5232. }
  5233. // Construct the randomized list
  5234. result = new LSL_List();
  5235. for (int i = 0; i < chunkk; i++)
  5236. {
  5237. for (int j = 0; j < stride; j++)
  5238. {
  5239. result.Add(src.Data[chunks[i] * stride + j]);
  5240. }
  5241. }
  5242. }
  5243. else
  5244. {
  5245. object[] array = new object[src.Length];
  5246. Array.Copy(src.Data, 0, array, 0, src.Length);
  5247. result = new LSL_List(array);
  5248. }
  5249. return result;
  5250. }
  5251. /// <summary>
  5252. /// Elements in the source list starting with 0 and then
  5253. /// every i+stride. If the stride is negative then the scan
  5254. /// is backwards producing an inverted result.
  5255. /// Only those elements that are also in the specified
  5256. /// range are included in the result.
  5257. /// </summary>
  5258. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  5259. {
  5260. LSL_List result = new LSL_List();
  5261. int[] si = new int[2];
  5262. int[] ei = new int[2];
  5263. bool twopass = false;
  5264. m_host.AddScriptLPS(1);
  5265. // First step is always to deal with negative indices
  5266. if (start < 0)
  5267. start = src.Length+start;
  5268. if (end < 0)
  5269. end = src.Length+end;
  5270. // Out of bounds indices are OK, just trim them
  5271. // accordingly
  5272. if (start > src.Length)
  5273. start = src.Length;
  5274. if (end > src.Length)
  5275. end = src.Length;
  5276. if (stride == 0)
  5277. stride = 1;
  5278. // There may be one or two ranges to be considered
  5279. if (start != end)
  5280. {
  5281. if (start <= end)
  5282. {
  5283. si[0] = start;
  5284. ei[0] = end;
  5285. }
  5286. else
  5287. {
  5288. si[1] = start;
  5289. ei[1] = src.Length;
  5290. si[0] = 0;
  5291. ei[0] = end;
  5292. twopass = true;
  5293. }
  5294. // The scan always starts from the beginning of the
  5295. // source list, but members are only selected if they
  5296. // fall within the specified sub-range. The specified
  5297. // range values are inclusive.
  5298. // A negative stride reverses the direction of the
  5299. // scan producing an inverted list as a result.
  5300. if (stride > 0)
  5301. {
  5302. for (int i = 0; i < src.Length; i += stride)
  5303. {
  5304. if (i<=ei[0] && i>=si[0])
  5305. result.Add(src.Data[i]);
  5306. if (twopass && i>=si[1] && i<=ei[1])
  5307. result.Add(src.Data[i]);
  5308. }
  5309. }
  5310. else if (stride < 0)
  5311. {
  5312. for (int i = src.Length - 1; i >= 0; i += stride)
  5313. {
  5314. if (i <= ei[0] && i >= si[0])
  5315. result.Add(src.Data[i]);
  5316. if (twopass && i >= si[1] && i <= ei[1])
  5317. result.Add(src.Data[i]);
  5318. }
  5319. }
  5320. }
  5321. else
  5322. {
  5323. if (start%stride == 0)
  5324. {
  5325. result.Add(src.Data[start]);
  5326. }
  5327. }
  5328. return result;
  5329. }
  5330. public LSL_Integer llGetRegionAgentCount()
  5331. {
  5332. m_host.AddScriptLPS(1);
  5333. int count = 0;
  5334. World.ForEachRootScenePresence(delegate(ScenePresence sp) {
  5335. count++;
  5336. });
  5337. return new LSL_Integer(count);
  5338. }
  5339. public LSL_Vector llGetRegionCorner()
  5340. {
  5341. m_host.AddScriptLPS(1);
  5342. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  5343. }
  5344. public LSL_String llGetEnv(LSL_String name)
  5345. {
  5346. m_host.AddScriptLPS(1);
  5347. if (name == "agent_limit")
  5348. {
  5349. return World.RegionInfo.RegionSettings.AgentLimit.ToString();
  5350. }
  5351. else if (name == "dynamic_pathfinding")
  5352. {
  5353. return "0";
  5354. }
  5355. else if (name == "estate_id")
  5356. {
  5357. return World.RegionInfo.EstateSettings.EstateID.ToString();
  5358. }
  5359. else if (name == "estate_name")
  5360. {
  5361. return World.RegionInfo.EstateSettings.EstateName;
  5362. }
  5363. else if (name == "frame_number")
  5364. {
  5365. return World.Frame.ToString();
  5366. }
  5367. else if (name == "region_cpu_ratio")
  5368. {
  5369. return "1";
  5370. }
  5371. else if (name == "region_idle")
  5372. {
  5373. return "0";
  5374. }
  5375. else if (name == "region_product_name")
  5376. {
  5377. if (World.RegionInfo.RegionType != String.Empty)
  5378. return World.RegionInfo.RegionType;
  5379. else
  5380. return "";
  5381. }
  5382. else if (name == "region_product_sku")
  5383. {
  5384. return "OpenSim";
  5385. }
  5386. else if (name == "region_start_time")
  5387. {
  5388. return World.UnixStartTime.ToString();
  5389. }
  5390. else if (name == "sim_channel")
  5391. {
  5392. return "OpenSim";
  5393. }
  5394. else if (name == "sim_version")
  5395. {
  5396. return World.GetSimulatorVersion();
  5397. }
  5398. else if (name == "simulator_hostname")
  5399. {
  5400. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  5401. return UrlModule.ExternalHostNameForLSL;
  5402. }
  5403. else if (name == "region_max_prims")
  5404. {
  5405. return World.RegionInfo.ObjectCapacity.ToString();
  5406. }
  5407. else if (name == "region_object_bonus")
  5408. {
  5409. return World.RegionInfo.RegionSettings.ObjectBonus.ToString();
  5410. }
  5411. else
  5412. {
  5413. return "";
  5414. }
  5415. }
  5416. /// <summary>
  5417. /// Insert the list identified by <paramref name="src"/> into the
  5418. /// list designated by <paramref name="dest"/> such that the first
  5419. /// new element has the index specified by <paramref name="index"/>
  5420. /// </summary>
  5421. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  5422. {
  5423. LSL_List pref;
  5424. LSL_List suff;
  5425. m_host.AddScriptLPS(1);
  5426. if (index < 0)
  5427. {
  5428. index = index+dest.Length;
  5429. if (index < 0)
  5430. {
  5431. index = 0;
  5432. }
  5433. }
  5434. if (index != 0)
  5435. {
  5436. pref = dest.GetSublist(0,index-1);
  5437. if (index < dest.Length)
  5438. {
  5439. suff = dest.GetSublist(index,-1);
  5440. return pref + src + suff;
  5441. }
  5442. else
  5443. {
  5444. return pref + src;
  5445. }
  5446. }
  5447. else
  5448. {
  5449. if (index < dest.Length)
  5450. {
  5451. suff = dest.GetSublist(index,-1);
  5452. return src + suff;
  5453. }
  5454. else
  5455. {
  5456. return src;
  5457. }
  5458. }
  5459. }
  5460. /// <summary>
  5461. /// Returns the index of the first occurrence of test
  5462. /// in src.
  5463. /// </summary>
  5464. /// <param name="src">Source list</param>
  5465. /// <param name="test">List to search for</param>
  5466. /// <returns>
  5467. /// The index number of the point in src where test was found if it was found.
  5468. /// Otherwise returns -1
  5469. /// </returns>
  5470. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  5471. {
  5472. int index = -1;
  5473. int length = src.Length - test.Length + 1;
  5474. m_host.AddScriptLPS(1);
  5475. // If either list is empty, do not match
  5476. if (src.Length != 0 && test.Length != 0)
  5477. {
  5478. for (int i = 0; i < length; i++)
  5479. {
  5480. int needle = llGetListEntryType(test, 0).value;
  5481. int haystack = llGetListEntryType(src, i).value;
  5482. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  5483. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  5484. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  5485. // Therefore, here we test Equals on both the source and destination objects.
  5486. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  5487. if ((needle == haystack) && (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])))
  5488. {
  5489. int j;
  5490. for (j = 1; j < test.Length; j++)
  5491. {
  5492. needle = llGetListEntryType(test, j).value;
  5493. haystack = llGetListEntryType(src, i+j).value;
  5494. if ((needle != haystack) || (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))))
  5495. break;
  5496. }
  5497. if (j == test.Length)
  5498. {
  5499. index = i;
  5500. break;
  5501. }
  5502. }
  5503. }
  5504. }
  5505. return index;
  5506. }
  5507. public LSL_String llGetObjectName()
  5508. {
  5509. m_host.AddScriptLPS(1);
  5510. return m_host.Name !=null ? m_host.Name : String.Empty;
  5511. }
  5512. public void llSetObjectName(string name)
  5513. {
  5514. m_host.AddScriptLPS(1);
  5515. m_host.Name = name != null ? name : String.Empty;
  5516. }
  5517. public LSL_String llGetDate()
  5518. {
  5519. m_host.AddScriptLPS(1);
  5520. DateTime date = DateTime.Now.ToUniversalTime();
  5521. string result = date.ToString("yyyy-MM-dd");
  5522. return result;
  5523. }
  5524. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  5525. {
  5526. m_host.AddScriptLPS(1);
  5527. if(dir.x == 0 && dir.y == 0)
  5528. return 1; // SL wiki
  5529. float rsx = World.RegionInfo.RegionSizeX;
  5530. float rsy = World.RegionInfo.RegionSizeY;
  5531. // can understand what sl does if position is not in region, so do something :)
  5532. float px = (float)Util.Clamp(pos.x, 0.5, rsx - 0.5);
  5533. float py = (float)Util.Clamp(pos.y, 0.5, rsy - 0.5);
  5534. float ex, ey;
  5535. if (dir.x == 0)
  5536. {
  5537. ex = px;
  5538. ey = dir.y > 0 ? rsy + 1.0f : -1.0f;
  5539. }
  5540. else if(dir.y == 0)
  5541. {
  5542. ex = dir.x > 0 ? rsx + 1.0f : -1.0f;
  5543. ey = py;
  5544. }
  5545. else
  5546. {
  5547. float dx = (float) dir.x;
  5548. float dy = (float) dir.y;
  5549. float t1 = dx * dx + dy * dy;
  5550. t1 = (float)Math.Sqrt(t1);
  5551. dx /= t1;
  5552. dy /= t1;
  5553. if(dx > 0)
  5554. t1 = (rsx + 1f - px)/dx;
  5555. else
  5556. t1 = -(px + 1f)/dx;
  5557. float t2;
  5558. if(dy > 0)
  5559. t2 = (rsy + 1f - py)/dy;
  5560. else
  5561. t2 = -(py + 1f)/dy;
  5562. if(t1 > t2)
  5563. t1 = t2;
  5564. ex = px + t1 * dx;
  5565. ey = py + t1 * dy;
  5566. }
  5567. ex += World.RegionInfo.WorldLocX;
  5568. ey += World.RegionInfo.WorldLocY;
  5569. if(World.GridService.GetRegionByPosition(World.RegionInfo.ScopeID, (int)ex, (int)ey) != null)
  5570. return 0;
  5571. return 1;
  5572. }
  5573. /// <summary>
  5574. /// Not fully implemented yet. Still to do:-
  5575. /// AGENT_BUSY
  5576. /// Remove as they are done
  5577. /// </summary>
  5578. public LSL_Integer llGetAgentInfo(string id)
  5579. {
  5580. m_host.AddScriptLPS(1);
  5581. UUID key = new UUID();
  5582. if (!UUID.TryParse(id, out key))
  5583. {
  5584. return 0;
  5585. }
  5586. int flags = 0;
  5587. ScenePresence agent = World.GetScenePresence(key);
  5588. if (agent == null)
  5589. {
  5590. return 0;
  5591. }
  5592. if (agent.IsChildAgent)
  5593. return 0; // Fail if they are not in the same region
  5594. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  5595. if (agent.SetAlwaysRun)
  5596. {
  5597. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  5598. }
  5599. if (agent.HasAttachments())
  5600. {
  5601. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  5602. if (agent.HasScriptedAttachments())
  5603. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  5604. }
  5605. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  5606. {
  5607. flags |= ScriptBaseClass.AGENT_FLYING;
  5608. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  5609. }
  5610. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  5611. {
  5612. flags |= ScriptBaseClass.AGENT_AWAY;
  5613. }
  5614. UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
  5615. UUID[] anims = agent.Animator.GetAnimationArray();
  5616. if (Array.Exists<UUID>(anims, a => { return a == busy; }))
  5617. {
  5618. flags |= ScriptBaseClass.AGENT_BUSY;
  5619. }
  5620. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  5621. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  5622. {
  5623. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  5624. }
  5625. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  5626. {
  5627. flags |= ScriptBaseClass.AGENT_TYPING;
  5628. }
  5629. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5630. if (agentMovementAnimation == "CROUCH")
  5631. {
  5632. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5633. }
  5634. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5635. {
  5636. flags |= ScriptBaseClass.AGENT_WALKING;
  5637. }
  5638. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5639. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5640. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5641. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5642. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5643. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5644. {
  5645. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5646. }
  5647. if (agent.ParentPart != null)
  5648. {
  5649. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5650. flags |= ScriptBaseClass.AGENT_SITTING;
  5651. }
  5652. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5653. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  5654. {
  5655. flags |= ScriptBaseClass.AGENT_SITTING;
  5656. }
  5657. if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
  5658. {
  5659. flags |= ScriptBaseClass.AGENT_MALE;
  5660. }
  5661. return flags;
  5662. }
  5663. public LSL_String llGetAgentLanguage(string id)
  5664. {
  5665. // This should only return a value if the avatar is in the same region, but eh. idc.
  5666. m_host.AddScriptLPS(1);
  5667. if (World.AgentPreferencesService == null)
  5668. {
  5669. Error("llGetAgentLanguage", "No AgentPreferencesService present");
  5670. }
  5671. else
  5672. {
  5673. UUID key = new UUID();
  5674. if (UUID.TryParse(id, out key))
  5675. {
  5676. return new LSL_String(World.AgentPreferencesService.GetLang(key));
  5677. }
  5678. }
  5679. return new LSL_String("en-us");
  5680. }
  5681. /// <summary>
  5682. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5683. /// The list of options is currently not used in SL
  5684. /// scope is one of:-
  5685. /// AGENT_LIST_REGION - all in the region
  5686. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5687. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5688. /// current parcel.
  5689. /// AGENT_LIST_EXCLUDENPC ignore NPCs (bit mask)
  5690. /// </summary>
  5691. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5692. {
  5693. m_host.AddScriptLPS(1);
  5694. // do our bit masks part
  5695. bool noNPC = (scope & ScriptBaseClass.AGENT_LIST_EXCLUDENPC) !=0;
  5696. // remove bit masks part
  5697. scope &= ~ ScriptBaseClass.AGENT_LIST_EXCLUDENPC;
  5698. // the constants are 1, 2 and 4 so bits are being set, but you
  5699. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5700. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5701. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5702. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5703. LSL_List result = new LSL_List();
  5704. if (!regionWide && !parcelOwned && !parcel)
  5705. {
  5706. result.Add("INVALID_SCOPE");
  5707. return result;
  5708. }
  5709. ILandObject land;
  5710. UUID id = UUID.Zero;
  5711. if (parcel || parcelOwned)
  5712. {
  5713. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5714. if (land == null)
  5715. {
  5716. id = UUID.Zero;
  5717. }
  5718. else
  5719. {
  5720. if (parcelOwned)
  5721. {
  5722. id = land.LandData.OwnerID;
  5723. }
  5724. else
  5725. {
  5726. id = land.LandData.GlobalID;
  5727. }
  5728. }
  5729. }
  5730. World.ForEachRootScenePresence(
  5731. delegate (ScenePresence ssp)
  5732. {
  5733. if(noNPC && ssp.IsNPC)
  5734. return;
  5735. // Gods are not listed in SL
  5736. if (!ssp.IsDeleted && !ssp.IsViewerUIGod && !ssp.IsChildAgent)
  5737. {
  5738. if (!regionWide)
  5739. {
  5740. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5741. if (land != null)
  5742. {
  5743. if (parcelOwned && land.LandData.OwnerID == id ||
  5744. parcel && land.LandData.GlobalID == id)
  5745. {
  5746. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5747. }
  5748. }
  5749. }
  5750. else
  5751. {
  5752. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5753. }
  5754. }
  5755. // Maximum of 100 results
  5756. if (result.Length > 99)
  5757. {
  5758. return;
  5759. }
  5760. }
  5761. );
  5762. return result;
  5763. }
  5764. public void llAdjustSoundVolume(double volume)
  5765. {
  5766. m_host.AddScriptLPS(1);
  5767. m_host.AdjustSoundGain(volume);
  5768. ScriptSleep(m_sleepMsOnAdjustSoundVolume);
  5769. }
  5770. public void llSetSoundRadius(double radius)
  5771. {
  5772. m_host.AddScriptLPS(1);
  5773. m_host.SoundRadius = radius;
  5774. }
  5775. public LSL_String llKey2Name(string id)
  5776. {
  5777. m_host.AddScriptLPS(1);
  5778. UUID key = new UUID();
  5779. if (UUID.TryParse(id,out key))
  5780. {
  5781. ScenePresence presence = World.GetScenePresence(key);
  5782. if (presence != null)
  5783. {
  5784. return presence.ControllingClient.Name;
  5785. //return presence.Name;
  5786. }
  5787. if (World.GetSceneObjectPart(key) != null)
  5788. {
  5789. return World.GetSceneObjectPart(key).Name;
  5790. }
  5791. }
  5792. return String.Empty;
  5793. }
  5794. public LSL_Key llName2Key(LSL_String name)
  5795. {
  5796. m_host.AddScriptLPS(1);
  5797. foreach (ScenePresence sp in World.GetScenePresences())
  5798. {
  5799. if (sp.IsDeleted || sp.IsChildAgent)
  5800. continue;
  5801. string test = sp.ControllingClient.Name;
  5802. if (!name.Contains(" "))
  5803. test = test.Replace(" ", ".");
  5804. if (String.Compare(name, test, true) == 0)
  5805. return sp.UUID.ToString();
  5806. }
  5807. return UUID.Zero.ToString();
  5808. }
  5809. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5810. {
  5811. m_host.AddScriptLPS(1);
  5812. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5813. }
  5814. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5815. {
  5816. m_host.AddScriptLPS(1);
  5817. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5818. try
  5819. {
  5820. foreach (SceneObjectPart part in parts)
  5821. {
  5822. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5823. }
  5824. }
  5825. finally
  5826. {
  5827. }
  5828. }
  5829. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5830. {
  5831. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  5832. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  5833. //ALL_SIDES
  5834. if (face == ScriptBaseClass.ALL_SIDES)
  5835. face = 255;
  5836. pTexAnim.Face = (uint)face;
  5837. pTexAnim.Length = (float)length;
  5838. pTexAnim.Rate = (float)rate;
  5839. pTexAnim.SizeX = (uint)sizex;
  5840. pTexAnim.SizeY = (uint)sizey;
  5841. pTexAnim.Start = (float)start;
  5842. part.AddTextureAnimation(pTexAnim);
  5843. part.SendFullUpdateToAllClients();
  5844. part.ParentGroup.HasGroupChanged = true;
  5845. }
  5846. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5847. LSL_Vector bottom_south_west)
  5848. {
  5849. m_host.AddScriptLPS(1);
  5850. if (m_SoundModule != null)
  5851. {
  5852. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5853. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5854. bottom_south_west, top_north_east);
  5855. }
  5856. }
  5857. public void llEjectFromLand(LSL_Key pest)
  5858. {
  5859. m_host.AddScriptLPS(1);
  5860. UUID agentID = new UUID();
  5861. if (UUID.TryParse(pest, out agentID))
  5862. {
  5863. ScenePresence presence = World.GetScenePresence(agentID);
  5864. if (presence != null)
  5865. {
  5866. // agent must be over the owners land
  5867. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  5868. if (land == null)
  5869. return;
  5870. if (m_host.OwnerID == land.LandData.OwnerID)
  5871. {
  5872. Vector3 p = World.GetNearestAllowedPosition(presence, land);
  5873. presence.TeleportOnEject(p);
  5874. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  5875. }
  5876. }
  5877. }
  5878. ScriptSleep(m_sleepMsOnEjectFromLand);
  5879. }
  5880. public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
  5881. {
  5882. return ParseString2List(str, separators, in_spacers, false);
  5883. }
  5884. public LSL_Integer llOverMyLand(string id)
  5885. {
  5886. m_host.AddScriptLPS(1);
  5887. UUID key = new UUID();
  5888. if (UUID.TryParse(id, out key))
  5889. {
  5890. try
  5891. {
  5892. ScenePresence presence = World.GetScenePresence(key);
  5893. if (presence != null) // object is an avatar
  5894. {
  5895. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  5896. return 1;
  5897. }
  5898. else // object is not an avatar
  5899. {
  5900. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5901. if (obj != null &&
  5902. m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  5903. return 1;
  5904. }
  5905. }
  5906. catch { }
  5907. }
  5908. return 0;
  5909. }
  5910. public LSL_Key llGetLandOwnerAt(LSL_Vector pos)
  5911. {
  5912. m_host.AddScriptLPS(1);
  5913. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5914. if (land == null)
  5915. return UUID.Zero.ToString();
  5916. return land.LandData.OwnerID.ToString();
  5917. }
  5918. /// <summary>
  5919. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  5920. /// only the height of avatars vary and that says:
  5921. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  5922. /// </summary>
  5923. public LSL_Vector llGetAgentSize(string id)
  5924. {
  5925. m_host.AddScriptLPS(1);
  5926. ScenePresence avatar = World.GetScenePresence((UUID)id);
  5927. LSL_Vector agentSize;
  5928. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  5929. {
  5930. agentSize = ScriptBaseClass.ZERO_VECTOR;
  5931. }
  5932. else
  5933. {
  5934. // agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
  5935. Vector3 s = avatar.Appearance.AvatarSize;
  5936. agentSize = new LSL_Vector(s.X, s.Y, s.Z);
  5937. }
  5938. return agentSize;
  5939. }
  5940. public LSL_Integer llSameGroup(string id)
  5941. {
  5942. m_host.AddScriptLPS(1);
  5943. UUID uuid = new UUID();
  5944. if (!UUID.TryParse(id, out uuid))
  5945. return new LSL_Integer(0);
  5946. // Check if it's a group key
  5947. if (uuid == m_host.ParentGroup.RootPart.GroupID)
  5948. return new LSL_Integer(1);
  5949. // Handle object case
  5950. SceneObjectPart part = World.GetSceneObjectPart(uuid);
  5951. if (part != null)
  5952. {
  5953. if(part.ParentGroup.IsAttachment)
  5954. {
  5955. uuid = part.ParentGroup.AttachedAvatar;
  5956. }
  5957. else
  5958. {
  5959. // This will handle both deed and non-deed and also the no
  5960. // group case
  5961. if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
  5962. return new LSL_Integer(1);
  5963. return new LSL_Integer(0);
  5964. }
  5965. }
  5966. // Handle the case where id names an avatar
  5967. ScenePresence presence = World.GetScenePresence(uuid);
  5968. if (presence != null)
  5969. {
  5970. if (presence.IsChildAgent)
  5971. return new LSL_Integer(0);
  5972. IClientAPI client = presence.ControllingClient;
  5973. if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
  5974. return new LSL_Integer(1);
  5975. return new LSL_Integer(0);
  5976. }
  5977. return new LSL_Integer(0);
  5978. }
  5979. public void llUnSit(string id)
  5980. {
  5981. m_host.AddScriptLPS(1);
  5982. UUID key = new UUID();
  5983. if (UUID.TryParse(id, out key))
  5984. {
  5985. ScenePresence av = World.GetScenePresence(key);
  5986. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  5987. if (av != null)
  5988. {
  5989. if (sittingAvatars.Contains(av))
  5990. {
  5991. // if the avatar is sitting on this object, then
  5992. // we can unsit them. We don't want random scripts unsitting random people
  5993. // Lets avoid the popcorn avatar scenario.
  5994. av.StandUp();
  5995. }
  5996. else
  5997. {
  5998. // If the object owner also owns the parcel
  5999. // or
  6000. // if the land is group owned and the object is group owned by the same group
  6001. // or
  6002. // if the object is owned by a person with estate access.
  6003. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  6004. if (parcel != null)
  6005. {
  6006. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  6007. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  6008. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  6009. {
  6010. av.StandUp();
  6011. }
  6012. }
  6013. }
  6014. }
  6015. }
  6016. }
  6017. public LSL_Vector llGroundSlope(LSL_Vector offset)
  6018. {
  6019. m_host.AddScriptLPS(1);
  6020. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  6021. LSL_Vector vsn = llGroundNormal(offset);
  6022. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  6023. //the height of that point on the plane. The resulting vector gives the slope.
  6024. Vector3 vsl = vsn;
  6025. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  6026. vsl.Normalize();
  6027. //Normalization might be overkill here
  6028. vsn.x = vsl.X;
  6029. vsn.y = vsl.Y;
  6030. vsn.z = vsl.Z;
  6031. return vsn;
  6032. }
  6033. public LSL_Vector llGroundNormal(LSL_Vector offset)
  6034. {
  6035. m_host.AddScriptLPS(1);
  6036. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  6037. // Clamp to valid position
  6038. if (pos.X < 0)
  6039. pos.X = 0;
  6040. else if (pos.X >= World.Heightmap.Width)
  6041. pos.X = World.Heightmap.Width - 1;
  6042. if (pos.Y < 0)
  6043. pos.Y = 0;
  6044. else if (pos.Y >= World.Heightmap.Height)
  6045. pos.Y = World.Heightmap.Height - 1;
  6046. //Find two points in addition to the position to define a plane
  6047. Vector3 p0 = new Vector3(pos.X, pos.Y,
  6048. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6049. Vector3 p1 = new Vector3();
  6050. Vector3 p2 = new Vector3();
  6051. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  6052. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6053. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6054. else
  6055. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6056. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  6057. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  6058. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6059. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6060. else
  6061. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6062. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  6063. //Find normalized vectors from p0 to p1 and p0 to p2
  6064. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  6065. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  6066. v0.Normalize();
  6067. v1.Normalize();
  6068. //Find the cross product of the vectors (the slope normal).
  6069. Vector3 vsn = new Vector3();
  6070. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  6071. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  6072. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  6073. vsn.Normalize();
  6074. //I believe the crossproduct of two normalized vectors is a normalized vector so
  6075. //this normalization may be overkill
  6076. return new LSL_Vector(vsn);
  6077. }
  6078. public LSL_Vector llGroundContour(LSL_Vector offset)
  6079. {
  6080. m_host.AddScriptLPS(1);
  6081. LSL_Vector x = llGroundSlope(offset);
  6082. return new LSL_Vector(-x.y, x.x, 0.0);
  6083. }
  6084. public LSL_Integer llGetAttached()
  6085. {
  6086. m_host.AddScriptLPS(1);
  6087. return m_host.ParentGroup.AttachmentPoint;
  6088. }
  6089. public LSL_List llGetAttachedList(string id)
  6090. {
  6091. m_host.AddScriptLPS(1);
  6092. ScenePresence av = World.GetScenePresence((UUID)id);
  6093. if (av == null || av.IsDeleted)
  6094. return new LSL_List("NOT_FOUND");
  6095. if (av.IsChildAgent || av.IsInTransit)
  6096. return new LSL_List("NOT_ON_REGION");
  6097. LSL_List AttachmentsList = new LSL_List();
  6098. List<SceneObjectGroup> Attachments;
  6099. Attachments = av.GetAttachments();
  6100. foreach (SceneObjectGroup Attachment in Attachments)
  6101. {
  6102. if(Attachment.HasPrivateAttachmentPoint)
  6103. continue;
  6104. AttachmentsList.Add(new LSL_Key(Attachment.UUID.ToString()));
  6105. }
  6106. return AttachmentsList;
  6107. }
  6108. public virtual LSL_Integer llGetFreeMemory()
  6109. {
  6110. m_host.AddScriptLPS(1);
  6111. // Make scripts designed for Mono happy
  6112. return 65536;
  6113. }
  6114. public LSL_Integer llGetFreeURLs()
  6115. {
  6116. m_host.AddScriptLPS(1);
  6117. if (m_UrlModule != null)
  6118. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  6119. return new LSL_Integer(0);
  6120. }
  6121. public LSL_String llGetRegionName()
  6122. {
  6123. m_host.AddScriptLPS(1);
  6124. return World.RegionInfo.RegionName;
  6125. }
  6126. public LSL_Float llGetRegionTimeDilation()
  6127. {
  6128. m_host.AddScriptLPS(1);
  6129. return (double)World.TimeDilation;
  6130. }
  6131. /// <summary>
  6132. /// Returns the value reported in the client Statistics window
  6133. /// </summary>
  6134. public LSL_Float llGetRegionFPS()
  6135. {
  6136. m_host.AddScriptLPS(1);
  6137. return World.StatsReporter.LastReportedSimFPS;
  6138. }
  6139. /* particle system rules should be coming into this routine as doubles, that is
  6140. rule[0] should be an integer from this list and rule[1] should be the arg
  6141. for the same integer. wiki.secondlife.com has most of this mapping, but some
  6142. came from http://www.caligari-designs.com/p4u2
  6143. We iterate through the list for 'Count' elements, incrementing by two for each
  6144. iteration and set the members of Primitive.ParticleSystem, one at a time.
  6145. */
  6146. public enum PrimitiveRule : int
  6147. {
  6148. PSYS_PART_FLAGS = 0,
  6149. PSYS_PART_START_COLOR = 1,
  6150. PSYS_PART_START_ALPHA = 2,
  6151. PSYS_PART_END_COLOR = 3,
  6152. PSYS_PART_END_ALPHA = 4,
  6153. PSYS_PART_START_SCALE = 5,
  6154. PSYS_PART_END_SCALE = 6,
  6155. PSYS_PART_MAX_AGE = 7,
  6156. PSYS_SRC_ACCEL = 8,
  6157. PSYS_SRC_PATTERN = 9,
  6158. PSYS_SRC_INNERANGLE = 10,
  6159. PSYS_SRC_OUTERANGLE = 11,
  6160. PSYS_SRC_TEXTURE = 12,
  6161. PSYS_SRC_BURST_RATE = 13,
  6162. PSYS_SRC_BURST_PART_COUNT = 15,
  6163. PSYS_SRC_BURST_RADIUS = 16,
  6164. PSYS_SRC_BURST_SPEED_MIN = 17,
  6165. PSYS_SRC_BURST_SPEED_MAX = 18,
  6166. PSYS_SRC_MAX_AGE = 19,
  6167. PSYS_SRC_TARGET_KEY = 20,
  6168. PSYS_SRC_OMEGA = 21,
  6169. PSYS_SRC_ANGLE_BEGIN = 22,
  6170. PSYS_SRC_ANGLE_END = 23,
  6171. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  6172. PSYS_PART_BLEND_FUNC_DEST = 25,
  6173. PSYS_PART_START_GLOW = 26,
  6174. PSYS_PART_END_GLOW = 27
  6175. }
  6176. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  6177. {
  6178. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  6179. return returnval;
  6180. }
  6181. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  6182. {
  6183. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  6184. // TODO find out about the other defaults and add them here
  6185. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  6186. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  6187. ps.PartStartScaleX = 1.0f;
  6188. ps.PartStartScaleY = 1.0f;
  6189. ps.PartEndScaleX = 1.0f;
  6190. ps.PartEndScaleY = 1.0f;
  6191. ps.BurstSpeedMin = 1.0f;
  6192. ps.BurstSpeedMax = 1.0f;
  6193. ps.BurstRate = 0.1f;
  6194. ps.PartMaxAge = 10.0f;
  6195. ps.BurstPartCount = 1;
  6196. ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA;
  6197. ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA;
  6198. ps.PartStartGlow = 0.0f;
  6199. ps.PartEndGlow = 0.0f;
  6200. return ps;
  6201. }
  6202. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  6203. {
  6204. m_host.AddScriptLPS(1);
  6205. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6206. foreach (SceneObjectPart part in parts)
  6207. {
  6208. SetParticleSystem(part, rules, "llLinkParticleSystem");
  6209. }
  6210. }
  6211. public void llParticleSystem(LSL_List rules)
  6212. {
  6213. m_host.AddScriptLPS(1);
  6214. SetParticleSystem(m_host, rules, "llParticleSystem");
  6215. }
  6216. private void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc)
  6217. {
  6218. if (rules.Length == 0)
  6219. {
  6220. part.RemoveParticleSystem();
  6221. part.ParentGroup.HasGroupChanged = true;
  6222. }
  6223. else
  6224. {
  6225. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  6226. LSL_Vector tempv = new LSL_Vector();
  6227. float tempf = 0;
  6228. int tmpi = 0;
  6229. for (int i = 0; i < rules.Length; i += 2)
  6230. {
  6231. int psystype;
  6232. try
  6233. {
  6234. psystype = rules.GetLSLIntegerItem(i);
  6235. }
  6236. catch (InvalidCastException)
  6237. {
  6238. Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i));
  6239. return;
  6240. }
  6241. switch (psystype)
  6242. {
  6243. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  6244. try
  6245. {
  6246. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  6247. }
  6248. catch(InvalidCastException)
  6249. {
  6250. Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1));
  6251. return;
  6252. }
  6253. break;
  6254. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  6255. try
  6256. {
  6257. tempv = rules.GetVector3Item(i + 1);
  6258. }
  6259. catch(InvalidCastException)
  6260. {
  6261. Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6262. return;
  6263. }
  6264. prules.PartStartColor.R = (float)tempv.x;
  6265. prules.PartStartColor.G = (float)tempv.y;
  6266. prules.PartStartColor.B = (float)tempv.z;
  6267. break;
  6268. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  6269. try
  6270. {
  6271. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6272. }
  6273. catch(InvalidCastException)
  6274. {
  6275. Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6276. return;
  6277. }
  6278. prules.PartStartColor.A = tempf;
  6279. break;
  6280. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  6281. try
  6282. {
  6283. tempv = rules.GetVector3Item(i + 1);
  6284. }
  6285. catch(InvalidCastException)
  6286. {
  6287. Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6288. return;
  6289. }
  6290. prules.PartEndColor.R = (float)tempv.x;
  6291. prules.PartEndColor.G = (float)tempv.y;
  6292. prules.PartEndColor.B = (float)tempv.z;
  6293. break;
  6294. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  6295. try
  6296. {
  6297. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6298. }
  6299. catch(InvalidCastException)
  6300. {
  6301. Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6302. return;
  6303. }
  6304. prules.PartEndColor.A = tempf;
  6305. break;
  6306. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  6307. try
  6308. {
  6309. tempv = rules.GetVector3Item(i + 1);
  6310. }
  6311. catch(InvalidCastException)
  6312. {
  6313. Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6314. return;
  6315. }
  6316. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  6317. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  6318. break;
  6319. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  6320. try
  6321. {
  6322. tempv = rules.GetVector3Item(i + 1);
  6323. }
  6324. catch(InvalidCastException)
  6325. {
  6326. Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6327. return;
  6328. }
  6329. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  6330. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  6331. break;
  6332. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  6333. try
  6334. {
  6335. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6336. }
  6337. catch(InvalidCastException)
  6338. {
  6339. Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6340. return;
  6341. }
  6342. prules.PartMaxAge = tempf;
  6343. break;
  6344. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  6345. try
  6346. {
  6347. tempv = rules.GetVector3Item(i + 1);
  6348. }
  6349. catch(InvalidCastException)
  6350. {
  6351. Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1));
  6352. return;
  6353. }
  6354. prules.PartAcceleration.X = (float)tempv.x;
  6355. prules.PartAcceleration.Y = (float)tempv.y;
  6356. prules.PartAcceleration.Z = (float)tempv.z;
  6357. break;
  6358. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  6359. try
  6360. {
  6361. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6362. }
  6363. catch(InvalidCastException)
  6364. {
  6365. Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1));
  6366. return;
  6367. }
  6368. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  6369. break;
  6370. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  6371. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  6372. // client tells the difference between the two by looking at the 0x02 bit in
  6373. // the PartFlags variable.
  6374. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  6375. try
  6376. {
  6377. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6378. }
  6379. catch(InvalidCastException)
  6380. {
  6381. Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6382. return;
  6383. }
  6384. prules.InnerAngle = (float)tempf;
  6385. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6386. break;
  6387. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  6388. try
  6389. {
  6390. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6391. }
  6392. catch(InvalidCastException)
  6393. {
  6394. Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6395. return;
  6396. }
  6397. prules.OuterAngle = (float)tempf;
  6398. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6399. break;
  6400. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  6401. try
  6402. {
  6403. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6404. }
  6405. catch(InvalidCastException)
  6406. {
  6407. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1));
  6408. return;
  6409. }
  6410. prules.BlendFuncSource = (byte)tmpi;
  6411. break;
  6412. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  6413. try
  6414. {
  6415. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6416. }
  6417. catch(InvalidCastException)
  6418. {
  6419. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1));
  6420. return;
  6421. }
  6422. prules.BlendFuncDest = (byte)tmpi;
  6423. break;
  6424. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  6425. try
  6426. {
  6427. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6428. }
  6429. catch(InvalidCastException)
  6430. {
  6431. Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6432. return;
  6433. }
  6434. prules.PartStartGlow = (float)tempf;
  6435. break;
  6436. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  6437. try
  6438. {
  6439. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6440. }
  6441. catch(InvalidCastException)
  6442. {
  6443. Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6444. return;
  6445. }
  6446. prules.PartEndGlow = (float)tempf;
  6447. break;
  6448. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  6449. try
  6450. {
  6451. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  6452. }
  6453. catch(InvalidCastException)
  6454. {
  6455. Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1));
  6456. return;
  6457. }
  6458. break;
  6459. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  6460. try
  6461. {
  6462. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6463. }
  6464. catch(InvalidCastException)
  6465. {
  6466. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1));
  6467. return;
  6468. }
  6469. prules.BurstRate = (float)tempf;
  6470. break;
  6471. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  6472. try
  6473. {
  6474. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  6475. }
  6476. catch(InvalidCastException)
  6477. {
  6478. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1));
  6479. return;
  6480. }
  6481. break;
  6482. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  6483. try
  6484. {
  6485. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6486. }
  6487. catch(InvalidCastException)
  6488. {
  6489. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1));
  6490. return;
  6491. }
  6492. prules.BurstRadius = (float)tempf;
  6493. break;
  6494. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  6495. try
  6496. {
  6497. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6498. }
  6499. catch(InvalidCastException)
  6500. {
  6501. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1));
  6502. return;
  6503. }
  6504. prules.BurstSpeedMin = (float)tempf;
  6505. break;
  6506. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  6507. try
  6508. {
  6509. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6510. }
  6511. catch(InvalidCastException)
  6512. {
  6513. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1));
  6514. return;
  6515. }
  6516. prules.BurstSpeedMax = (float)tempf;
  6517. break;
  6518. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  6519. try
  6520. {
  6521. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6522. }
  6523. catch(InvalidCastException)
  6524. {
  6525. Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6526. return;
  6527. }
  6528. prules.MaxAge = (float)tempf;
  6529. break;
  6530. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  6531. UUID key = UUID.Zero;
  6532. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  6533. {
  6534. prules.Target = key;
  6535. }
  6536. else
  6537. {
  6538. prules.Target = part.UUID;
  6539. }
  6540. break;
  6541. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  6542. // AL: This is an assumption, since it is the only thing that would match.
  6543. try
  6544. {
  6545. tempv = rules.GetVector3Item(i + 1);
  6546. }
  6547. catch(InvalidCastException)
  6548. {
  6549. Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1));
  6550. return;
  6551. }
  6552. prules.AngularVelocity.X = (float)tempv.x;
  6553. prules.AngularVelocity.Y = (float)tempv.y;
  6554. prules.AngularVelocity.Z = (float)tempv.z;
  6555. break;
  6556. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  6557. try
  6558. {
  6559. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6560. }
  6561. catch(InvalidCastException)
  6562. {
  6563. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1));
  6564. return;
  6565. }
  6566. prules.InnerAngle = (float)tempf;
  6567. prules.PartFlags |= 0x02; // Set new angle format.
  6568. break;
  6569. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  6570. try
  6571. {
  6572. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6573. }
  6574. catch (InvalidCastException)
  6575. {
  6576. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1));
  6577. return;
  6578. }
  6579. prules.OuterAngle = (float)tempf;
  6580. prules.PartFlags |= 0x02; // Set new angle format.
  6581. break;
  6582. }
  6583. }
  6584. prules.CRC = 1;
  6585. part.AddNewParticleSystem(prules);
  6586. part.ParentGroup.HasGroupChanged = true;
  6587. }
  6588. part.SendFullUpdateToAllClients();
  6589. }
  6590. private float validParticleScale(float value)
  6591. {
  6592. if (value > 4.0f) return 4.0f;
  6593. return value;
  6594. }
  6595. public void llGroundRepel(double height, int water, double tau)
  6596. {
  6597. m_host.AddScriptLPS(1);
  6598. if (m_host.PhysActor != null)
  6599. {
  6600. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  6601. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  6602. PIDHoverType hoverType = PIDHoverType.Ground;
  6603. if (water != 0)
  6604. {
  6605. hoverType = PIDHoverType.GroundAndWater;
  6606. if (ground < waterLevel)
  6607. height += waterLevel;
  6608. else
  6609. height += ground;
  6610. }
  6611. else
  6612. {
  6613. height += ground;
  6614. }
  6615. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  6616. }
  6617. }
  6618. public void llGiveInventoryList(string destination, string category, LSL_List inventory)
  6619. {
  6620. m_host.AddScriptLPS(1);
  6621. UUID destID;
  6622. if (!UUID.TryParse(destination, out destID))
  6623. return;
  6624. List<UUID> itemList = new List<UUID>();
  6625. foreach (Object item in inventory.Data)
  6626. {
  6627. string rawItemString = item.ToString();
  6628. UUID itemID;
  6629. if (UUID.TryParse(rawItemString, out itemID))
  6630. {
  6631. itemList.Add(itemID);
  6632. }
  6633. else
  6634. {
  6635. TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  6636. if (taskItem != null)
  6637. itemList.Add(taskItem.ItemID);
  6638. }
  6639. }
  6640. if (itemList.Count == 0)
  6641. return;
  6642. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  6643. if (folderID == UUID.Zero)
  6644. return;
  6645. if (m_TransferModule != null)
  6646. {
  6647. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  6648. Vector3 pos = m_host.AbsolutePosition;
  6649. GridInstantMessage msg = new GridInstantMessage(World,
  6650. m_host.OwnerID, m_host.Name, destID,
  6651. (byte)InstantMessageDialog.TaskInventoryOffered,
  6652. false, string.Format("'{0}'", category),
  6653. // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06
  6654. // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  6655. folderID, false, pos,
  6656. bucket, false);
  6657. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  6658. }
  6659. }
  6660. public void llSetVehicleType(int type)
  6661. {
  6662. m_host.AddScriptLPS(1);
  6663. if (!m_host.ParentGroup.IsDeleted)
  6664. {
  6665. m_host.ParentGroup.RootPart.SetVehicleType(type);
  6666. }
  6667. }
  6668. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6669. //CFK 9/28: so these are not complete yet.
  6670. public void llSetVehicleFloatParam(int param, LSL_Float value)
  6671. {
  6672. m_host.AddScriptLPS(1);
  6673. if (!m_host.ParentGroup.IsDeleted)
  6674. {
  6675. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  6676. }
  6677. }
  6678. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6679. //CFK 9/28: so these are not complete yet.
  6680. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  6681. {
  6682. m_host.AddScriptLPS(1);
  6683. if (!m_host.ParentGroup.IsDeleted)
  6684. {
  6685. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  6686. }
  6687. }
  6688. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6689. //CFK 9/28: so these are not complete yet.
  6690. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  6691. {
  6692. m_host.AddScriptLPS(1);
  6693. if (!m_host.ParentGroup.IsDeleted)
  6694. {
  6695. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  6696. }
  6697. }
  6698. public void llSetVehicleFlags(int flags)
  6699. {
  6700. m_host.AddScriptLPS(1);
  6701. if (!m_host.ParentGroup.IsDeleted)
  6702. {
  6703. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  6704. }
  6705. }
  6706. public void llRemoveVehicleFlags(int flags)
  6707. {
  6708. m_host.AddScriptLPS(1);
  6709. if (!m_host.ParentGroup.IsDeleted)
  6710. {
  6711. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  6712. }
  6713. }
  6714. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  6715. {
  6716. // LSL quaternions can normalize to 0, normal Quaternions can't.
  6717. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  6718. rot.s = 1; // ZERO_ROTATION = 0,0,0,1
  6719. part.SitTargetPosition = offset;
  6720. part.SitTargetOrientation = rot;
  6721. part.ParentGroup.HasGroupChanged = true;
  6722. }
  6723. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  6724. {
  6725. m_host.AddScriptLPS(1);
  6726. SitTarget(m_host, offset, rot);
  6727. }
  6728. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  6729. {
  6730. m_host.AddScriptLPS(1);
  6731. if (link == ScriptBaseClass.LINK_ROOT)
  6732. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  6733. else if (link == ScriptBaseClass.LINK_THIS)
  6734. SitTarget(m_host, offset, rot);
  6735. else
  6736. {
  6737. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  6738. if (null != part)
  6739. {
  6740. SitTarget(part, offset, rot);
  6741. }
  6742. }
  6743. }
  6744. public LSL_Key llAvatarOnSitTarget()
  6745. {
  6746. m_host.AddScriptLPS(1);
  6747. return m_host.SitTargetAvatar.ToString();
  6748. }
  6749. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  6750. public LSL_Key llAvatarOnLinkSitTarget(LSL_Integer linknum)
  6751. {
  6752. m_host.AddScriptLPS(1);
  6753. if(linknum == ScriptBaseClass.LINK_SET ||
  6754. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6755. linknum == ScriptBaseClass.LINK_ALL_OTHERS ||
  6756. linknum == 0)
  6757. return UUID.Zero.ToString();
  6758. List<SceneObjectPart> parts = GetLinkParts(linknum);
  6759. if (parts.Count == 0)
  6760. return UUID.Zero.ToString();
  6761. return parts[0].SitTargetAvatar.ToString();
  6762. }
  6763. public void llAddToLandPassList(LSL_Key avatar, double hours)
  6764. {
  6765. m_host.AddScriptLPS(1);
  6766. UUID key;
  6767. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6768. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  6769. {
  6770. int expires = 0;
  6771. if (hours != 0)
  6772. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  6773. if (UUID.TryParse(avatar, out key))
  6774. {
  6775. int idx = land.LandData.ParcelAccessList.FindIndex(
  6776. delegate(LandAccessEntry e)
  6777. {
  6778. if (e.AgentID == key && e.Flags == AccessList.Access)
  6779. return true;
  6780. return false;
  6781. });
  6782. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  6783. return;
  6784. if (idx != -1)
  6785. land.LandData.ParcelAccessList.RemoveAt(idx);
  6786. LandAccessEntry entry = new LandAccessEntry();
  6787. entry.AgentID = key;
  6788. entry.Flags = AccessList.Access;
  6789. entry.Expires = expires;
  6790. land.LandData.ParcelAccessList.Add(entry);
  6791. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  6792. }
  6793. }
  6794. ScriptSleep(m_sleepMsOnAddToLandPassList);
  6795. }
  6796. public void llSetTouchText(string text)
  6797. {
  6798. m_host.AddScriptLPS(1);
  6799. m_host.TouchName = text;
  6800. }
  6801. public void llSetSitText(string text)
  6802. {
  6803. m_host.AddScriptLPS(1);
  6804. m_host.SitName = text;
  6805. }
  6806. public void llSetCameraEyeOffset(LSL_Vector offset)
  6807. {
  6808. m_host.AddScriptLPS(1);
  6809. m_host.SetCameraEyeOffset(offset);
  6810. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  6811. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  6812. }
  6813. public void llSetCameraAtOffset(LSL_Vector offset)
  6814. {
  6815. m_host.AddScriptLPS(1);
  6816. m_host.SetCameraAtOffset(offset);
  6817. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  6818. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  6819. }
  6820. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  6821. {
  6822. m_host.AddScriptLPS(1);
  6823. if (link == ScriptBaseClass.LINK_SET ||
  6824. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6825. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  6826. SceneObjectPart part = null;
  6827. switch (link)
  6828. {
  6829. case ScriptBaseClass.LINK_ROOT:
  6830. part = m_host.ParentGroup.RootPart;
  6831. break;
  6832. case ScriptBaseClass.LINK_THIS:
  6833. part = m_host;
  6834. break;
  6835. default:
  6836. part = m_host.ParentGroup.GetLinkNumPart(link);
  6837. break;
  6838. }
  6839. if (null != part)
  6840. {
  6841. part.SetCameraEyeOffset(eye);
  6842. part.SetCameraAtOffset(at);
  6843. }
  6844. }
  6845. public LSL_String llDumpList2String(LSL_List src, string seperator)
  6846. {
  6847. m_host.AddScriptLPS(1);
  6848. if (src.Length == 0)
  6849. {
  6850. return String.Empty;
  6851. }
  6852. string ret = String.Empty;
  6853. foreach (object o in src.Data)
  6854. {
  6855. ret = ret + o.ToString() + seperator;
  6856. }
  6857. ret = ret.Substring(0, ret.Length - seperator.Length);
  6858. return ret;
  6859. }
  6860. public LSL_Integer llScriptDanger(LSL_Vector pos)
  6861. {
  6862. m_host.AddScriptLPS(1);
  6863. bool result = World.LSLScriptDanger(m_host, pos);
  6864. if (result)
  6865. {
  6866. return 1;
  6867. }
  6868. else
  6869. {
  6870. return 0;
  6871. }
  6872. }
  6873. public void llDialog(LSL_Key avatar, LSL_String message, LSL_List buttons, int chat_channel)
  6874. {
  6875. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  6876. if (dm == null)
  6877. return;
  6878. m_host.AddScriptLPS(1);
  6879. UUID av = new UUID();
  6880. if (!UUID.TryParse(avatar,out av))
  6881. {
  6882. Error("llDialog", "First parameter must be a key");
  6883. return;
  6884. }
  6885. int length = buttons.Length;
  6886. if (length < 1)
  6887. {
  6888. buttons.Add(new LSL_String("Ok"));
  6889. length = 1;
  6890. }
  6891. else if (length > 12)
  6892. {
  6893. Error("llDialog", "No more than 12 buttons can be shown");
  6894. return;
  6895. }
  6896. if (message == string.Empty)
  6897. {
  6898. Error("llDialog", "Empty message");
  6899. }
  6900. else if (Encoding.UTF8.GetByteCount(message) > 512)
  6901. {
  6902. Error("llDialog", "Message longer than 512 bytes");
  6903. }
  6904. string[] buts = new string[length];
  6905. for (int i = 0; i < length; i++)
  6906. {
  6907. if (buttons.Data[i].ToString() == String.Empty)
  6908. {
  6909. Error("llDialog", "Button label cannot be blank");
  6910. return;
  6911. }
  6912. /*
  6913. if (buttons.Data[i].ToString().Length > 24)
  6914. {
  6915. Error("llDialog", "Button label cannot be longer than 24 characters");
  6916. return;
  6917. }
  6918. */
  6919. buts[i] = buttons.Data[i].ToString();
  6920. }
  6921. dm.SendDialogToUser(
  6922. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  6923. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  6924. ScriptSleep(m_sleepMsOnDialog);
  6925. }
  6926. public void llVolumeDetect(int detect)
  6927. {
  6928. m_host.AddScriptLPS(1);
  6929. if (!m_host.ParentGroup.IsDeleted)
  6930. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  6931. }
  6932. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  6933. {
  6934. m_host.AddScriptLPS(1);
  6935. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  6936. ScriptSleep(m_sleepMsOnRemoteLoadScript);
  6937. }
  6938. public void llSetRemoteScriptAccessPin(int pin)
  6939. {
  6940. m_host.AddScriptLPS(1);
  6941. m_host.ScriptAccessPin = pin;
  6942. }
  6943. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  6944. {
  6945. m_host.AddScriptLPS(1);
  6946. UUID destId = UUID.Zero;
  6947. if (!UUID.TryParse(target, out destId))
  6948. {
  6949. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  6950. return;
  6951. }
  6952. // target must be a different prim than the one containing the script
  6953. if (m_host.UUID == destId)
  6954. {
  6955. return;
  6956. }
  6957. // copy the first script found with this inventory name
  6958. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  6959. // make sure the object is a script
  6960. if (item == null || item.Type != 10)
  6961. {
  6962. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  6963. return;
  6964. }
  6965. SceneObjectPart dest = World.GetSceneObjectPart(destId);
  6966. if (dest != null)
  6967. {
  6968. if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
  6969. {
  6970. // the rest of the permission checks are done in RezScript, so check the pin there as well
  6971. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  6972. if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
  6973. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  6974. }
  6975. }
  6976. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  6977. ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
  6978. }
  6979. public void llOpenRemoteDataChannel()
  6980. {
  6981. m_host.AddScriptLPS(1);
  6982. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6983. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  6984. {
  6985. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  6986. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  6987. if (xmlRpcRouter != null)
  6988. {
  6989. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  6990. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  6991. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  6992. xmlrpcMod.Port.ToString()));
  6993. }
  6994. object[] resobj = new object[]
  6995. {
  6996. new LSL_Integer(1),
  6997. new LSL_String(channelID.ToString()),
  6998. new LSL_String(UUID.Zero.ToString()),
  6999. new LSL_String(String.Empty),
  7000. new LSL_Integer(0),
  7001. new LSL_String(String.Empty)
  7002. };
  7003. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  7004. new DetectParams[0]));
  7005. }
  7006. ScriptSleep(m_sleepMsOnOpenRemoteDataChannel);
  7007. }
  7008. public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
  7009. {
  7010. m_host.AddScriptLPS(1);
  7011. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7012. ScriptSleep(m_sleepMsOnSendRemoteData);
  7013. if (xmlrpcMod == null)
  7014. return "";
  7015. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  7016. }
  7017. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  7018. {
  7019. m_host.AddScriptLPS(1);
  7020. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7021. if (xmlrpcMod != null)
  7022. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  7023. ScriptSleep(m_sleepMsOnRemoteDataReply);
  7024. }
  7025. public void llCloseRemoteDataChannel(string channel)
  7026. {
  7027. m_host.AddScriptLPS(1);
  7028. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7029. if (xmlRpcRouter != null)
  7030. {
  7031. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  7032. }
  7033. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7034. if (xmlrpcMod != null)
  7035. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  7036. ScriptSleep(m_sleepMsOnCloseRemoteDataChannel);
  7037. }
  7038. public LSL_String llMD5String(string src, int nonce)
  7039. {
  7040. m_host.AddScriptLPS(1);
  7041. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
  7042. }
  7043. public LSL_String llSHA1String(string src)
  7044. {
  7045. m_host.AddScriptLPS(1);
  7046. return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
  7047. }
  7048. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  7049. {
  7050. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7051. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7052. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7053. return shapeBlock;
  7054. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  7055. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  7056. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  7057. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  7058. {
  7059. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  7060. }
  7061. shapeBlock.PathCurve = pathcurve;
  7062. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  7063. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  7064. if (cut.x < 0f)
  7065. {
  7066. cut.x = 0f;
  7067. }
  7068. else if (cut.x > 1f)
  7069. {
  7070. cut.x = 1f;
  7071. }
  7072. if (cut.y < 0f)
  7073. {
  7074. cut.y = 0f;
  7075. }
  7076. else if (cut.y > 1f)
  7077. {
  7078. cut.y = 1f;
  7079. }
  7080. if (cut.y - cut.x < 0.02f)
  7081. {
  7082. cut.x = cut.y - 0.02f;
  7083. if (cut.x < 0.0f)
  7084. {
  7085. cut.x = 0.0f;
  7086. cut.y = 0.02f;
  7087. }
  7088. }
  7089. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  7090. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  7091. if (hollow < 0f)
  7092. {
  7093. hollow = 0f;
  7094. }
  7095. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  7096. // Box or Tube) and the hole shape is a square, hollow is limited to
  7097. // a max of 70%. The viewer performs its own check on this value but
  7098. // we need to do it here also so llGetPrimitiveParams can have access
  7099. // to the correct value.
  7100. if (profileshape != (byte)ProfileCurve.Square &&
  7101. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  7102. {
  7103. if (hollow > 0.70f)
  7104. {
  7105. hollow = 0.70f;
  7106. }
  7107. }
  7108. // Otherwise, hollow is limited to 99%.
  7109. else
  7110. {
  7111. if (hollow > 0.99f)
  7112. {
  7113. hollow = 0.99f;
  7114. }
  7115. }
  7116. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  7117. if (twist.x < -1.0f)
  7118. {
  7119. twist.x = -1.0f;
  7120. }
  7121. else if (twist.x > 1.0f)
  7122. {
  7123. twist.x = 1.0f;
  7124. }
  7125. if (twist.y < -1.0f)
  7126. {
  7127. twist.y = -1.0f;
  7128. }
  7129. else if (twist.y > 1.0f)
  7130. {
  7131. twist.y = 1.0f;
  7132. }
  7133. tempFloat = 100.0f * (float)twist.x;
  7134. if (tempFloat >= 0)
  7135. tempFloat += 0.5f;
  7136. else
  7137. tempFloat -= 0.5f;
  7138. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  7139. tempFloat = 100.0f * (float)twist.y;
  7140. if (tempFloat >= 0)
  7141. tempFloat += 0.5f;
  7142. else
  7143. tempFloat -= 0.5f;
  7144. shapeBlock.PathTwist = (sbyte)tempFloat;
  7145. shapeBlock.ObjectLocalID = part.LocalId;
  7146. part.Shape.SculptEntry = false;
  7147. return shapeBlock;
  7148. }
  7149. // Prim type box, cylinder and prism.
  7150. 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)
  7151. {
  7152. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7153. return;
  7154. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7155. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7156. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7157. if (taper_b.x < 0f)
  7158. {
  7159. taper_b.x = 0f;
  7160. }
  7161. else if (taper_b.x > 2f)
  7162. {
  7163. taper_b.x = 2f;
  7164. }
  7165. if (taper_b.y < 0f)
  7166. {
  7167. taper_b.y = 0f;
  7168. }
  7169. else if (taper_b.y > 2f)
  7170. {
  7171. taper_b.y = 2f;
  7172. }
  7173. tempFloat = 100.0f * (2.0f - (float)taper_b.x);
  7174. if (tempFloat >= 0)
  7175. tempFloat += 0.5f;
  7176. else
  7177. tempFloat -= 0.5f;
  7178. shapeBlock.PathScaleX = (byte)tempFloat;
  7179. tempFloat = 100.0f * (2.0f - (float)taper_b.y);
  7180. if (tempFloat >= 0)
  7181. tempFloat += 0.5f;
  7182. else
  7183. tempFloat -= 0.5f;
  7184. shapeBlock.PathScaleY = (byte)tempFloat;
  7185. if (topshear.x < -0.5f)
  7186. {
  7187. topshear.x = -0.5f;
  7188. }
  7189. else if (topshear.x > 0.5f)
  7190. {
  7191. topshear.x = 0.5f;
  7192. }
  7193. if (topshear.y < -0.5f)
  7194. {
  7195. topshear.y = -0.5f;
  7196. }
  7197. else if (topshear.y > 0.5f)
  7198. {
  7199. topshear.y = 0.5f;
  7200. }
  7201. tempFloat = 100.0f * (float)topshear.x;
  7202. if (tempFloat >= 0)
  7203. tempFloat += 0.5f;
  7204. else
  7205. tempFloat -= 0.5f;
  7206. shapeBlock.PathShearX = (byte)tempFloat;
  7207. tempFloat = 100.0f * (float)topshear.y;
  7208. if (tempFloat >= 0)
  7209. tempFloat += 0.5f;
  7210. else
  7211. tempFloat -= 0.5f;
  7212. shapeBlock.PathShearY = (byte)tempFloat;
  7213. part.Shape.SculptEntry = false;
  7214. part.UpdateShape(shapeBlock);
  7215. }
  7216. // Prim type sphere.
  7217. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  7218. {
  7219. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7220. return;
  7221. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7222. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7223. // profile/path swapped for a sphere
  7224. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7225. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7226. shapeBlock.PathScaleX = 100;
  7227. shapeBlock.PathScaleY = 100;
  7228. if (dimple.x < 0f)
  7229. {
  7230. dimple.x = 0f;
  7231. }
  7232. else if (dimple.x > 1f)
  7233. {
  7234. dimple.x = 1f;
  7235. }
  7236. if (dimple.y < 0f)
  7237. {
  7238. dimple.y = 0f;
  7239. }
  7240. else if (dimple.y > 1f)
  7241. {
  7242. dimple.y = 1f;
  7243. }
  7244. if (dimple.y - dimple.x < 0.02f)
  7245. {
  7246. dimple.x = dimple.y - 0.02f;
  7247. if (dimple.x < 0.0f)
  7248. {
  7249. dimple.x = 0.0f;
  7250. dimple.y = 0.02f;
  7251. }
  7252. }
  7253. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  7254. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  7255. part.Shape.SculptEntry = false;
  7256. part.UpdateShape(shapeBlock);
  7257. }
  7258. // Prim type torus, tube and ring.
  7259. 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)
  7260. {
  7261. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7262. return;
  7263. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7264. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7265. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7266. // profile/path swapped for a torrus, tube, ring
  7267. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7268. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7269. if (holesize.x < 0.01f)
  7270. {
  7271. holesize.x = 0.01f;
  7272. }
  7273. else if (holesize.x > 1f)
  7274. {
  7275. holesize.x = 1f;
  7276. }
  7277. tempFloat = 100.0f * (2.0f - (float)holesize.x) + 0.5f;
  7278. shapeBlock.PathScaleX = (byte)tempFloat;
  7279. if (holesize.y < 0.01f)
  7280. {
  7281. holesize.y = 0.01f;
  7282. }
  7283. else if (holesize.y > 0.5f)
  7284. {
  7285. holesize.y = 0.5f;
  7286. }
  7287. tempFloat = 100.0f * (2.0f - (float)holesize.y) + 0.5f;
  7288. shapeBlock.PathScaleY = (byte)tempFloat;
  7289. if (topshear.x < -0.5f)
  7290. {
  7291. topshear.x = -0.5f;
  7292. }
  7293. else if (topshear.x > 0.5f)
  7294. {
  7295. topshear.x = 0.5f;
  7296. }
  7297. tempFloat = (float)(100.0d * topshear.x);
  7298. if (tempFloat >= 0)
  7299. tempFloat += 0.5f;
  7300. else
  7301. tempFloat -= 0.5f;
  7302. shapeBlock.PathShearX = (byte)tempFloat;
  7303. if (topshear.y < -0.5f)
  7304. {
  7305. topshear.y = -0.5f;
  7306. }
  7307. else if (topshear.y > 0.5f)
  7308. {
  7309. topshear.y = 0.5f;
  7310. }
  7311. tempFloat = (float)(100.0d * topshear.y);
  7312. if (tempFloat >= 0)
  7313. tempFloat += 0.5f;
  7314. else
  7315. tempFloat -= 0.5f;
  7316. shapeBlock.PathShearY = (byte)tempFloat;
  7317. if (profilecut.x < 0f)
  7318. {
  7319. profilecut.x = 0f;
  7320. }
  7321. else if (profilecut.x > 1f)
  7322. {
  7323. profilecut.x = 1f;
  7324. }
  7325. if (profilecut.y < 0f)
  7326. {
  7327. profilecut.y = 0f;
  7328. }
  7329. else if (profilecut.y > 1f)
  7330. {
  7331. profilecut.y = 1f;
  7332. }
  7333. if (profilecut.y - profilecut.x < 0.02f)
  7334. {
  7335. profilecut.x = profilecut.y - 0.02f;
  7336. if (profilecut.x < 0.0f)
  7337. {
  7338. profilecut.x = 0.0f;
  7339. profilecut.y = 0.02f;
  7340. }
  7341. }
  7342. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  7343. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  7344. if (taper_a.x < -1f)
  7345. {
  7346. taper_a.x = -1f;
  7347. }
  7348. if (taper_a.x > 1f)
  7349. {
  7350. taper_a.x = 1f;
  7351. }
  7352. tempFloat = 100.0f * (float)taper_a.x;
  7353. if (tempFloat >= 0)
  7354. tempFloat += 0.5f;
  7355. else
  7356. tempFloat -= 0.5f;
  7357. shapeBlock.PathTaperX = (sbyte)tempFloat;
  7358. if (taper_a.y < -1f)
  7359. {
  7360. taper_a.y = -1f;
  7361. }
  7362. else if (taper_a.y > 1f)
  7363. {
  7364. taper_a.y = 1f;
  7365. }
  7366. tempFloat = 100.0f * (float)taper_a.y;
  7367. if (tempFloat >= 0)
  7368. tempFloat += 0.5f;
  7369. else
  7370. tempFloat -= 0.5f;
  7371. shapeBlock.PathTaperY = (sbyte)tempFloat;
  7372. if (revolutions < 1f)
  7373. {
  7374. revolutions = 1f;
  7375. }
  7376. if (revolutions > 4f)
  7377. {
  7378. revolutions = 4f;
  7379. }
  7380. tempFloat = 66.66667f * (revolutions - 1.0f) + 0.5f;
  7381. shapeBlock.PathRevolutions = (byte)tempFloat;
  7382. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  7383. if (radiusoffset < 0f)
  7384. {
  7385. radiusoffset = 0f;
  7386. }
  7387. if (radiusoffset > 1f)
  7388. {
  7389. radiusoffset = 1f;
  7390. }
  7391. tempFloat = 100.0f * radiusoffset + 0.5f;
  7392. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  7393. if (skew < -0.95f)
  7394. {
  7395. skew = -0.95f;
  7396. }
  7397. if (skew > 0.95f)
  7398. {
  7399. skew = 0.95f;
  7400. }
  7401. tempFloat = 100.0f * skew;
  7402. if (tempFloat >= 0)
  7403. tempFloat += 0.5f;
  7404. else
  7405. tempFloat -= 0.5f;
  7406. shapeBlock.PathSkew = (sbyte)tempFloat;
  7407. part.Shape.SculptEntry = false;
  7408. part.UpdateShape(shapeBlock);
  7409. }
  7410. // Prim type sculpt.
  7411. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  7412. {
  7413. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7414. return;
  7415. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7416. UUID sculptId;
  7417. if (!UUID.TryParse(map, out sculptId))
  7418. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  7419. if (sculptId == UUID.Zero)
  7420. return;
  7421. shapeBlock.PathCurve = pathcurve;
  7422. shapeBlock.ObjectLocalID = part.LocalId;
  7423. shapeBlock.PathScaleX = 100;
  7424. shapeBlock.PathScaleY = 150;
  7425. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  7426. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  7427. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  7428. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  7429. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  7430. {
  7431. // default
  7432. type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  7433. }
  7434. part.Shape.SetSculptProperties((byte)type, sculptId);
  7435. part.Shape.SculptEntry = true;
  7436. part.UpdateShape(shapeBlock);
  7437. }
  7438. public void llSetPrimitiveParams(LSL_List rules)
  7439. {
  7440. m_host.AddScriptLPS(1);
  7441. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  7442. ScriptSleep(m_sleepMsOnSetPrimitiveParams);
  7443. }
  7444. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7445. {
  7446. m_host.AddScriptLPS(1);
  7447. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  7448. ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
  7449. }
  7450. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  7451. {
  7452. m_host.AddScriptLPS(1);
  7453. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  7454. }
  7455. private void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  7456. {
  7457. List<object> parts = new List<object>();
  7458. List<SceneObjectPart> prims = GetLinkParts(linknumber);
  7459. List<ScenePresence> avatars = GetLinkAvatars(linknumber);
  7460. foreach (SceneObjectPart p in prims)
  7461. parts.Add(p);
  7462. foreach (ScenePresence p in avatars)
  7463. parts.Add(p);
  7464. LSL_List remaining = new LSL_List();
  7465. uint rulesParsed = 0;
  7466. if (parts.Count > 0)
  7467. {
  7468. foreach (object part in parts)
  7469. {
  7470. if (part is SceneObjectPart)
  7471. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7472. else
  7473. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7474. }
  7475. while (remaining.Length > 2)
  7476. {
  7477. linknumber = remaining.GetLSLIntegerItem(0);
  7478. rules = remaining.GetSublist(1, -1);
  7479. parts.Clear();
  7480. prims = GetLinkParts(linknumber);
  7481. avatars = GetLinkAvatars(linknumber);
  7482. foreach (SceneObjectPart p in prims)
  7483. parts.Add(p);
  7484. foreach (ScenePresence p in avatars)
  7485. parts.Add(p);
  7486. remaining = new LSL_List();
  7487. foreach (object part in parts)
  7488. {
  7489. if (part is SceneObjectPart)
  7490. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7491. else
  7492. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7493. }
  7494. }
  7495. }
  7496. }
  7497. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  7498. {
  7499. SceneObjectGroup group = m_host.ParentGroup;
  7500. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  7501. return;
  7502. if (group.IsAttachment)
  7503. return;
  7504. if (frames.Data.Length > 0) // We are getting a new motion
  7505. {
  7506. if (group.RootPart.KeyframeMotion != null)
  7507. group.RootPart.KeyframeMotion.Delete();
  7508. group.RootPart.KeyframeMotion = null;
  7509. int idx = 0;
  7510. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  7511. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  7512. while (idx < options.Data.Length)
  7513. {
  7514. int option = (int)options.GetLSLIntegerItem(idx++);
  7515. int remain = options.Data.Length - idx;
  7516. switch (option)
  7517. {
  7518. case ScriptBaseClass.KFM_MODE:
  7519. if (remain < 1)
  7520. break;
  7521. int modeval = (int)options.GetLSLIntegerItem(idx++);
  7522. switch(modeval)
  7523. {
  7524. case ScriptBaseClass.KFM_FORWARD:
  7525. mode = KeyframeMotion.PlayMode.Forward;
  7526. break;
  7527. case ScriptBaseClass.KFM_REVERSE:
  7528. mode = KeyframeMotion.PlayMode.Reverse;
  7529. break;
  7530. case ScriptBaseClass.KFM_LOOP:
  7531. mode = KeyframeMotion.PlayMode.Loop;
  7532. break;
  7533. case ScriptBaseClass.KFM_PING_PONG:
  7534. mode = KeyframeMotion.PlayMode.PingPong;
  7535. break;
  7536. }
  7537. break;
  7538. case ScriptBaseClass.KFM_DATA:
  7539. if (remain < 1)
  7540. break;
  7541. int dataval = (int)options.GetLSLIntegerItem(idx++);
  7542. data = (KeyframeMotion.DataFormat)dataval;
  7543. break;
  7544. }
  7545. }
  7546. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  7547. idx = 0;
  7548. int elemLength = 2;
  7549. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  7550. elemLength = 3;
  7551. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  7552. while (idx < frames.Data.Length)
  7553. {
  7554. int remain = frames.Data.Length - idx;
  7555. if (remain < elemLength)
  7556. break;
  7557. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
  7558. frame.Position = null;
  7559. frame.Rotation = null;
  7560. if ((data & KeyframeMotion.DataFormat.Translation) != 0)
  7561. {
  7562. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  7563. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  7564. }
  7565. if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
  7566. {
  7567. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  7568. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  7569. q.Normalize();
  7570. frame.Rotation = q;
  7571. }
  7572. float tempf = (float)frames.GetLSLFloatItem(idx++);
  7573. frame.TimeMS = (int)(tempf * 1000.0f);
  7574. keyframes.Add(frame);
  7575. }
  7576. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  7577. group.RootPart.KeyframeMotion.Start();
  7578. }
  7579. else
  7580. {
  7581. if (group.RootPart.KeyframeMotion == null)
  7582. return;
  7583. if (options.Data.Length == 0)
  7584. {
  7585. group.RootPart.KeyframeMotion.Stop();
  7586. return;
  7587. }
  7588. int idx = 0;
  7589. while (idx < options.Data.Length)
  7590. {
  7591. int option = (int)options.GetLSLIntegerItem(idx++);
  7592. switch (option)
  7593. {
  7594. case ScriptBaseClass.KFM_COMMAND:
  7595. int cmd = (int)options.GetLSLIntegerItem(idx++);
  7596. switch (cmd)
  7597. {
  7598. case ScriptBaseClass.KFM_CMD_PLAY:
  7599. group.RootPart.KeyframeMotion.Start();
  7600. break;
  7601. case ScriptBaseClass.KFM_CMD_STOP:
  7602. group.RootPart.KeyframeMotion.Stop();
  7603. break;
  7604. case ScriptBaseClass.KFM_CMD_PAUSE:
  7605. group.RootPart.KeyframeMotion.Pause();
  7606. break;
  7607. }
  7608. break;
  7609. }
  7610. }
  7611. }
  7612. }
  7613. public LSL_List llGetPhysicsMaterial()
  7614. {
  7615. LSL_List result = new LSL_List();
  7616. result.Add(new LSL_Float(m_host.GravityModifier));
  7617. result.Add(new LSL_Float(m_host.Restitution));
  7618. result.Add(new LSL_Float(m_host.Friction));
  7619. result.Add(new LSL_Float(m_host.Density));
  7620. return result;
  7621. }
  7622. private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
  7623. float material_density, float material_friction,
  7624. float material_restitution, float material_gravity_modifier)
  7625. {
  7626. ExtraPhysicsData physdata = new ExtraPhysicsData();
  7627. physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType;
  7628. physdata.Density = part.Density;
  7629. physdata.Friction = part.Friction;
  7630. physdata.Bounce = part.Restitution;
  7631. physdata.GravitationModifier = part.GravityModifier;
  7632. if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
  7633. physdata.Density = material_density;
  7634. if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
  7635. physdata.Friction = material_friction;
  7636. if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
  7637. physdata.Bounce = material_restitution;
  7638. if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
  7639. physdata.GravitationModifier = material_gravity_modifier;
  7640. part.UpdateExtraPhysics(physdata);
  7641. }
  7642. public void llSetPhysicsMaterial(int material_bits,
  7643. LSL_Float material_gravity_modifier, LSL_Float material_restitution,
  7644. LSL_Float material_friction, LSL_Float material_density)
  7645. {
  7646. SetPhysicsMaterial(m_host, material_bits, (float)material_density, (float)material_friction, (float)material_restitution, (float)material_gravity_modifier);
  7647. }
  7648. // vector up using libomv (c&p from sop )
  7649. // vector up rotated by r
  7650. private Vector3 Zrot(Quaternion r)
  7651. {
  7652. double x, y, z, m;
  7653. m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7654. if (Math.Abs(1.0 - m) > 0.000001)
  7655. {
  7656. m = 1.0 / Math.Sqrt(m);
  7657. r.X *= (float)m;
  7658. r.Y *= (float)m;
  7659. r.Z *= (float)m;
  7660. r.W *= (float)m;
  7661. }
  7662. x = 2 * (r.X * r.Z + r.Y * r.W);
  7663. y = 2 * (-r.X * r.W + r.Y * r.Z);
  7664. z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7665. return new Vector3((float)x, (float)y, (float)z);
  7666. }
  7667. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  7668. {
  7669. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7670. return new LSL_List();
  7671. int idx = 0;
  7672. int idxStart = 0;
  7673. SceneObjectGroup parentgrp = part.ParentGroup;
  7674. bool positionChanged = false;
  7675. bool materialChanged = false;
  7676. LSL_Vector currentPosition = GetPartLocalPos(part);
  7677. try
  7678. {
  7679. while (idx < rules.Length)
  7680. {
  7681. ++rulesParsed;
  7682. int code = rules.GetLSLIntegerItem(idx++);
  7683. int remain = rules.Length - idx;
  7684. idxStart = idx;
  7685. int face;
  7686. LSL_Vector v;
  7687. switch (code)
  7688. {
  7689. case ScriptBaseClass.PRIM_POSITION:
  7690. case ScriptBaseClass.PRIM_POS_LOCAL:
  7691. if (remain < 1)
  7692. return new LSL_List();
  7693. try
  7694. {
  7695. v = rules.GetVector3Item(idx++);
  7696. }
  7697. catch(InvalidCastException)
  7698. {
  7699. if(code == ScriptBaseClass.PRIM_POSITION)
  7700. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7701. else
  7702. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7703. return new LSL_List();
  7704. }
  7705. if (part.IsRoot && !part.ParentGroup.IsAttachment)
  7706. currentPosition = GetSetPosTarget(part, v, currentPosition, true);
  7707. else
  7708. currentPosition = GetSetPosTarget(part, v, currentPosition, false);
  7709. positionChanged = true;
  7710. break;
  7711. case ScriptBaseClass.PRIM_SIZE:
  7712. if (remain < 1)
  7713. return new LSL_List();
  7714. v=rules.GetVector3Item(idx++);
  7715. SetScale(part, v);
  7716. break;
  7717. case ScriptBaseClass.PRIM_ROTATION:
  7718. if (remain < 1)
  7719. return new LSL_List();
  7720. LSL_Rotation q;
  7721. try
  7722. {
  7723. q = rules.GetQuaternionItem(idx++);
  7724. }
  7725. catch(InvalidCastException)
  7726. {
  7727. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
  7728. return new LSL_List();
  7729. }
  7730. // try to let this work as in SL...
  7731. if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
  7732. {
  7733. // special case: If we are root, rotate complete SOG to new rotation
  7734. SetRot(part, q);
  7735. }
  7736. else
  7737. {
  7738. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  7739. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  7740. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  7741. }
  7742. break;
  7743. case ScriptBaseClass.PRIM_TYPE:
  7744. if (remain < 3)
  7745. return new LSL_List();
  7746. try
  7747. {
  7748. code = (int)rules.GetLSLIntegerItem(idx++);
  7749. }
  7750. catch(InvalidCastException)
  7751. {
  7752. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  7753. return new LSL_List();
  7754. }
  7755. remain = rules.Length - idx;
  7756. float hollow;
  7757. LSL_Vector twist;
  7758. LSL_Vector taper_b;
  7759. LSL_Vector topshear;
  7760. float revolutions;
  7761. float radiusoffset;
  7762. float skew;
  7763. LSL_Vector holesize;
  7764. LSL_Vector profilecut;
  7765. switch (code)
  7766. {
  7767. case ScriptBaseClass.PRIM_TYPE_BOX:
  7768. if (remain < 6)
  7769. return new LSL_List();
  7770. try
  7771. {
  7772. face = (int)rules.GetLSLIntegerItem(idx++);
  7773. }
  7774. catch(InvalidCastException)
  7775. {
  7776. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7777. return new LSL_List();
  7778. }
  7779. try
  7780. {
  7781. v = rules.GetVector3Item(idx++); // cut
  7782. }
  7783. catch(InvalidCastException)
  7784. {
  7785. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7786. return new LSL_List();
  7787. }
  7788. try
  7789. {
  7790. hollow = (float)rules.GetLSLFloatItem(idx++);
  7791. }
  7792. catch(InvalidCastException)
  7793. {
  7794. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7795. return new LSL_List();
  7796. }
  7797. try
  7798. {
  7799. twist = rules.GetVector3Item(idx++);
  7800. }
  7801. catch(InvalidCastException)
  7802. {
  7803. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
  7804. return new LSL_List();
  7805. }
  7806. try
  7807. {
  7808. taper_b = rules.GetVector3Item(idx++);
  7809. }
  7810. catch(InvalidCastException)
  7811. {
  7812. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7813. return new LSL_List();
  7814. }
  7815. try
  7816. {
  7817. topshear = rules.GetVector3Item(idx++);
  7818. }
  7819. catch(InvalidCastException)
  7820. {
  7821. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7822. return new LSL_List();
  7823. }
  7824. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7825. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  7826. break;
  7827. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  7828. if (remain < 6)
  7829. return new LSL_List();
  7830. try
  7831. {
  7832. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7833. }
  7834. catch(InvalidCastException)
  7835. {
  7836. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7837. return new LSL_List();
  7838. }
  7839. try
  7840. {
  7841. v = rules.GetVector3Item(idx++); // cut
  7842. }
  7843. catch(InvalidCastException)
  7844. {
  7845. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7846. return new LSL_List();
  7847. }
  7848. try
  7849. {
  7850. hollow = (float)rules.GetLSLFloatItem(idx++);
  7851. }
  7852. catch(InvalidCastException)
  7853. {
  7854. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7855. return new LSL_List();
  7856. }
  7857. try
  7858. {
  7859. twist = rules.GetVector3Item(idx++);
  7860. }
  7861. catch(InvalidCastException)
  7862. {
  7863. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7864. return new LSL_List();
  7865. }
  7866. try
  7867. {
  7868. taper_b = rules.GetVector3Item(idx++);
  7869. }
  7870. catch(InvalidCastException)
  7871. {
  7872. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7873. return new LSL_List();
  7874. }
  7875. try
  7876. {
  7877. topshear = rules.GetVector3Item(idx++);
  7878. }
  7879. catch(InvalidCastException)
  7880. {
  7881. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7882. return new LSL_List();
  7883. }
  7884. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7885. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  7886. break;
  7887. case ScriptBaseClass.PRIM_TYPE_PRISM:
  7888. if (remain < 6)
  7889. return new LSL_List();
  7890. try
  7891. {
  7892. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7893. }
  7894. catch(InvalidCastException)
  7895. {
  7896. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7897. return new LSL_List();
  7898. }
  7899. try
  7900. {
  7901. v = rules.GetVector3Item(idx++); //cut
  7902. }
  7903. catch(InvalidCastException)
  7904. {
  7905. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7906. return new LSL_List();
  7907. }
  7908. try
  7909. {
  7910. hollow = (float)rules.GetLSLFloatItem(idx++);
  7911. }
  7912. catch(InvalidCastException)
  7913. {
  7914. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7915. return new LSL_List();
  7916. }
  7917. try
  7918. {
  7919. twist = rules.GetVector3Item(idx++);
  7920. }
  7921. catch(InvalidCastException)
  7922. {
  7923. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7924. return new LSL_List();
  7925. }
  7926. try
  7927. {
  7928. taper_b = rules.GetVector3Item(idx++);
  7929. }
  7930. catch(InvalidCastException)
  7931. {
  7932. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7933. return new LSL_List();
  7934. }
  7935. try
  7936. {
  7937. topshear = rules.GetVector3Item(idx++);
  7938. }
  7939. catch(InvalidCastException)
  7940. {
  7941. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7942. return new LSL_List();
  7943. }
  7944. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7945. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  7946. break;
  7947. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  7948. if (remain < 5)
  7949. return new LSL_List();
  7950. try
  7951. {
  7952. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7953. }
  7954. catch(InvalidCastException)
  7955. {
  7956. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7957. return new LSL_List();
  7958. }
  7959. try
  7960. {
  7961. v = rules.GetVector3Item(idx++); // cut
  7962. }
  7963. catch(InvalidCastException)
  7964. {
  7965. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7966. return new LSL_List();
  7967. }
  7968. try
  7969. {
  7970. hollow = (float)rules.GetLSLFloatItem(idx++);
  7971. }
  7972. catch(InvalidCastException)
  7973. {
  7974. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7975. return new LSL_List();
  7976. }
  7977. try
  7978. {
  7979. twist = rules.GetVector3Item(idx++);
  7980. }
  7981. catch(InvalidCastException)
  7982. {
  7983. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7984. return new LSL_List();
  7985. }
  7986. try
  7987. {
  7988. taper_b = rules.GetVector3Item(idx++); // dimple
  7989. }
  7990. catch(InvalidCastException)
  7991. {
  7992. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7993. return new LSL_List();
  7994. }
  7995. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  7996. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  7997. break;
  7998. case ScriptBaseClass.PRIM_TYPE_TORUS:
  7999. if (remain < 11)
  8000. return new LSL_List();
  8001. try
  8002. {
  8003. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8004. }
  8005. catch(InvalidCastException)
  8006. {
  8007. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8008. return new LSL_List();
  8009. }
  8010. try
  8011. {
  8012. v = rules.GetVector3Item(idx++); //cut
  8013. }
  8014. catch(InvalidCastException)
  8015. {
  8016. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8017. return new LSL_List();
  8018. }
  8019. try
  8020. {
  8021. hollow = (float)rules.GetLSLFloatItem(idx++);
  8022. }
  8023. catch(InvalidCastException)
  8024. {
  8025. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8026. return new LSL_List();
  8027. }
  8028. try
  8029. {
  8030. twist = rules.GetVector3Item(idx++);
  8031. }
  8032. catch(InvalidCastException)
  8033. {
  8034. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8035. return new LSL_List();
  8036. }
  8037. try
  8038. {
  8039. holesize = rules.GetVector3Item(idx++);
  8040. }
  8041. catch(InvalidCastException)
  8042. {
  8043. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8044. return new LSL_List();
  8045. }
  8046. try
  8047. {
  8048. topshear = rules.GetVector3Item(idx++);
  8049. }
  8050. catch(InvalidCastException)
  8051. {
  8052. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8053. return new LSL_List();
  8054. }
  8055. try
  8056. {
  8057. profilecut = rules.GetVector3Item(idx++);
  8058. }
  8059. catch(InvalidCastException)
  8060. {
  8061. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8062. return new LSL_List();
  8063. }
  8064. try
  8065. {
  8066. taper_b = rules.GetVector3Item(idx++); // taper_a
  8067. }
  8068. catch(InvalidCastException)
  8069. {
  8070. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8071. return new LSL_List();
  8072. }
  8073. try
  8074. {
  8075. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8076. }
  8077. catch(InvalidCastException)
  8078. {
  8079. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8080. return new LSL_List();
  8081. }
  8082. try
  8083. {
  8084. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8085. }
  8086. catch(InvalidCastException)
  8087. {
  8088. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8089. return new LSL_List();
  8090. }
  8091. try
  8092. {
  8093. skew = (float)rules.GetLSLFloatItem(idx++);
  8094. }
  8095. catch(InvalidCastException)
  8096. {
  8097. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
  8098. return new LSL_List();
  8099. }
  8100. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8101. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  8102. break;
  8103. case ScriptBaseClass.PRIM_TYPE_TUBE:
  8104. if (remain < 11)
  8105. return new LSL_List();
  8106. try
  8107. {
  8108. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8109. }
  8110. catch(InvalidCastException)
  8111. {
  8112. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8113. return new LSL_List();
  8114. }
  8115. try
  8116. {
  8117. v = rules.GetVector3Item(idx++); //cut
  8118. }
  8119. catch(InvalidCastException)
  8120. {
  8121. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8122. return new LSL_List();
  8123. }
  8124. try
  8125. {
  8126. hollow = (float)rules.GetLSLFloatItem(idx++);
  8127. }
  8128. catch(InvalidCastException)
  8129. {
  8130. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8131. return new LSL_List();
  8132. }
  8133. try
  8134. {
  8135. twist = rules.GetVector3Item(idx++);
  8136. }
  8137. catch(InvalidCastException)
  8138. {
  8139. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8140. return new LSL_List();
  8141. }
  8142. try
  8143. {
  8144. holesize = rules.GetVector3Item(idx++);
  8145. }
  8146. catch(InvalidCastException)
  8147. {
  8148. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8149. return new LSL_List();
  8150. }
  8151. try
  8152. {
  8153. topshear = rules.GetVector3Item(idx++);
  8154. }
  8155. catch(InvalidCastException)
  8156. {
  8157. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8158. return new LSL_List();
  8159. }
  8160. try
  8161. {
  8162. profilecut = rules.GetVector3Item(idx++);
  8163. }
  8164. catch(InvalidCastException)
  8165. {
  8166. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8167. return new LSL_List();
  8168. }
  8169. try
  8170. {
  8171. taper_b = rules.GetVector3Item(idx++); // taper_a
  8172. }
  8173. catch(InvalidCastException)
  8174. {
  8175. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8176. return new LSL_List();
  8177. }
  8178. try
  8179. {
  8180. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8181. }
  8182. catch(InvalidCastException)
  8183. {
  8184. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8185. return new LSL_List();
  8186. }
  8187. try
  8188. {
  8189. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8190. }
  8191. catch(InvalidCastException)
  8192. {
  8193. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8194. return new LSL_List();
  8195. }
  8196. try
  8197. {
  8198. skew = (float)rules.GetLSLFloatItem(idx++);
  8199. }
  8200. catch(InvalidCastException)
  8201. {
  8202. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8203. return new LSL_List();
  8204. }
  8205. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8206. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  8207. break;
  8208. case ScriptBaseClass.PRIM_TYPE_RING:
  8209. if (remain < 11)
  8210. return new LSL_List();
  8211. try
  8212. {
  8213. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8214. }
  8215. catch(InvalidCastException)
  8216. {
  8217. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8218. return new LSL_List();
  8219. }
  8220. try
  8221. {
  8222. v = rules.GetVector3Item(idx++); //cut
  8223. }
  8224. catch(InvalidCastException)
  8225. {
  8226. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8227. return new LSL_List();
  8228. }
  8229. try
  8230. {
  8231. hollow = (float)rules.GetLSLFloatItem(idx++);
  8232. }
  8233. catch(InvalidCastException)
  8234. {
  8235. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8236. return new LSL_List();
  8237. }
  8238. try
  8239. {
  8240. twist = rules.GetVector3Item(idx++);
  8241. }
  8242. catch(InvalidCastException)
  8243. {
  8244. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8245. return new LSL_List();
  8246. }
  8247. try
  8248. {
  8249. holesize = rules.GetVector3Item(idx++);
  8250. }
  8251. catch(InvalidCastException)
  8252. {
  8253. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8254. return new LSL_List();
  8255. }
  8256. try
  8257. {
  8258. topshear = rules.GetVector3Item(idx++);
  8259. }
  8260. catch(InvalidCastException)
  8261. {
  8262. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8263. return new LSL_List();
  8264. }
  8265. try
  8266. {
  8267. profilecut = rules.GetVector3Item(idx++);
  8268. }
  8269. catch(InvalidCastException)
  8270. {
  8271. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8272. return new LSL_List();
  8273. }
  8274. try
  8275. {
  8276. taper_b = rules.GetVector3Item(idx++); // taper_a
  8277. }
  8278. catch(InvalidCastException)
  8279. {
  8280. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8281. return new LSL_List();
  8282. }
  8283. try
  8284. {
  8285. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8286. }
  8287. catch(InvalidCastException)
  8288. {
  8289. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8290. return new LSL_List();
  8291. }
  8292. try
  8293. {
  8294. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8295. }
  8296. catch(InvalidCastException)
  8297. {
  8298. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8299. return new LSL_List();
  8300. }
  8301. try
  8302. {
  8303. skew = (float)rules.GetLSLFloatItem(idx++);
  8304. }
  8305. catch(InvalidCastException)
  8306. {
  8307. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8308. return new LSL_List();
  8309. }
  8310. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8311. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  8312. break;
  8313. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  8314. if (remain < 2)
  8315. return new LSL_List();
  8316. string map = rules.Data[idx++].ToString();
  8317. try
  8318. {
  8319. face = (int)rules.GetLSLIntegerItem(idx++); // type
  8320. }
  8321. catch(InvalidCastException)
  8322. {
  8323. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8324. return new LSL_List();
  8325. }
  8326. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  8327. break;
  8328. }
  8329. break;
  8330. case ScriptBaseClass.PRIM_TEXTURE:
  8331. if (remain < 5)
  8332. return new LSL_List();
  8333. face=(int)rules.GetLSLIntegerItem(idx++);
  8334. string tex;
  8335. LSL_Vector repeats;
  8336. LSL_Vector offsets;
  8337. double rotation;
  8338. tex = rules.Data[idx++].ToString();
  8339. try
  8340. {
  8341. repeats = rules.GetVector3Item(idx++);
  8342. }
  8343. catch(InvalidCastException)
  8344. {
  8345. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8346. return new LSL_List();
  8347. }
  8348. try
  8349. {
  8350. offsets = rules.GetVector3Item(idx++);
  8351. }
  8352. catch(InvalidCastException)
  8353. {
  8354. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8355. return new LSL_List();
  8356. }
  8357. try
  8358. {
  8359. rotation = (double)rules.GetLSLFloatItem(idx++);
  8360. }
  8361. catch(InvalidCastException)
  8362. {
  8363. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8364. return new LSL_List();
  8365. }
  8366. SetTexture(part, tex, face);
  8367. ScaleTexture(part, repeats.x, repeats.y, face);
  8368. OffsetTexture(part, offsets.x, offsets.y, face);
  8369. RotateTexture(part, rotation, face);
  8370. break;
  8371. case ScriptBaseClass.PRIM_COLOR:
  8372. if (remain < 3)
  8373. return new LSL_List();
  8374. LSL_Vector color;
  8375. double alpha;
  8376. try
  8377. {
  8378. face = (int)rules.GetLSLIntegerItem(idx++);
  8379. }
  8380. catch(InvalidCastException)
  8381. {
  8382. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8383. return new LSL_List();
  8384. }
  8385. try
  8386. {
  8387. color = rules.GetVector3Item(idx++);
  8388. }
  8389. catch(InvalidCastException)
  8390. {
  8391. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8392. return new LSL_List();
  8393. }
  8394. try
  8395. {
  8396. alpha = (double)rules.GetLSLFloatItem(idx++);
  8397. }
  8398. catch(InvalidCastException)
  8399. {
  8400. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8401. return new LSL_List();
  8402. }
  8403. part.SetFaceColorAlpha(face, color, alpha);
  8404. break;
  8405. case ScriptBaseClass.PRIM_FLEXIBLE:
  8406. if (remain < 7)
  8407. return new LSL_List();
  8408. bool flexi;
  8409. int softness;
  8410. float gravity;
  8411. float friction;
  8412. float wind;
  8413. float tension;
  8414. LSL_Vector force;
  8415. try
  8416. {
  8417. flexi = rules.GetLSLIntegerItem(idx++);
  8418. }
  8419. catch(InvalidCastException)
  8420. {
  8421. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8422. return new LSL_List();
  8423. }
  8424. try
  8425. {
  8426. softness = rules.GetLSLIntegerItem(idx++);
  8427. }
  8428. catch(InvalidCastException)
  8429. {
  8430. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8431. return new LSL_List();
  8432. }
  8433. try
  8434. {
  8435. gravity = (float)rules.GetLSLFloatItem(idx++);
  8436. }
  8437. catch(InvalidCastException)
  8438. {
  8439. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8440. return new LSL_List();
  8441. }
  8442. try
  8443. {
  8444. friction = (float)rules.GetLSLFloatItem(idx++);
  8445. }
  8446. catch(InvalidCastException)
  8447. {
  8448. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8449. return new LSL_List();
  8450. }
  8451. try
  8452. {
  8453. wind = (float)rules.GetLSLFloatItem(idx++);
  8454. }
  8455. catch(InvalidCastException)
  8456. {
  8457. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8458. return new LSL_List();
  8459. }
  8460. try
  8461. {
  8462. tension = (float)rules.GetLSLFloatItem(idx++);
  8463. }
  8464. catch(InvalidCastException)
  8465. {
  8466. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
  8467. return new LSL_List();
  8468. }
  8469. try
  8470. {
  8471. force = rules.GetVector3Item(idx++);
  8472. }
  8473. catch(InvalidCastException)
  8474. {
  8475. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8476. return new LSL_List();
  8477. }
  8478. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  8479. break;
  8480. case ScriptBaseClass.PRIM_POINT_LIGHT:
  8481. if (remain < 5)
  8482. return new LSL_List();
  8483. bool light;
  8484. LSL_Vector lightcolor;
  8485. float intensity;
  8486. float radius;
  8487. float falloff;
  8488. try
  8489. {
  8490. light = rules.GetLSLIntegerItem(idx++);
  8491. }
  8492. catch(InvalidCastException)
  8493. {
  8494. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8495. return new LSL_List();
  8496. }
  8497. try
  8498. {
  8499. lightcolor = rules.GetVector3Item(idx++);
  8500. }
  8501. catch(InvalidCastException)
  8502. {
  8503. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8504. return new LSL_List();
  8505. }
  8506. try
  8507. {
  8508. intensity = (float)rules.GetLSLFloatItem(idx++);
  8509. }
  8510. catch(InvalidCastException)
  8511. {
  8512. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8513. return new LSL_List();
  8514. }
  8515. try
  8516. {
  8517. radius = (float)rules.GetLSLFloatItem(idx++);
  8518. }
  8519. catch(InvalidCastException)
  8520. {
  8521. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8522. return new LSL_List();
  8523. }
  8524. try
  8525. {
  8526. falloff = (float)rules.GetLSLFloatItem(idx++);
  8527. }
  8528. catch(InvalidCastException)
  8529. {
  8530. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8531. return new LSL_List();
  8532. }
  8533. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  8534. break;
  8535. case ScriptBaseClass.PRIM_GLOW:
  8536. if (remain < 2)
  8537. return new LSL_List();
  8538. float glow;
  8539. try
  8540. {
  8541. face = rules.GetLSLIntegerItem(idx++);
  8542. }
  8543. catch(InvalidCastException)
  8544. {
  8545. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8546. return new LSL_List();
  8547. }
  8548. try
  8549. {
  8550. glow = (float)rules.GetLSLFloatItem(idx++);
  8551. }
  8552. catch(InvalidCastException)
  8553. {
  8554. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8555. return new LSL_List();
  8556. }
  8557. SetGlow(part, face, glow);
  8558. break;
  8559. case ScriptBaseClass.PRIM_BUMP_SHINY:
  8560. if (remain < 3)
  8561. return new LSL_List();
  8562. int shiny;
  8563. Bumpiness bump;
  8564. try
  8565. {
  8566. face = (int)rules.GetLSLIntegerItem(idx++);
  8567. }
  8568. catch(InvalidCastException)
  8569. {
  8570. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8571. return new LSL_List();
  8572. }
  8573. try
  8574. {
  8575. shiny = (int)rules.GetLSLIntegerItem(idx++);
  8576. }
  8577. catch(InvalidCastException)
  8578. {
  8579. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8580. return new LSL_List();
  8581. }
  8582. try
  8583. {
  8584. bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  8585. }
  8586. catch(InvalidCastException)
  8587. {
  8588. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8589. return new LSL_List();
  8590. }
  8591. SetShiny(part, face, shiny, bump);
  8592. break;
  8593. case ScriptBaseClass.PRIM_FULLBRIGHT:
  8594. if (remain < 2)
  8595. return new LSL_List();
  8596. bool st;
  8597. try
  8598. {
  8599. face = rules.GetLSLIntegerItem(idx++);
  8600. }
  8601. catch(InvalidCastException)
  8602. {
  8603. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8604. return new LSL_List();
  8605. }
  8606. try
  8607. {
  8608. st = rules.GetLSLIntegerItem(idx++);
  8609. }
  8610. catch(InvalidCastException)
  8611. {
  8612. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8613. return new LSL_List();
  8614. }
  8615. SetFullBright(part, face , st);
  8616. break;
  8617. case ScriptBaseClass.PRIM_MATERIAL:
  8618. if (remain < 1)
  8619. return new LSL_List();
  8620. int mat;
  8621. try
  8622. {
  8623. mat = rules.GetLSLIntegerItem(idx++);
  8624. }
  8625. catch(InvalidCastException)
  8626. {
  8627. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8628. return new LSL_List();
  8629. }
  8630. if (mat < 0 || mat > 7)
  8631. return new LSL_List();
  8632. part.Material = Convert.ToByte(mat);
  8633. break;
  8634. case ScriptBaseClass.PRIM_PHANTOM:
  8635. if (remain < 1)
  8636. return new LSL_List();
  8637. string ph = rules.Data[idx++].ToString();
  8638. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  8639. break;
  8640. case ScriptBaseClass.PRIM_PHYSICS:
  8641. if (remain < 1)
  8642. return new LSL_List();
  8643. string phy = rules.Data[idx++].ToString();
  8644. part.ScriptSetPhysicsStatus(phy.Equals("1"));
  8645. break;
  8646. case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  8647. if (remain < 1)
  8648. return new LSL_List();
  8649. int shape_type;
  8650. try
  8651. {
  8652. shape_type = rules.GetLSLIntegerItem(idx++);
  8653. }
  8654. catch(InvalidCastException)
  8655. {
  8656. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8657. return new LSL_List();
  8658. }
  8659. ExtraPhysicsData physdata = new ExtraPhysicsData();
  8660. physdata.Density = part.Density;
  8661. physdata.Bounce = part.Restitution;
  8662. physdata.GravitationModifier = part.GravityModifier;
  8663. physdata.PhysShapeType = (PhysShapeType)shape_type;
  8664. part.UpdateExtraPhysics(physdata);
  8665. break;
  8666. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  8667. if (remain < 5)
  8668. return new LSL_List();
  8669. int material_bits = rules.GetLSLIntegerItem(idx++);
  8670. float material_density = (float)rules.GetLSLFloatItem(idx++);
  8671. float material_friction = (float)rules.GetLSLFloatItem(idx++);
  8672. float material_restitution = (float)rules.GetLSLFloatItem(idx++);
  8673. float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
  8674. SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
  8675. break;
  8676. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  8677. if (remain < 1)
  8678. return new LSL_List();
  8679. string temp = rules.Data[idx++].ToString();
  8680. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  8681. break;
  8682. case ScriptBaseClass.PRIM_TEXGEN:
  8683. if (remain < 2)
  8684. return new LSL_List();
  8685. //face,type
  8686. int style;
  8687. try
  8688. {
  8689. face = rules.GetLSLIntegerItem(idx++);
  8690. }
  8691. catch(InvalidCastException)
  8692. {
  8693. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8694. return new LSL_List();
  8695. }
  8696. try
  8697. {
  8698. style = rules.GetLSLIntegerItem(idx++);
  8699. }
  8700. catch(InvalidCastException)
  8701. {
  8702. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8703. return new LSL_List();
  8704. }
  8705. SetTexGen(part, face, style);
  8706. break;
  8707. case ScriptBaseClass.PRIM_TEXT:
  8708. if (remain < 3)
  8709. return new LSL_List();
  8710. string primText;
  8711. LSL_Vector primTextColor;
  8712. LSL_Float primTextAlpha;
  8713. try
  8714. {
  8715. primText = rules.GetLSLStringItem(idx++);
  8716. }
  8717. catch(InvalidCastException)
  8718. {
  8719. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8720. return new LSL_List();
  8721. }
  8722. try
  8723. {
  8724. primTextColor = rules.GetVector3Item(idx++);
  8725. }
  8726. catch(InvalidCastException)
  8727. {
  8728. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8729. return new LSL_List();
  8730. }
  8731. try
  8732. {
  8733. primTextAlpha = rules.GetLSLFloatItem(idx++);
  8734. }
  8735. catch(InvalidCastException)
  8736. {
  8737. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8738. return new LSL_List();
  8739. }
  8740. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  8741. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  8742. break;
  8743. case ScriptBaseClass.PRIM_NAME:
  8744. if (remain < 1)
  8745. return new LSL_List();
  8746. try
  8747. {
  8748. string primName = rules.GetLSLStringItem(idx++);
  8749. part.Name = primName;
  8750. }
  8751. catch(InvalidCastException)
  8752. {
  8753. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8754. return new LSL_List();
  8755. }
  8756. break;
  8757. case ScriptBaseClass.PRIM_DESC:
  8758. if (remain < 1)
  8759. return new LSL_List();
  8760. try
  8761. {
  8762. string primDesc = rules.GetLSLStringItem(idx++);
  8763. part.Description = primDesc;
  8764. }
  8765. catch(InvalidCastException)
  8766. {
  8767. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8768. return new LSL_List();
  8769. }
  8770. break;
  8771. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8772. if (remain < 1)
  8773. return new LSL_List();
  8774. LSL_Rotation rot;
  8775. try
  8776. {
  8777. rot = rules.GetQuaternionItem(idx++);
  8778. }
  8779. catch(InvalidCastException)
  8780. {
  8781. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8782. return new LSL_List();
  8783. }
  8784. SetRot(part, rot);
  8785. break;
  8786. case ScriptBaseClass.PRIM_OMEGA:
  8787. if (remain < 3)
  8788. return new LSL_List();
  8789. LSL_Vector axis;
  8790. LSL_Float spinrate;
  8791. LSL_Float gain;
  8792. try
  8793. {
  8794. axis = rules.GetVector3Item(idx++);
  8795. }
  8796. catch(InvalidCastException)
  8797. {
  8798. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8799. return new LSL_List();
  8800. }
  8801. try
  8802. {
  8803. spinrate = rules.GetLSLFloatItem(idx++);
  8804. }
  8805. catch(InvalidCastException)
  8806. {
  8807. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8808. return new LSL_List();
  8809. }
  8810. try
  8811. {
  8812. gain = rules.GetLSLFloatItem(idx++);
  8813. }
  8814. catch(InvalidCastException)
  8815. {
  8816. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8817. return new LSL_List();
  8818. }
  8819. TargetOmega(part, axis, (double)spinrate, (double)gain);
  8820. break;
  8821. case ScriptBaseClass.PRIM_SLICE:
  8822. if (remain < 1)
  8823. return new LSL_List();
  8824. LSL_Vector slice;
  8825. try
  8826. {
  8827. slice = rules.GetVector3Item(idx++);
  8828. }
  8829. catch(InvalidCastException)
  8830. {
  8831. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8832. return new LSL_List();
  8833. }
  8834. part.UpdateSlice((float)slice.x, (float)slice.y);
  8835. break;
  8836. case ScriptBaseClass.PRIM_SIT_TARGET:
  8837. if (remain < 3)
  8838. return new LSL_List();
  8839. int active;
  8840. try
  8841. {
  8842. active = rules.GetLSLIntegerItem(idx++);
  8843. }
  8844. catch(InvalidCastException)
  8845. {
  8846. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  8847. return new LSL_List();
  8848. }
  8849. LSL_Vector offset;
  8850. try
  8851. {
  8852. offset = rules.GetVector3Item(idx++);
  8853. }
  8854. catch(InvalidCastException)
  8855. {
  8856. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8857. return new LSL_List();
  8858. }
  8859. LSL_Rotation sitrot;
  8860. try
  8861. {
  8862. sitrot = rules.GetQuaternionItem(idx++);
  8863. }
  8864. catch(InvalidCastException)
  8865. {
  8866. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 3 must be rotation", rulesParsed, idx - idxStart - 1));
  8867. return new LSL_List();
  8868. }
  8869. // not SL compatible since we don't have a independent flag to control active target but use the values of offset and rotation
  8870. if(active == 1)
  8871. {
  8872. if(offset.x == 0 && offset.y == 0 && offset.z == 0 && sitrot.s == 1.0)
  8873. offset.z = 1e-5f; // hack
  8874. SitTarget(part,offset,sitrot);
  8875. }
  8876. else if(active == 0)
  8877. SitTarget(part, Vector3.Zero , Quaternion.Identity);
  8878. break;
  8879. case ScriptBaseClass.PRIM_ALPHA_MODE:
  8880. if (remain < 3)
  8881. return new LSL_List();
  8882. try
  8883. {
  8884. face = rules.GetLSLIntegerItem(idx++);
  8885. }
  8886. catch(InvalidCastException)
  8887. {
  8888. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8889. return new LSL_List();
  8890. }
  8891. int materialAlphaMode;
  8892. try
  8893. {
  8894. materialAlphaMode = rules.GetLSLIntegerItem(idx++);
  8895. }
  8896. catch(InvalidCastException)
  8897. {
  8898. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8899. return new LSL_List();
  8900. }
  8901. if(materialAlphaMode < 0 || materialAlphaMode > 3)
  8902. {
  8903. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 3", rulesParsed, idx - idxStart - 1));
  8904. return new LSL_List();
  8905. }
  8906. int materialMaskCutoff;
  8907. try
  8908. {
  8909. materialMaskCutoff = rules.GetLSLIntegerItem(idx++);
  8910. }
  8911. catch(InvalidCastException)
  8912. {
  8913. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8914. return new LSL_List();
  8915. }
  8916. if(materialMaskCutoff < 0 || materialMaskCutoff > 255)
  8917. {
  8918. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 255", rulesParsed, idx - idxStart - 1));
  8919. return new LSL_List();
  8920. }
  8921. materialChanged |= SetMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  8922. break;
  8923. case ScriptBaseClass.PRIM_NORMAL:
  8924. if (remain < 5)
  8925. return new LSL_List();
  8926. try
  8927. {
  8928. face = rules.GetLSLIntegerItem(idx++);
  8929. }
  8930. catch(InvalidCastException)
  8931. {
  8932. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8933. return new LSL_List();
  8934. }
  8935. string mapname = rules.Data[idx++].ToString();
  8936. UUID mapID = ScriptUtils.GetAssetIdFromItemName(m_host, mapname, (int)AssetType.Texture);
  8937. if (mapID == UUID.Zero)
  8938. {
  8939. if (!UUID.TryParse(mapname, out mapID))
  8940. {
  8941. 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));
  8942. return new LSL_List();
  8943. }
  8944. }
  8945. LSL_Vector mnrepeat;
  8946. try
  8947. {
  8948. mnrepeat = rules.GetVector3Item(idx++);
  8949. }
  8950. catch(InvalidCastException)
  8951. {
  8952. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  8953. return new LSL_List();
  8954. }
  8955. LSL_Vector mnoffset;
  8956. try
  8957. {
  8958. mnoffset = rules.GetVector3Item(idx++);
  8959. }
  8960. catch(InvalidCastException)
  8961. {
  8962. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  8963. return new LSL_List();
  8964. }
  8965. LSL_Float mnrot;
  8966. try
  8967. {
  8968. mnrot = rules.GetLSLFloatItem(idx++);
  8969. }
  8970. catch(InvalidCastException)
  8971. {
  8972. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  8973. return new LSL_List();
  8974. }
  8975. float repeatX = (float)Util.Clamp(mnrepeat.x,-100.0, 100.0);
  8976. float repeatY = (float)Util.Clamp(mnrepeat.y,-100.0, 100.0);
  8977. float offsetX = (float)Util.Clamp(mnoffset.x, 0, 1.0);
  8978. float offsetY = (float)Util.Clamp(mnoffset.y, 0, 1.0);
  8979. materialChanged |= SetMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, (float)mnrot);
  8980. break;
  8981. case ScriptBaseClass.PRIM_SPECULAR:
  8982. if (remain < 8)
  8983. return new LSL_List();
  8984. try
  8985. {
  8986. face = rules.GetLSLIntegerItem(idx++);
  8987. }
  8988. catch(InvalidCastException)
  8989. {
  8990. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8991. return new LSL_List();
  8992. }
  8993. string smapname = rules.Data[idx++].ToString();
  8994. UUID smapID = ScriptUtils.GetAssetIdFromItemName(m_host, smapname, (int)AssetType.Texture);
  8995. if (smapID == UUID.Zero)
  8996. {
  8997. if (!UUID.TryParse(smapname, out smapID))
  8998. {
  8999. 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));
  9000. return new LSL_List();
  9001. }
  9002. }
  9003. LSL_Vector msrepeat;
  9004. try
  9005. {
  9006. msrepeat = rules.GetVector3Item(idx++);
  9007. }
  9008. catch(InvalidCastException)
  9009. {
  9010. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9011. return new LSL_List();
  9012. }
  9013. LSL_Vector msoffset;
  9014. try
  9015. {
  9016. msoffset = rules.GetVector3Item(idx++);
  9017. }
  9018. catch(InvalidCastException)
  9019. {
  9020. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9021. return new LSL_List();
  9022. }
  9023. LSL_Float msrot;
  9024. try
  9025. {
  9026. msrot = rules.GetLSLFloatItem(idx++);
  9027. }
  9028. catch(InvalidCastException)
  9029. {
  9030. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9031. return new LSL_List();
  9032. }
  9033. LSL_Vector mscolor;
  9034. try
  9035. {
  9036. mscolor = rules.GetVector3Item(idx++);
  9037. }
  9038. catch(InvalidCastException)
  9039. {
  9040. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9041. return new LSL_List();
  9042. }
  9043. LSL_Integer msgloss;
  9044. try
  9045. {
  9046. msgloss = rules.GetLSLIntegerItem(idx++);
  9047. }
  9048. catch(InvalidCastException)
  9049. {
  9050. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9051. return new LSL_List();
  9052. }
  9053. LSL_Integer msenv;
  9054. try
  9055. {
  9056. msenv = rules.GetLSLIntegerItem(idx++);
  9057. }
  9058. catch(InvalidCastException)
  9059. {
  9060. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9061. return new LSL_List();
  9062. }
  9063. float srepeatX = (float)Util.Clamp(msrepeat.x, -100.0, 100.0);
  9064. float srepeatY = (float)Util.Clamp(msrepeat.y, -100.0, 100.0);
  9065. float soffsetX = (float)Util.Clamp(msoffset.x, -1.0, 1.0);
  9066. float soffsetY = (float)Util.Clamp(msoffset.y, -1.0, 1.0);
  9067. byte colorR = (byte)(255.0 * Util.Clamp(mscolor.x, 0, 1.0) + 0.5);
  9068. byte colorG = (byte)(255.0 * Util.Clamp(mscolor.y, 0, 1.0) + 0.5);
  9069. byte colorB = (byte)(255.0 * Util.Clamp(mscolor.z, 0, 1.0) + 0.5);
  9070. byte gloss = (byte)Util.Clamp((int)msgloss, 0, 255);
  9071. byte env = (byte)Util.Clamp((int)msenv, 0, 255);
  9072. materialChanged |= SetMaterialSpecMap(part, face, smapID, srepeatX, srepeatY, soffsetX, soffsetY,
  9073. (float)msrot, colorR, colorG, colorB, gloss, env);
  9074. break;
  9075. case ScriptBaseClass.PRIM_LINK_TARGET:
  9076. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9077. return new LSL_List();
  9078. return rules.GetSublist(idx, -1);
  9079. default:
  9080. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
  9081. return new LSL_List();
  9082. }
  9083. }
  9084. }
  9085. catch (InvalidCastException e)
  9086. {
  9087. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9088. }
  9089. finally
  9090. {
  9091. if (positionChanged)
  9092. {
  9093. if (part.ParentGroup.RootPart == part)
  9094. {
  9095. SceneObjectGroup parent = part.ParentGroup;
  9096. // Util.FireAndForget(delegate(object x) {
  9097. parent.UpdateGroupPosition(currentPosition);
  9098. // });
  9099. }
  9100. else
  9101. {
  9102. part.OffsetPosition = currentPosition;
  9103. // SceneObjectGroup parent = part.ParentGroup;
  9104. // parent.HasGroupChanged = true;
  9105. // parent.ScheduleGroupForTerseUpdate();
  9106. part.ScheduleTerseUpdate();
  9107. }
  9108. }
  9109. if(materialChanged)
  9110. {
  9111. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  9112. {
  9113. part.TriggerScriptChangedEvent(Changed.TEXTURE);
  9114. part.ScheduleFullUpdate();
  9115. part.ParentGroup.HasGroupChanged = true;
  9116. }
  9117. }
  9118. }
  9119. return new LSL_List();
  9120. }
  9121. protected bool SetMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9122. {
  9123. if(m_materialsModule == null)
  9124. return false;
  9125. int nsides = part.GetNumberOfSides();
  9126. if(face == ScriptBaseClass.ALL_SIDES)
  9127. {
  9128. bool changed = false;
  9129. for(int i = 0; i < nsides; i++)
  9130. changed |= SetFaceMaterialAlphaMode(part, i, materialAlphaMode, materialMaskCutoff);
  9131. return changed;
  9132. }
  9133. if( face >= 0 && face < nsides)
  9134. return SetFaceMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9135. return false;
  9136. }
  9137. protected bool SetFaceMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9138. {
  9139. Primitive.TextureEntry tex = part.Shape.Textures;
  9140. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9141. if(texface == null)
  9142. return false;
  9143. FaceMaterial mat = null;
  9144. UUID oldid = texface.MaterialID;
  9145. if(oldid != UUID.Zero)
  9146. mat = m_materialsModule.GetMaterialCopy(oldid);
  9147. if(mat == null)
  9148. mat = new FaceMaterial();
  9149. mat.DiffuseAlphaMode = (byte)materialAlphaMode;
  9150. mat.AlphaMaskCutoff = (byte)materialMaskCutoff;
  9151. UUID id = m_materialsModule.AddNewMaterial(mat);
  9152. if(oldid == id)
  9153. return false;
  9154. texface.MaterialID = id;
  9155. part.Shape.TextureEntry = tex.GetBytes(9);
  9156. m_materialsModule.RemoveMaterial(oldid);
  9157. return true;
  9158. }
  9159. protected bool SetMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9160. float offsetX, float offsetY, float rot)
  9161. {
  9162. if(m_materialsModule == null)
  9163. return false;
  9164. int nsides = part.GetNumberOfSides();
  9165. if(face == ScriptBaseClass.ALL_SIDES)
  9166. {
  9167. bool changed = false;
  9168. for(int i = 0; i < nsides; i++)
  9169. changed |= SetFaceMaterialNormalMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9170. return changed;
  9171. }
  9172. if( face >= 0 && face < nsides)
  9173. return SetFaceMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9174. return false;
  9175. }
  9176. protected bool SetFaceMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9177. float offsetX, float offsetY, float rot)
  9178. {
  9179. Primitive.TextureEntry tex = part.Shape.Textures;
  9180. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9181. if(texface == null)
  9182. return false;
  9183. FaceMaterial mat = null;
  9184. UUID oldid = texface.MaterialID;
  9185. if(oldid != UUID.Zero)
  9186. mat = m_materialsModule.GetMaterialCopy(oldid);
  9187. if(mat == null)
  9188. mat = new FaceMaterial();
  9189. mat.NormalMapID = mapID;
  9190. mat.NormalOffsetX = offsetX;
  9191. mat.NormalOffsetY = offsetY;
  9192. mat.NormalRepeatX = repeatX;
  9193. mat.NormalRepeatY = repeatY;
  9194. mat.NormalRotation = rot;
  9195. UUID id = m_materialsModule.AddNewMaterial(mat);
  9196. if(oldid == id)
  9197. return false;
  9198. texface.MaterialID = id;
  9199. part.Shape.TextureEntry = tex.GetBytes(9);
  9200. m_materialsModule.RemoveMaterial(oldid);
  9201. return true;
  9202. }
  9203. protected bool SetMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9204. float offsetX, float offsetY, float rot,
  9205. byte colorR, byte colorG, byte colorB,
  9206. byte gloss, byte env)
  9207. {
  9208. if(m_materialsModule == null)
  9209. return false;
  9210. int nsides = part.GetNumberOfSides();
  9211. if(face == ScriptBaseClass.ALL_SIDES)
  9212. {
  9213. bool changed = false;
  9214. for(int i = 0; i < nsides; i++)
  9215. changed |= SetFaceMaterialSpecMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9216. colorR, colorG, colorB, gloss, env);
  9217. return changed;
  9218. }
  9219. if( face >= 0 && face < nsides)
  9220. return SetFaceMaterialSpecMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9221. colorR, colorG, colorB, gloss, env);
  9222. return false;
  9223. }
  9224. protected bool SetFaceMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9225. float offsetX, float offsetY, float rot,
  9226. byte colorR, byte colorG, byte colorB,
  9227. byte gloss, byte env)
  9228. {
  9229. Primitive.TextureEntry tex = part.Shape.Textures;
  9230. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9231. if(texface == null)
  9232. return false;
  9233. FaceMaterial mat = null;
  9234. UUID oldid = texface.MaterialID;
  9235. if(oldid != UUID.Zero)
  9236. mat = m_materialsModule.GetMaterialCopy(oldid);
  9237. if(mat == null)
  9238. mat = new FaceMaterial();
  9239. mat.SpecularMapID = mapID;
  9240. mat.SpecularOffsetX = offsetX;
  9241. mat.SpecularOffsetY = offsetY;
  9242. mat.SpecularRepeatX = repeatX;
  9243. mat.SpecularRepeatY = repeatY;
  9244. mat.SpecularRotation = rot;
  9245. mat.SpecularLightColorR = colorR;
  9246. mat.SpecularLightColorG = colorG;
  9247. mat.SpecularLightColorB = colorB;
  9248. mat.SpecularLightExponent = gloss;
  9249. mat.EnvironmentIntensity = env;
  9250. UUID id = m_materialsModule.AddNewMaterial(mat);
  9251. if(oldid == id)
  9252. return false;
  9253. texface.MaterialID = id;
  9254. part.Shape.TextureEntry = tex.GetBytes(9);
  9255. m_materialsModule.RemoveMaterial(oldid);
  9256. return true;
  9257. }
  9258. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  9259. {
  9260. int idx = 0;
  9261. int idxStart = 0;
  9262. try
  9263. {
  9264. while (idx < rules.Length)
  9265. {
  9266. ++rulesParsed;
  9267. int code = rules.GetLSLIntegerItem(idx++);
  9268. int remain = rules.Length - idx;
  9269. idxStart = idx;
  9270. switch (code)
  9271. {
  9272. case ScriptBaseClass.PRIM_POSITION:
  9273. case ScriptBaseClass.PRIM_POS_LOCAL:
  9274. if (remain < 1)
  9275. return new LSL_List();
  9276. try
  9277. {
  9278. sp.OffsetPosition = rules.GetVector3Item(idx++);
  9279. }
  9280. catch(InvalidCastException)
  9281. {
  9282. if (code == ScriptBaseClass.PRIM_POSITION)
  9283. {
  9284. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9285. }
  9286. else
  9287. {
  9288. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9289. }
  9290. return new LSL_List();
  9291. }
  9292. break;
  9293. case ScriptBaseClass.PRIM_ROTATION:
  9294. if (remain < 1)
  9295. return new LSL_List();
  9296. Quaternion inRot;
  9297. try
  9298. {
  9299. inRot = rules.GetQuaternionItem(idx++);
  9300. }
  9301. catch(InvalidCastException)
  9302. {
  9303. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9304. return new LSL_List();
  9305. }
  9306. SceneObjectPart parentPart = sp.ParentPart;
  9307. if (parentPart != null)
  9308. sp.Rotation = m_host.GetWorldRotation() * inRot;
  9309. break;
  9310. case ScriptBaseClass.PRIM_ROT_LOCAL:
  9311. if (remain < 1)
  9312. return new LSL_List();
  9313. try
  9314. {
  9315. sp.Rotation = rules.GetQuaternionItem(idx++);
  9316. }
  9317. catch(InvalidCastException)
  9318. {
  9319. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9320. return new LSL_List();
  9321. }
  9322. break;
  9323. case ScriptBaseClass.PRIM_TYPE:
  9324. Error(originFunc, "PRIM_TYPE disallowed on agent");
  9325. return new LSL_List();
  9326. case ScriptBaseClass.PRIM_OMEGA:
  9327. Error(originFunc, "PRIM_OMEGA disallowed on agent");
  9328. return new LSL_List();
  9329. case ScriptBaseClass.PRIM_LINK_TARGET:
  9330. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9331. return new LSL_List();
  9332. return rules.GetSublist(idx, -1);
  9333. default:
  9334. Error(originFunc,
  9335. string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
  9336. return new LSL_List();
  9337. }
  9338. }
  9339. }
  9340. catch (InvalidCastException e)
  9341. {
  9342. Error(
  9343. originFunc,
  9344. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9345. }
  9346. return new LSL_List();
  9347. }
  9348. public LSL_String llStringToBase64(string str)
  9349. {
  9350. m_host.AddScriptLPS(1);
  9351. try
  9352. {
  9353. byte[] encData_byte;
  9354. encData_byte = Util.UTF8.GetBytes(str);
  9355. string encodedData = Convert.ToBase64String(encData_byte);
  9356. return encodedData;
  9357. }
  9358. catch
  9359. {
  9360. Error("llBase64ToString", "Error encoding string");
  9361. return String.Empty;
  9362. }
  9363. }
  9364. public LSL_String llBase64ToString(string str)
  9365. {
  9366. m_host.AddScriptLPS(1);
  9367. try
  9368. {
  9369. byte[] b = Convert.FromBase64String(str);
  9370. return Encoding.UTF8.GetString(b);
  9371. }
  9372. catch
  9373. {
  9374. Error("llBase64ToString", "Error decoding string");
  9375. return String.Empty;
  9376. }
  9377. }
  9378. public LSL_String llXorBase64Strings(string str1, string str2)
  9379. {
  9380. int padding = 0;
  9381. string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  9382. ScriptSleep(300);
  9383. m_host.AddScriptLPS(1);
  9384. if (str1 == String.Empty)
  9385. return String.Empty;
  9386. if (str2 == String.Empty)
  9387. return str1;
  9388. int len = str2.Length;
  9389. if ((len % 4) != 0) // LL is EVIL!!!!
  9390. {
  9391. while (str2.EndsWith("="))
  9392. str2 = str2.Substring(0, str2.Length - 1);
  9393. len = str2.Length;
  9394. int mod = len % 4;
  9395. if (mod == 1)
  9396. str2 = str2.Substring(0, str2.Length - 1);
  9397. else if (mod == 2)
  9398. str2 += "==";
  9399. else if (mod == 3)
  9400. str2 += "=";
  9401. }
  9402. byte[] data1;
  9403. byte[] data2;
  9404. try
  9405. {
  9406. data1 = Convert.FromBase64String(str1);
  9407. data2 = Convert.FromBase64String(str2);
  9408. }
  9409. catch (Exception)
  9410. {
  9411. return new LSL_String(String.Empty);
  9412. }
  9413. // For cases where the decoded length of s2 is greater
  9414. // than the decoded length of s1, simply perform a normal
  9415. // decode and XOR
  9416. //
  9417. /*
  9418. if (data2.Length >= data1.Length)
  9419. {
  9420. for (int pos = 0 ; pos < data1.Length ; pos++ )
  9421. data1[pos] ^= data2[pos];
  9422. return Convert.ToBase64String(data1);
  9423. }
  9424. */
  9425. // Remove padding
  9426. while (str1.EndsWith("="))
  9427. {
  9428. str1 = str1.Substring(0, str1.Length - 1);
  9429. padding++;
  9430. }
  9431. while (str2.EndsWith("="))
  9432. str2 = str2.Substring(0, str2.Length - 1);
  9433. byte[] d1 = new byte[str1.Length];
  9434. byte[] d2 = new byte[str2.Length];
  9435. for (int i = 0 ; i < str1.Length ; i++)
  9436. {
  9437. int idx = b64.IndexOf(str1.Substring(i, 1));
  9438. if (idx == -1)
  9439. idx = 0;
  9440. d1[i] = (byte)idx;
  9441. }
  9442. for (int i = 0 ; i < str2.Length ; i++)
  9443. {
  9444. int idx = b64.IndexOf(str2.Substring(i, 1));
  9445. if (idx == -1)
  9446. idx = 0;
  9447. d2[i] = (byte)idx;
  9448. }
  9449. string output = String.Empty;
  9450. for (int pos = 0 ; pos < d1.Length ; pos++)
  9451. output += b64[d1[pos] ^ d2[pos % d2.Length]];
  9452. // Here's a funny thing: LL blithely violate the base64
  9453. // standard pretty much everywhere. Here, padding is
  9454. // added only if the first input string had it, rather
  9455. // than when the data actually needs it. This can result
  9456. // in invalid base64 being returned. Go figure.
  9457. while (padding-- > 0)
  9458. output += "=";
  9459. return output;
  9460. }
  9461. public void llRemoteDataSetRegion()
  9462. {
  9463. m_host.AddScriptLPS(1);
  9464. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  9465. }
  9466. public LSL_Float llLog10(double val)
  9467. {
  9468. m_host.AddScriptLPS(1);
  9469. return (double)Math.Log10(val);
  9470. }
  9471. public LSL_Float llLog(double val)
  9472. {
  9473. m_host.AddScriptLPS(1);
  9474. return (double)Math.Log(val);
  9475. }
  9476. public LSL_List llGetAnimationList(string id)
  9477. {
  9478. m_host.AddScriptLPS(1);
  9479. LSL_List l = new LSL_List();
  9480. ScenePresence av = World.GetScenePresence((UUID)id);
  9481. if (av == null || av.IsChildAgent) // only if in the region
  9482. return l;
  9483. UUID[] anims;
  9484. anims = av.Animator.GetAnimationArray();
  9485. foreach (UUID foo in anims)
  9486. l.Add(new LSL_Key(foo.ToString()));
  9487. return l;
  9488. }
  9489. public void llSetParcelMusicURL(string url)
  9490. {
  9491. m_host.AddScriptLPS(1);
  9492. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9493. if (land.LandData.OwnerID != m_host.OwnerID)
  9494. return;
  9495. land.SetMusicUrl(url);
  9496. ScriptSleep(m_sleepMsOnSetParcelMusicURL);
  9497. }
  9498. public LSL_String llGetParcelMusicURL()
  9499. {
  9500. m_host.AddScriptLPS(1);
  9501. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9502. if (land.LandData.OwnerID != m_host.OwnerID)
  9503. return String.Empty;
  9504. return land.GetMusicUrl();
  9505. }
  9506. public LSL_Vector llGetRootPosition()
  9507. {
  9508. m_host.AddScriptLPS(1);
  9509. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  9510. }
  9511. /// <summary>
  9512. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  9513. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  9514. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  9515. /// In the root prim:-
  9516. /// Returns the object rotation if not attached
  9517. /// Returns the avatars rotation if attached
  9518. /// Returns the camera rotation if attached and the avatar is in mouselook
  9519. /// </summary>
  9520. public LSL_Rotation llGetRootRotation()
  9521. {
  9522. m_host.AddScriptLPS(1);
  9523. Quaternion q;
  9524. if (m_host.ParentGroup.AttachmentPoint != 0)
  9525. {
  9526. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  9527. if (avatar != null)
  9528. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  9529. q = avatar.CameraRotation; // Mouselook
  9530. else
  9531. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  9532. else
  9533. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  9534. }
  9535. else
  9536. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  9537. return new LSL_Rotation(q);
  9538. }
  9539. public LSL_String llGetObjectDesc()
  9540. {
  9541. return m_host.Description!=null?m_host.Description:String.Empty;
  9542. }
  9543. public void llSetObjectDesc(string desc)
  9544. {
  9545. m_host.AddScriptLPS(1);
  9546. m_host.Description = desc!=null?desc:String.Empty;
  9547. }
  9548. public LSL_Key llGetCreator()
  9549. {
  9550. m_host.AddScriptLPS(1);
  9551. return m_host.CreatorID.ToString();
  9552. }
  9553. public LSL_String llGetTimestamp()
  9554. {
  9555. m_host.AddScriptLPS(1);
  9556. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  9557. }
  9558. public LSL_Integer llGetNumberOfPrims()
  9559. {
  9560. m_host.AddScriptLPS(1);
  9561. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  9562. }
  9563. /// <summary>
  9564. /// Full implementation of llGetBoundingBox according to SL 2015-04-15.
  9565. /// http://wiki.secondlife.com/wiki/LlGetBoundingBox
  9566. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  9567. /// Returns local bounding box of avatar without attachments
  9568. /// if target is non-seated avatar or prim/mesh in avatar attachment.
  9569. /// Returns local bounding box of object including seated avatars
  9570. /// if target is seated avatar or prim/mesh in object.
  9571. /// Uses meshing of prims for high accuracy
  9572. /// or less accurate box models for speed.
  9573. /// </summary>
  9574. public LSL_List llGetBoundingBox(string obj)
  9575. {
  9576. m_host.AddScriptLPS(1);
  9577. UUID objID = UUID.Zero;
  9578. LSL_List result = new LSL_List();
  9579. // If the ID is not valid, return null result
  9580. if (!UUID.TryParse(obj, out objID))
  9581. {
  9582. result.Add(new LSL_Vector());
  9583. result.Add(new LSL_Vector());
  9584. return result;
  9585. }
  9586. // Check if this is an attached prim. If so, replace
  9587. // the UUID with the avatar UUID and report it's bounding box
  9588. SceneObjectPart part = World.GetSceneObjectPart(objID);
  9589. if (part != null && part.ParentGroup.IsAttachment)
  9590. objID = part.ParentGroup.AttachedAvatar;
  9591. // Find out if this is an avatar ID. If so, return it's box
  9592. ScenePresence presence = World.GetScenePresence(objID);
  9593. if (presence != null)
  9594. {
  9595. // As per LSL Wiki, there is no difference between sitting
  9596. // and standing avatar since server 1.36
  9597. LSL_Vector lower;
  9598. LSL_Vector upper;
  9599. Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
  9600. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  9601. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  9602. /*
  9603. {
  9604. // This is for ground sitting avatars
  9605. float height = presence.Appearance.AvatarHeight / 2.66666667f;
  9606. lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
  9607. upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
  9608. }
  9609. else
  9610. {
  9611. // This is for standing/flying avatars
  9612. float height = presence.Appearance.AvatarHeight / 2.0f;
  9613. lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
  9614. upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
  9615. }
  9616. // Adjust to the documented error offsets (see LSL Wiki)
  9617. lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
  9618. upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
  9619. */
  9620. {
  9621. // This is for ground sitting avatars TODO!
  9622. lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
  9623. upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
  9624. }
  9625. else
  9626. {
  9627. // This is for standing/flying avatars
  9628. lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
  9629. upper = new LSL_Vector(box.X, box.Y, box.Z);
  9630. }
  9631. if (lower.x > upper.x)
  9632. lower.x = upper.x;
  9633. if (lower.y > upper.y)
  9634. lower.y = upper.y;
  9635. if (lower.z > upper.z)
  9636. lower.z = upper.z;
  9637. result.Add(lower);
  9638. result.Add(upper);
  9639. return result;
  9640. }
  9641. part = World.GetSceneObjectPart(objID);
  9642. // Currently only works for single prims without a sitting avatar
  9643. if (part == null)
  9644. {
  9645. result.Add(new LSL_Vector());
  9646. result.Add(new LSL_Vector());
  9647. return result;
  9648. }
  9649. SceneObjectGroup sog = part.ParentGroup;
  9650. if(sog.IsDeleted)
  9651. {
  9652. result.Add(new LSL_Vector());
  9653. result.Add(new LSL_Vector());
  9654. return result;
  9655. }
  9656. float minX;
  9657. float maxX;
  9658. float minY;
  9659. float maxY;
  9660. float minZ;
  9661. float maxZ;
  9662. sog.GetBoundingBox(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  9663. result.Add(new LSL_Vector(minX, minY, minZ));
  9664. result.Add(new LSL_Vector(maxX, maxY, maxZ));
  9665. return result;
  9666. }
  9667. /// <summary>
  9668. /// Helper to calculate bounding box of an avatar.
  9669. /// </summary>
  9670. private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper)
  9671. {
  9672. // Adjust from OS model
  9673. // avatar height = visual height - 0.2, bounding box height = visual height
  9674. // to SL model
  9675. // avatar height = visual height, bounding box height = visual height + 0.2
  9676. float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection;
  9677. // According to avatar bounding box in SL 2015-04-18:
  9678. // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h>
  9679. // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5>
  9680. // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h>
  9681. // When avatar is sitting
  9682. if (sp.ParentPart != null)
  9683. {
  9684. lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height);
  9685. upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height);
  9686. }
  9687. // When avatar is groundsitting
  9688. else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  9689. {
  9690. lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height);
  9691. upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height);
  9692. }
  9693. // When avatar is standing or flying
  9694. else
  9695. {
  9696. lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
  9697. upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
  9698. }
  9699. }
  9700. public LSL_Vector llGetGeometricCenter()
  9701. {
  9702. return new LSL_Vector(m_host.GetGeometricCenter());
  9703. }
  9704. public LSL_List llGetPrimitiveParams(LSL_List rules)
  9705. {
  9706. m_host.AddScriptLPS(1);
  9707. LSL_List result = new LSL_List();
  9708. LSL_List remaining = GetPrimParams(m_host, rules, ref result);
  9709. while ((object)remaining != null && remaining.Length > 1)
  9710. {
  9711. int linknumber = remaining.GetLSLIntegerItem(0);
  9712. rules = remaining.GetSublist(1, -1);
  9713. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  9714. if(parts.Count == 0)
  9715. break;
  9716. foreach (SceneObjectPart part in parts)
  9717. remaining = GetPrimParams(part, rules, ref result);
  9718. }
  9719. return result;
  9720. }
  9721. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  9722. {
  9723. m_host.AddScriptLPS(1);
  9724. // acording to SL wiki this must indicate a single link number or link_root or link_this.
  9725. // keep other options as before
  9726. List<SceneObjectPart> parts;
  9727. List<ScenePresence> avatars;
  9728. LSL_List res = new LSL_List();
  9729. LSL_List remaining = new LSL_List();
  9730. while (rules.Length > 0)
  9731. {
  9732. parts = GetLinkParts(linknumber);
  9733. avatars = GetLinkAvatars(linknumber);
  9734. remaining = new LSL_List();
  9735. foreach (SceneObjectPart part in parts)
  9736. {
  9737. remaining = GetPrimParams(part, rules, ref res);
  9738. }
  9739. foreach (ScenePresence avatar in avatars)
  9740. {
  9741. remaining = GetPrimParams(avatar, rules, ref res);
  9742. }
  9743. if (remaining.Length > 0)
  9744. {
  9745. linknumber = remaining.GetLSLIntegerItem(0);
  9746. rules = remaining.GetSublist(1, -1);
  9747. }
  9748. else
  9749. break;
  9750. }
  9751. return res;
  9752. }
  9753. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  9754. {
  9755. int idx = 0;
  9756. int face;
  9757. Primitive.TextureEntry tex;
  9758. int nsides = GetNumberOfSides(part);
  9759. while (idx < rules.Length)
  9760. {
  9761. int code = (int)rules.GetLSLIntegerItem(idx++);
  9762. int remain = rules.Length - idx;
  9763. switch (code)
  9764. {
  9765. case (int)ScriptBaseClass.PRIM_MATERIAL:
  9766. res.Add(new LSL_Integer(part.Material));
  9767. break;
  9768. case (int)ScriptBaseClass.PRIM_PHYSICS:
  9769. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  9770. res.Add(new LSL_Integer(1));
  9771. else
  9772. res.Add(new LSL_Integer(0));
  9773. break;
  9774. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  9775. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  9776. res.Add(new LSL_Integer(1));
  9777. else
  9778. res.Add(new LSL_Integer(0));
  9779. break;
  9780. case (int)ScriptBaseClass.PRIM_PHANTOM:
  9781. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  9782. res.Add(new LSL_Integer(1));
  9783. else
  9784. res.Add(new LSL_Integer(0));
  9785. break;
  9786. case (int)ScriptBaseClass.PRIM_POSITION:
  9787. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  9788. part.AbsolutePosition.Y,
  9789. part.AbsolutePosition.Z);
  9790. res.Add(v);
  9791. break;
  9792. case (int)ScriptBaseClass.PRIM_SIZE:
  9793. res.Add(new LSL_Vector(part.Scale));
  9794. break;
  9795. case (int)ScriptBaseClass.PRIM_ROTATION:
  9796. res.Add(GetPartRot(part));
  9797. break;
  9798. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  9799. res.Add(new LSL_Integer((int)part.PhysicsShapeType));
  9800. break;
  9801. case (int)ScriptBaseClass.PRIM_TYPE:
  9802. // implementing box
  9803. PrimitiveBaseShape Shape = part.Shape;
  9804. int primType = (int)part.GetPrimType();
  9805. res.Add(new LSL_Integer(primType));
  9806. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  9807. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  9808. switch (primType)
  9809. {
  9810. case ScriptBaseClass.PRIM_TYPE_BOX:
  9811. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  9812. case ScriptBaseClass.PRIM_TYPE_PRISM:
  9813. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9814. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9815. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9816. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9817. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9818. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9819. break;
  9820. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  9821. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9822. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9823. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9824. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9825. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9826. break;
  9827. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  9828. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  9829. res.Add(new LSL_Integer(Shape.SculptType));
  9830. break;
  9831. case ScriptBaseClass.PRIM_TYPE_RING:
  9832. case ScriptBaseClass.PRIM_TYPE_TUBE:
  9833. case ScriptBaseClass.PRIM_TYPE_TORUS:
  9834. // holeshape
  9835. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9836. // cut
  9837. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9838. // hollow
  9839. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9840. // twist
  9841. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9842. // vector holesize
  9843. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9844. // vector topshear
  9845. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9846. // vector profilecut
  9847. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9848. // vector tapera
  9849. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  9850. // float revolutions
  9851. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  9852. // Slightly inaccurate, because an unsigned byte is being used to represent
  9853. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  9854. // SL does it).
  9855. //
  9856. // Using these formulas to store and retrieve PathRevolutions, it is not
  9857. // possible to use all values between 1.00 and 4.00. For instance, you can't
  9858. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  9859. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  9860. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  9861. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  9862. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  9863. // such as 1.10. So, SL must store and retreive the actual user input rather
  9864. // than only storing the encoded value.
  9865. // float radiusoffset
  9866. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  9867. // float skew
  9868. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  9869. break;
  9870. }
  9871. break;
  9872. case (int)ScriptBaseClass.PRIM_TEXTURE:
  9873. if (remain < 1)
  9874. return new LSL_List();
  9875. face = (int)rules.GetLSLIntegerItem(idx++);
  9876. tex = part.Shape.Textures;
  9877. if (face == ScriptBaseClass.ALL_SIDES)
  9878. {
  9879. for (face = 0; face < nsides; face++)
  9880. {
  9881. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9882. res.Add(new LSL_String(texface.TextureID.ToString()));
  9883. res.Add(new LSL_Vector(texface.RepeatU,
  9884. texface.RepeatV,
  9885. 0));
  9886. res.Add(new LSL_Vector(texface.OffsetU,
  9887. texface.OffsetV,
  9888. 0));
  9889. res.Add(new LSL_Float(texface.Rotation));
  9890. }
  9891. }
  9892. else
  9893. {
  9894. if (face >= 0 && face < nsides)
  9895. {
  9896. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9897. res.Add(new LSL_String(texface.TextureID.ToString()));
  9898. res.Add(new LSL_Vector(texface.RepeatU,
  9899. texface.RepeatV,
  9900. 0));
  9901. res.Add(new LSL_Vector(texface.OffsetU,
  9902. texface.OffsetV,
  9903. 0));
  9904. res.Add(new LSL_Float(texface.Rotation));
  9905. }
  9906. }
  9907. break;
  9908. case (int)ScriptBaseClass.PRIM_COLOR:
  9909. if (remain < 1)
  9910. return new LSL_List();
  9911. face = (int)rules.GetLSLIntegerItem(idx++);
  9912. tex = part.Shape.Textures;
  9913. Color4 texcolor;
  9914. if (face == ScriptBaseClass.ALL_SIDES)
  9915. {
  9916. for (face = 0; face < nsides; face++)
  9917. {
  9918. texcolor = tex.GetFace((uint)face).RGBA;
  9919. res.Add(new LSL_Vector(texcolor.R,
  9920. texcolor.G,
  9921. texcolor.B));
  9922. res.Add(new LSL_Float(texcolor.A));
  9923. }
  9924. }
  9925. else
  9926. {
  9927. texcolor = tex.GetFace((uint)face).RGBA;
  9928. res.Add(new LSL_Vector(texcolor.R,
  9929. texcolor.G,
  9930. texcolor.B));
  9931. res.Add(new LSL_Float(texcolor.A));
  9932. }
  9933. break;
  9934. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  9935. {
  9936. if (remain < 1)
  9937. return new LSL_List();
  9938. face = (int)rules.GetLSLIntegerItem(idx++);
  9939. tex = part.Shape.Textures;
  9940. int shiny;
  9941. if (face == ScriptBaseClass.ALL_SIDES)
  9942. {
  9943. for (face = 0; face < nsides; face++)
  9944. {
  9945. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  9946. if (shinyness == Shininess.High)
  9947. {
  9948. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  9949. }
  9950. else if (shinyness == Shininess.Medium)
  9951. {
  9952. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  9953. }
  9954. else if (shinyness == Shininess.Low)
  9955. {
  9956. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  9957. }
  9958. else
  9959. {
  9960. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  9961. }
  9962. res.Add(new LSL_Integer(shiny));
  9963. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  9964. }
  9965. }
  9966. else
  9967. {
  9968. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  9969. if (shinyness == Shininess.High)
  9970. {
  9971. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  9972. }
  9973. else if (shinyness == Shininess.Medium)
  9974. {
  9975. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  9976. }
  9977. else if (shinyness == Shininess.Low)
  9978. {
  9979. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  9980. }
  9981. else
  9982. {
  9983. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  9984. }
  9985. res.Add(new LSL_Integer(shiny));
  9986. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  9987. }
  9988. break;
  9989. }
  9990. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  9991. {
  9992. if (remain < 1)
  9993. return new LSL_List();
  9994. face = (int)rules.GetLSLIntegerItem(idx++);
  9995. tex = part.Shape.Textures;
  9996. int fullbright;
  9997. if (face == ScriptBaseClass.ALL_SIDES)
  9998. {
  9999. for (face = 0; face < nsides; face++)
  10000. {
  10001. if (tex.GetFace((uint)face).Fullbright == true)
  10002. {
  10003. fullbright = ScriptBaseClass.TRUE;
  10004. }
  10005. else
  10006. {
  10007. fullbright = ScriptBaseClass.FALSE;
  10008. }
  10009. res.Add(new LSL_Integer(fullbright));
  10010. }
  10011. }
  10012. else
  10013. {
  10014. if (tex.GetFace((uint)face).Fullbright == true)
  10015. {
  10016. fullbright = ScriptBaseClass.TRUE;
  10017. }
  10018. else
  10019. {
  10020. fullbright = ScriptBaseClass.FALSE;
  10021. }
  10022. res.Add(new LSL_Integer(fullbright));
  10023. }
  10024. break;
  10025. }
  10026. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  10027. PrimitiveBaseShape shape = part.Shape;
  10028. if (shape.FlexiEntry)
  10029. res.Add(new LSL_Integer(1)); // active
  10030. else
  10031. res.Add(new LSL_Integer(0));
  10032. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  10033. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  10034. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  10035. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  10036. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  10037. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  10038. shape.FlexiForceY,
  10039. shape.FlexiForceZ));
  10040. break;
  10041. case (int)ScriptBaseClass.PRIM_TEXGEN:
  10042. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  10043. if (remain < 1)
  10044. return new LSL_List();
  10045. face = (int)rules.GetLSLIntegerItem(idx++);
  10046. tex = part.Shape.Textures;
  10047. if (face == ScriptBaseClass.ALL_SIDES)
  10048. {
  10049. for (face = 0; face < nsides; face++)
  10050. {
  10051. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10052. {
  10053. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10054. }
  10055. else
  10056. {
  10057. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10058. }
  10059. }
  10060. }
  10061. else
  10062. {
  10063. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10064. {
  10065. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10066. }
  10067. else
  10068. {
  10069. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10070. }
  10071. }
  10072. break;
  10073. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  10074. shape = part.Shape;
  10075. if (shape.LightEntry)
  10076. res.Add(new LSL_Integer(1)); // active
  10077. else
  10078. res.Add(new LSL_Integer(0));
  10079. res.Add(new LSL_Vector(shape.LightColorR, // color
  10080. shape.LightColorG,
  10081. shape.LightColorB));
  10082. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  10083. res.Add(new LSL_Float(shape.LightRadius)); // radius
  10084. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  10085. break;
  10086. case (int)ScriptBaseClass.PRIM_GLOW:
  10087. if (remain < 1)
  10088. return new LSL_List();
  10089. face = (int)rules.GetLSLIntegerItem(idx++);
  10090. tex = part.Shape.Textures;
  10091. float primglow;
  10092. if (face == ScriptBaseClass.ALL_SIDES)
  10093. {
  10094. for (face = 0; face < nsides; face++)
  10095. {
  10096. primglow = tex.GetFace((uint)face).Glow;
  10097. res.Add(new LSL_Float(primglow));
  10098. }
  10099. }
  10100. else
  10101. {
  10102. primglow = tex.GetFace((uint)face).Glow;
  10103. res.Add(new LSL_Float(primglow));
  10104. }
  10105. break;
  10106. case (int)ScriptBaseClass.PRIM_TEXT:
  10107. Color4 textColor = part.GetTextColor();
  10108. res.Add(new LSL_String(part.Text));
  10109. res.Add(new LSL_Vector(textColor.R,
  10110. textColor.G,
  10111. textColor.B));
  10112. res.Add(new LSL_Float(textColor.A));
  10113. break;
  10114. case (int)ScriptBaseClass.PRIM_NAME:
  10115. res.Add(new LSL_String(part.Name));
  10116. break;
  10117. case (int)ScriptBaseClass.PRIM_DESC:
  10118. res.Add(new LSL_String(part.Description));
  10119. break;
  10120. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  10121. res.Add(new LSL_Rotation(part.RotationOffset));
  10122. break;
  10123. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  10124. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  10125. break;
  10126. case (int)ScriptBaseClass.PRIM_SLICE:
  10127. PrimType prim_type = part.GetPrimType();
  10128. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  10129. res.Add(new LSL_Vector(
  10130. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  10131. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  10132. 0
  10133. ));
  10134. break;
  10135. case (int)ScriptBaseClass.PRIM_OMEGA:
  10136. // this may return values diferent from SL since we don't handle set the same way
  10137. float gain = 1.0f; // we don't use gain and don't store it
  10138. Vector3 axis = part.AngularVelocity;
  10139. float spin = axis.Length();
  10140. if(spin < 1.0e-6)
  10141. {
  10142. axis = Vector3.Zero;
  10143. gain = 0.0f;
  10144. spin = 0.0f;
  10145. }
  10146. else
  10147. {
  10148. axis = axis * (1.0f/spin);
  10149. }
  10150. res.Add(new LSL_Vector(axis.X,
  10151. axis.Y,
  10152. axis.Z));
  10153. res.Add(new LSL_Float(spin));
  10154. res.Add(new LSL_Float(gain));
  10155. break;
  10156. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  10157. if(part.IsSitTargetSet)
  10158. {
  10159. res.Add(new LSL_Integer(1));
  10160. res.Add(new LSL_Vector(part.SitTargetPosition));
  10161. res.Add(new LSL_Rotation(part.SitTargetOrientation));
  10162. }
  10163. else
  10164. {
  10165. res.Add(new LSL_Integer(0));
  10166. res.Add(new LSL_Vector(Vector3.Zero));
  10167. res.Add(new LSL_Rotation(Quaternion.Identity));
  10168. }
  10169. break;
  10170. case (int)ScriptBaseClass.PRIM_NORMAL:
  10171. case (int)ScriptBaseClass.PRIM_SPECULAR:
  10172. case (int)ScriptBaseClass.PRIM_ALPHA_MODE:
  10173. if (remain < 1)
  10174. return new LSL_List();
  10175. face = (int)rules.GetLSLIntegerItem(idx++);
  10176. tex = part.Shape.Textures;
  10177. if (face == ScriptBaseClass.ALL_SIDES)
  10178. {
  10179. for (face = 0; face < nsides; face++)
  10180. {
  10181. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10182. getLSLFaceMaterial(ref res, code, part, texface);
  10183. }
  10184. }
  10185. else
  10186. {
  10187. if (face >= 0 && face < nsides)
  10188. {
  10189. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10190. getLSLFaceMaterial(ref res, code, part, texface);
  10191. }
  10192. }
  10193. break;
  10194. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  10195. // TODO: Should be issuing a runtime script warning in this case.
  10196. if (remain < 2)
  10197. return new LSL_List();
  10198. return rules.GetSublist(idx, -1);
  10199. }
  10200. }
  10201. return new LSL_List();
  10202. }
  10203. private string GetMaterialTextureUUIDbyRights(UUID origID, SceneObjectPart part)
  10204. {
  10205. if(World.Permissions.CanEditObject(m_host.ParentGroup.UUID, m_host.ParentGroup.RootPart.OwnerID))
  10206. return origID.ToString();
  10207. lock(part.TaskInventory)
  10208. {
  10209. foreach(KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  10210. {
  10211. if(inv.Value.InvType == (int)InventoryType.Texture && inv.Value.AssetID == origID)
  10212. return origID.ToString();
  10213. }
  10214. }
  10215. return UUID.Zero.ToString();
  10216. }
  10217. private void getLSLFaceMaterial(ref LSL_List res, int code, SceneObjectPart part, Primitive.TextureEntryFace texface)
  10218. {
  10219. UUID matID = UUID.Zero;
  10220. if(m_materialsModule != null)
  10221. matID = texface.MaterialID;
  10222. if(matID != UUID.Zero)
  10223. {
  10224. FaceMaterial mat = m_materialsModule.GetMaterial(matID);
  10225. if(mat != null)
  10226. {
  10227. if(code == ScriptBaseClass.PRIM_NORMAL)
  10228. {
  10229. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.NormalMapID, part)));
  10230. res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0));
  10231. res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0));
  10232. res.Add(new LSL_Float(mat.NormalRotation));
  10233. }
  10234. else if(code == ScriptBaseClass.PRIM_SPECULAR)
  10235. {
  10236. const float colorScale = 1.0f / 255f;
  10237. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.SpecularMapID, part)));
  10238. res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0));
  10239. res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0));
  10240. res.Add(new LSL_Float(mat.SpecularRotation));
  10241. res.Add(new LSL_Vector(mat.SpecularLightColorR * colorScale,
  10242. mat.SpecularLightColorG * colorScale,
  10243. mat.SpecularLightColorB * colorScale));
  10244. res.Add(new LSL_Integer(mat.SpecularLightExponent));
  10245. res.Add(new LSL_Integer(mat.EnvironmentIntensity));
  10246. }
  10247. else if(code == ScriptBaseClass.PRIM_ALPHA_MODE)
  10248. {
  10249. res.Add(new LSL_Integer(mat.DiffuseAlphaMode));
  10250. res.Add(new LSL_Integer(mat.AlphaMaskCutoff));
  10251. }
  10252. return;
  10253. }
  10254. }
  10255. // material not found
  10256. if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10257. {
  10258. res.Add(new LSL_String(UUID.Zero.ToString()));
  10259. res.Add(new LSL_Vector(1.0, 1.0, 0));
  10260. res.Add(new LSL_Vector(0, 0, 0));
  10261. res.Add(new LSL_Float(0));
  10262. if(code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10263. {
  10264. res.Add(new LSL_Vector(1.0, 1.0, 1.0));
  10265. res.Add(new LSL_Integer(51));
  10266. res.Add(new LSL_Integer(0));
  10267. }
  10268. }
  10269. else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE)
  10270. {
  10271. res.Add(new LSL_Integer(1));
  10272. res.Add(new LSL_Integer(0));
  10273. }
  10274. }
  10275. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  10276. {
  10277. m_host.AddScriptLPS(1);
  10278. ScriptSleep(m_sleepMsOnGetPrimMediaParams);
  10279. return GetPrimMediaParams(m_host, face, rules);
  10280. }
  10281. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10282. {
  10283. m_host.AddScriptLPS(1);
  10284. ScriptSleep(m_sleepMsOnGetLinkMedia);
  10285. if (link == ScriptBaseClass.LINK_ROOT)
  10286. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10287. else if (link == ScriptBaseClass.LINK_THIS)
  10288. return GetPrimMediaParams(m_host, face, rules);
  10289. else
  10290. {
  10291. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10292. if (null != part)
  10293. return GetPrimMediaParams(part, face, rules);
  10294. }
  10295. return new LSL_List();
  10296. }
  10297. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  10298. {
  10299. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  10300. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  10301. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  10302. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10303. return new LSL_List();
  10304. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10305. if (null == module)
  10306. return new LSL_List();
  10307. MediaEntry me = module.GetMediaEntry(part, face);
  10308. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  10309. if (null == me)
  10310. return new LSL_List();
  10311. LSL_List res = new LSL_List();
  10312. for (int i = 0; i < rules.Length; i++)
  10313. {
  10314. int code = (int)rules.GetLSLIntegerItem(i);
  10315. switch (code)
  10316. {
  10317. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10318. // Not implemented
  10319. res.Add(new LSL_Integer(0));
  10320. break;
  10321. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10322. if (me.Controls == MediaControls.Standard)
  10323. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  10324. else
  10325. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  10326. break;
  10327. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10328. res.Add(new LSL_String(me.CurrentURL));
  10329. break;
  10330. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10331. res.Add(new LSL_String(me.HomeURL));
  10332. break;
  10333. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10334. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10335. break;
  10336. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10337. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10338. break;
  10339. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10340. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10341. break;
  10342. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10343. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10344. break;
  10345. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10346. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10347. break;
  10348. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10349. res.Add(new LSL_Integer(me.Width));
  10350. break;
  10351. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10352. res.Add(new LSL_Integer(me.Height));
  10353. break;
  10354. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10355. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10356. break;
  10357. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10358. string[] urls = (string[])me.WhiteList.Clone();
  10359. for (int j = 0; j < urls.Length; j++)
  10360. urls[j] = Uri.EscapeDataString(urls[j]);
  10361. res.Add(new LSL_String(string.Join(", ", urls)));
  10362. break;
  10363. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10364. res.Add(new LSL_Integer((int)me.InteractPermissions));
  10365. break;
  10366. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10367. res.Add(new LSL_Integer((int)me.ControlPermissions));
  10368. break;
  10369. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10370. }
  10371. }
  10372. return res;
  10373. }
  10374. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  10375. {
  10376. m_host.AddScriptLPS(1);
  10377. ScriptSleep(m_sleepMsOnSetPrimMediaParams);
  10378. return SetPrimMediaParams(m_host, face, rules);
  10379. }
  10380. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10381. {
  10382. m_host.AddScriptLPS(1);
  10383. ScriptSleep(m_sleepMsOnSetLinkMedia);
  10384. if (link == ScriptBaseClass.LINK_ROOT)
  10385. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10386. else if (link == ScriptBaseClass.LINK_THIS)
  10387. return SetPrimMediaParams(m_host, face, rules);
  10388. else
  10389. {
  10390. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10391. if (null != part)
  10392. return SetPrimMediaParams(part, face, rules);
  10393. }
  10394. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10395. }
  10396. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  10397. {
  10398. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  10399. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10400. // Don't perform the media check directly
  10401. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10402. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10403. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10404. if (null == module)
  10405. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10406. MediaEntry me = module.GetMediaEntry(part, face);
  10407. if (null == me)
  10408. me = new MediaEntry();
  10409. int i = 0;
  10410. while (i < rules.Length - 1)
  10411. {
  10412. int code = rules.GetLSLIntegerItem(i++);
  10413. switch (code)
  10414. {
  10415. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10416. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  10417. break;
  10418. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10419. int v = rules.GetLSLIntegerItem(i++);
  10420. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  10421. me.Controls = MediaControls.Standard;
  10422. else
  10423. me.Controls = MediaControls.Mini;
  10424. break;
  10425. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10426. me.CurrentURL = rules.GetLSLStringItem(i++);
  10427. break;
  10428. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10429. me.HomeURL = rules.GetLSLStringItem(i++);
  10430. break;
  10431. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10432. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10433. break;
  10434. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10435. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10436. break;
  10437. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10438. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10439. break;
  10440. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10441. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10442. break;
  10443. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10444. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10445. break;
  10446. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10447. me.Width = (int)rules.GetLSLIntegerItem(i++);
  10448. break;
  10449. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10450. me.Height = (int)rules.GetLSLIntegerItem(i++);
  10451. break;
  10452. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10453. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10454. break;
  10455. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10456. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  10457. List<string> whiteListUrls = new List<string>();
  10458. Array.ForEach(
  10459. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  10460. me.WhiteList = whiteListUrls.ToArray();
  10461. break;
  10462. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10463. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10464. break;
  10465. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10466. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10467. break;
  10468. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10469. }
  10470. }
  10471. module.SetMediaEntry(part, face, me);
  10472. return ScriptBaseClass.LSL_STATUS_OK;
  10473. }
  10474. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  10475. {
  10476. m_host.AddScriptLPS(1);
  10477. ScriptSleep(m_sleepMsOnClearPrimMedia);
  10478. return ClearPrimMedia(m_host, face);
  10479. }
  10480. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  10481. {
  10482. m_host.AddScriptLPS(1);
  10483. ScriptSleep(m_sleepMsOnClearLinkMedia);
  10484. if (link == ScriptBaseClass.LINK_ROOT)
  10485. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  10486. else if (link == ScriptBaseClass.LINK_THIS)
  10487. return ClearPrimMedia(m_host, face);
  10488. else
  10489. {
  10490. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10491. if (null != part)
  10492. return ClearPrimMedia(part, face);
  10493. }
  10494. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10495. }
  10496. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  10497. {
  10498. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  10499. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10500. // FIXME: Don't perform the media check directly
  10501. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10502. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10503. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10504. if (null == module)
  10505. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10506. module.ClearMediaEntry(part, face);
  10507. return ScriptBaseClass.LSL_STATUS_OK;
  10508. }
  10509. // <remarks>
  10510. // <para>
  10511. // The .NET definition of base 64 is:
  10512. // <list>
  10513. // <item>
  10514. // Significant: A-Z a-z 0-9 + -
  10515. // </item>
  10516. // <item>
  10517. // Whitespace: \t \n \r ' '
  10518. // </item>
  10519. // <item>
  10520. // Valueless: =
  10521. // </item>
  10522. // <item>
  10523. // End-of-string: \0 or '=='
  10524. // </item>
  10525. // </list>
  10526. // </para>
  10527. // <para>
  10528. // Each point in a base-64 string represents
  10529. // a 6 bit value. A 32-bit integer can be
  10530. // represented using 6 characters (with some
  10531. // redundancy).
  10532. // </para>
  10533. // <para>
  10534. // LSL requires a base64 string to be 8
  10535. // characters in length. LSL also uses '/'
  10536. // rather than '-' (MIME compliant).
  10537. // </para>
  10538. // <para>
  10539. // RFC 1341 used as a reference (as specified
  10540. // by the SecondLife Wiki).
  10541. // </para>
  10542. // <para>
  10543. // SL do not record any kind of exception for
  10544. // these functions, so the string to integer
  10545. // conversion returns '0' if an invalid
  10546. // character is encountered during conversion.
  10547. // </para>
  10548. // <para>
  10549. // References
  10550. // <list>
  10551. // <item>
  10552. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  10553. // </item>
  10554. // <item>
  10555. // </item>
  10556. // </list>
  10557. // </para>
  10558. // </remarks>
  10559. // <summary>
  10560. // Table for converting 6-bit integers into
  10561. // base-64 characters
  10562. // </summary>
  10563. protected static readonly char[] i2ctable =
  10564. {
  10565. 'A','B','C','D','E','F','G','H',
  10566. 'I','J','K','L','M','N','O','P',
  10567. 'Q','R','S','T','U','V','W','X',
  10568. 'Y','Z',
  10569. 'a','b','c','d','e','f','g','h',
  10570. 'i','j','k','l','m','n','o','p',
  10571. 'q','r','s','t','u','v','w','x',
  10572. 'y','z',
  10573. '0','1','2','3','4','5','6','7',
  10574. '8','9',
  10575. '+','/'
  10576. };
  10577. // <summary>
  10578. // Table for converting base-64 characters
  10579. // into 6-bit integers.
  10580. // </summary>
  10581. protected static readonly int[] c2itable =
  10582. {
  10583. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  10584. -1,-1,-1,-1,-1,-1,-1,-1,
  10585. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  10586. -1,-1,-1,-1,-1,-1,-1,-1,
  10587. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  10588. -1,-1,-1,63,-1,-1,-1,64,
  10589. 53,54,55,56,57,58,59,60, // 3x
  10590. 61,62,-1,-1,-1,0,-1,-1,
  10591. -1,1,2,3,4,5,6,7, // 4x
  10592. 8,9,10,11,12,13,14,15,
  10593. 16,17,18,19,20,21,22,23, // 5x
  10594. 24,25,26,-1,-1,-1,-1,-1,
  10595. -1,27,28,29,30,31,32,33, // 6x
  10596. 34,35,36,37,38,39,40,41,
  10597. 42,43,44,45,46,47,48,49, // 7x
  10598. 50,51,52,-1,-1,-1,-1,-1,
  10599. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  10600. -1,-1,-1,-1,-1,-1,-1,-1,
  10601. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  10602. -1,-1,-1,-1,-1,-1,-1,-1,
  10603. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  10604. -1,-1,-1,-1,-1,-1,-1,-1,
  10605. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  10606. -1,-1,-1,-1,-1,-1,-1,-1,
  10607. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  10608. -1,-1,-1,-1,-1,-1,-1,-1,
  10609. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  10610. -1,-1,-1,-1,-1,-1,-1,-1,
  10611. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  10612. -1,-1,-1,-1,-1,-1,-1,-1,
  10613. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  10614. -1,-1,-1,-1,-1,-1,-1,-1
  10615. };
  10616. // <summary>
  10617. // Converts a 32-bit integer into a Base64
  10618. // character string. Base64 character strings
  10619. // are always 8 characters long. All iinteger
  10620. // values are acceptable.
  10621. // </summary>
  10622. // <param name="number">
  10623. // 32-bit integer to be converted.
  10624. // </param>
  10625. // <returns>
  10626. // 8 character string. The 1st six characters
  10627. // contain the encoded number, the last two
  10628. // characters are padded with "=".
  10629. // </returns>
  10630. public LSL_String llIntegerToBase64(int number)
  10631. {
  10632. // uninitialized string
  10633. char[] imdt = new char[8];
  10634. m_host.AddScriptLPS(1);
  10635. // Manually unroll the loop
  10636. imdt[7] = '=';
  10637. imdt[6] = '=';
  10638. imdt[5] = i2ctable[number<<4 & 0x3F];
  10639. imdt[4] = i2ctable[number>>2 & 0x3F];
  10640. imdt[3] = i2ctable[number>>8 & 0x3F];
  10641. imdt[2] = i2ctable[number>>14 & 0x3F];
  10642. imdt[1] = i2ctable[number>>20 & 0x3F];
  10643. imdt[0] = i2ctable[number>>26 & 0x3F];
  10644. return new string(imdt);
  10645. }
  10646. // <summary>
  10647. // Converts an eight character base-64 string
  10648. // into a 32-bit integer.
  10649. // </summary>
  10650. // <param name="str">
  10651. // 8 characters string to be converted. Other
  10652. // length strings return zero.
  10653. // </param>
  10654. // <returns>
  10655. // Returns an integer representing the
  10656. // encoded value providedint he 1st 6
  10657. // characters of the string.
  10658. // </returns>
  10659. // <remarks>
  10660. // This is coded to behave like LSL's
  10661. // implementation (I think), based upon the
  10662. // information available at the Wiki.
  10663. // If more than 8 characters are supplied,
  10664. // zero is returned.
  10665. // If a NULL string is supplied, zero will
  10666. // be returned.
  10667. // If fewer than 6 characters are supplied, then
  10668. // the answer will reflect a partial
  10669. // accumulation.
  10670. // <para>
  10671. // The 6-bit segments are
  10672. // extracted left-to-right in big-endian mode,
  10673. // which means that segment 6 only contains the
  10674. // two low-order bits of the 32 bit integer as
  10675. // its high order 2 bits. A short string therefore
  10676. // means loss of low-order information. E.g.
  10677. //
  10678. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  10679. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  10680. // |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|
  10681. // |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|
  10682. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  10683. //
  10684. // </para>
  10685. // </remarks>
  10686. public LSL_Integer llBase64ToInteger(string str)
  10687. {
  10688. int number = 0;
  10689. int digit;
  10690. m_host.AddScriptLPS(1);
  10691. // Require a well-fromed base64 string
  10692. if (str.Length > 8)
  10693. return 0;
  10694. // The loop is unrolled in the interests
  10695. // of performance and simple necessity.
  10696. //
  10697. // MUST find 6 digits to be well formed
  10698. // -1 == invalid
  10699. // 0 == padding
  10700. if ((digit = c2itable[str[0]]) <= 0)
  10701. {
  10702. return digit < 0 ? (int)0 : number;
  10703. }
  10704. number += --digit<<26;
  10705. if ((digit = c2itable[str[1]]) <= 0)
  10706. {
  10707. return digit < 0 ? (int)0 : number;
  10708. }
  10709. number += --digit<<20;
  10710. if ((digit = c2itable[str[2]]) <= 0)
  10711. {
  10712. return digit < 0 ? (int)0 : number;
  10713. }
  10714. number += --digit<<14;
  10715. if ((digit = c2itable[str[3]]) <= 0)
  10716. {
  10717. return digit < 0 ? (int)0 : number;
  10718. }
  10719. number += --digit<<8;
  10720. if ((digit = c2itable[str[4]]) <= 0)
  10721. {
  10722. return digit < 0 ? (int)0 : number;
  10723. }
  10724. number += --digit<<2;
  10725. if ((digit = c2itable[str[5]]) <= 0)
  10726. {
  10727. return digit < 0 ? (int)0 : number;
  10728. }
  10729. number += --digit>>4;
  10730. // ignore trailing padding
  10731. return number;
  10732. }
  10733. public LSL_Float llGetGMTclock()
  10734. {
  10735. m_host.AddScriptLPS(1);
  10736. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  10737. }
  10738. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  10739. {
  10740. m_host.AddScriptLPS(1);
  10741. if (m_UrlModule != null)
  10742. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  10743. return String.Empty;
  10744. }
  10745. public LSL_String llGetSimulatorHostname()
  10746. {
  10747. m_host.AddScriptLPS(1);
  10748. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  10749. return UrlModule.ExternalHostNameForLSL;
  10750. }
  10751. // <summary>
  10752. // Scan the string supplied in 'src' and
  10753. // tokenize it based upon two sets of
  10754. // tokenizers provided in two lists,
  10755. // separators and spacers.
  10756. // </summary>
  10757. //
  10758. // <remarks>
  10759. // Separators demarcate tokens and are
  10760. // elided as they are encountered. Spacers
  10761. // also demarcate tokens, but are themselves
  10762. // retained as tokens.
  10763. //
  10764. // Both separators and spacers may be arbitrarily
  10765. // long strings. i.e. ":::".
  10766. //
  10767. // The function returns an ordered list
  10768. // representing the tokens found in the supplied
  10769. // sources string. If two successive tokenizers
  10770. // are encountered, then a null-string entry is
  10771. // added to the list.
  10772. //
  10773. // It is a precondition that the source and
  10774. // toekizer lisst are non-null. If they are null,
  10775. // then a null pointer exception will be thrown
  10776. // while their lengths are being determined.
  10777. //
  10778. // A small amount of working memoryis required
  10779. // of approximately 8*#tokenizers + 8*srcstrlen.
  10780. //
  10781. // There are many ways in which this function
  10782. // can be implemented, this implementation is
  10783. // fairly naive and assumes that when the
  10784. // function is invooked with a short source
  10785. // string and/or short lists of tokenizers, then
  10786. // performance will not be an issue.
  10787. //
  10788. // In order to minimize the perofrmance
  10789. // effects of long strings, or large numbers
  10790. // of tokeizers, the function skips as far as
  10791. // possible whenever a toekenizer is found,
  10792. // and eliminates redundant tokenizers as soon
  10793. // as is possible.
  10794. //
  10795. // The implementation tries to minimize temporary
  10796. // garbage generation.
  10797. // </remarks>
  10798. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  10799. {
  10800. return ParseString2List(src, separators, spacers, true);
  10801. }
  10802. private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  10803. {
  10804. int srclen = src.Length;
  10805. int seplen = separators.Length;
  10806. object[] separray = separators.Data;
  10807. int spclen = spacers.Length;
  10808. object[] spcarray = spacers.Data;
  10809. int dellen = 0;
  10810. string[] delarray = new string[seplen+spclen];
  10811. int outlen = 0;
  10812. string[] outarray = new string[srclen*2+1];
  10813. int i, j;
  10814. string d;
  10815. m_host.AddScriptLPS(1);
  10816. /*
  10817. * Convert separator and spacer lists to C# strings.
  10818. * Also filter out null strings so we don't hang.
  10819. */
  10820. for (i = 0; i < seplen; i ++)
  10821. {
  10822. d = separray[i].ToString();
  10823. if (d.Length > 0)
  10824. {
  10825. delarray[dellen++] = d;
  10826. }
  10827. }
  10828. seplen = dellen;
  10829. for (i = 0; i < spclen; i ++)
  10830. {
  10831. d = spcarray[i].ToString();
  10832. if (d.Length > 0)
  10833. {
  10834. delarray[dellen++] = d;
  10835. }
  10836. }
  10837. /*
  10838. * Scan through source string from beginning to end.
  10839. */
  10840. for (i = 0;;)
  10841. {
  10842. /*
  10843. * Find earliest delimeter in src starting at i (if any).
  10844. */
  10845. int earliestDel = -1;
  10846. int earliestSrc = srclen;
  10847. string earliestStr = null;
  10848. for (j = 0; j < dellen; j ++)
  10849. {
  10850. d = delarray[j];
  10851. if (d != null)
  10852. {
  10853. int index = src.IndexOf(d, i);
  10854. if (index < 0)
  10855. {
  10856. delarray[j] = null; // delim nowhere in src, don't check it anymore
  10857. }
  10858. else if (index < earliestSrc)
  10859. {
  10860. earliestSrc = index; // where delimeter starts in source string
  10861. earliestDel = j; // where delimeter is in delarray[]
  10862. earliestStr = d; // the delimeter string from delarray[]
  10863. if (index == i) break; // can't do any better than found at beg of string
  10864. }
  10865. }
  10866. }
  10867. /*
  10868. * Output source string starting at i through start of earliest delimeter.
  10869. */
  10870. if (keepNulls || (earliestSrc > i))
  10871. {
  10872. outarray[outlen++] = src.Substring(i, earliestSrc - i);
  10873. }
  10874. /*
  10875. * If no delimeter found at or after i, we're done scanning.
  10876. */
  10877. if (earliestDel < 0) break;
  10878. /*
  10879. * If delimeter was a spacer, output the spacer.
  10880. */
  10881. if (earliestDel >= seplen)
  10882. {
  10883. outarray[outlen++] = earliestStr;
  10884. }
  10885. /*
  10886. * Look at rest of src string following delimeter.
  10887. */
  10888. i = earliestSrc + earliestStr.Length;
  10889. }
  10890. /*
  10891. * Make up an exact-sized output array suitable for an LSL_List object.
  10892. */
  10893. object[] outlist = new object[outlen];
  10894. for (i = 0; i < outlen; i ++)
  10895. {
  10896. outlist[i] = new LSL_String(outarray[i]);
  10897. }
  10898. return new LSL_List(outlist);
  10899. }
  10900. public LSL_Integer llGetObjectPermMask(int mask)
  10901. {
  10902. m_host.AddScriptLPS(1);
  10903. int permmask = 0;
  10904. if (mask == ScriptBaseClass.MASK_BASE)//0
  10905. {
  10906. permmask = (int)m_host.BaseMask;
  10907. }
  10908. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  10909. {
  10910. permmask = (int)m_host.OwnerMask;
  10911. }
  10912. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  10913. {
  10914. permmask = (int)m_host.GroupMask;
  10915. }
  10916. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  10917. {
  10918. permmask = (int)m_host.EveryoneMask;
  10919. }
  10920. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  10921. {
  10922. permmask = (int)m_host.NextOwnerMask;
  10923. }
  10924. return permmask;
  10925. }
  10926. public void llSetObjectPermMask(int mask, int value)
  10927. {
  10928. m_host.AddScriptLPS(1);
  10929. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  10930. {
  10931. if (World.Permissions.IsAdministrator(m_host.OwnerID))
  10932. {
  10933. if (mask == ScriptBaseClass.MASK_BASE)//0
  10934. {
  10935. m_host.BaseMask = (uint)value;
  10936. }
  10937. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  10938. {
  10939. m_host.OwnerMask = (uint)value;
  10940. }
  10941. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  10942. {
  10943. m_host.GroupMask = (uint)value;
  10944. }
  10945. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  10946. {
  10947. m_host.EveryoneMask = (uint)value;
  10948. }
  10949. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  10950. {
  10951. m_host.NextOwnerMask = (uint)value;
  10952. }
  10953. }
  10954. }
  10955. }
  10956. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  10957. {
  10958. m_host.AddScriptLPS(1);
  10959. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  10960. if (item == null)
  10961. return -1;
  10962. switch (mask)
  10963. {
  10964. case 0:
  10965. return (int)item.BasePermissions;
  10966. case 1:
  10967. return (int)item.CurrentPermissions;
  10968. case 2:
  10969. return (int)item.GroupPermissions;
  10970. case 3:
  10971. return (int)item.EveryonePermissions;
  10972. case 4:
  10973. return (int)item.NextPermissions;
  10974. }
  10975. return -1;
  10976. }
  10977. public void llSetInventoryPermMask(string itemName, int mask, int value)
  10978. {
  10979. m_host.AddScriptLPS(1);
  10980. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  10981. {
  10982. if (World.Permissions.IsAdministrator(m_host.OwnerID))
  10983. {
  10984. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  10985. if (item != null)
  10986. {
  10987. switch (mask)
  10988. {
  10989. case 0:
  10990. item.BasePermissions = (uint)value;
  10991. break;
  10992. case 1:
  10993. item.CurrentPermissions = (uint)value;
  10994. break;
  10995. case 2:
  10996. item.GroupPermissions = (uint)value;
  10997. break;
  10998. case 3:
  10999. item.EveryonePermissions = (uint)value;
  11000. break;
  11001. case 4:
  11002. item.NextPermissions = (uint)value;
  11003. break;
  11004. }
  11005. }
  11006. }
  11007. }
  11008. }
  11009. public LSL_Key llGetInventoryCreator(string itemName)
  11010. {
  11011. m_host.AddScriptLPS(1);
  11012. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11013. if (item == null)
  11014. {
  11015. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  11016. return String.Empty;
  11017. }
  11018. return item.CreatorID.ToString();
  11019. }
  11020. public void llOwnerSay(string msg)
  11021. {
  11022. m_host.AddScriptLPS(1);
  11023. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  11024. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  11025. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  11026. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  11027. }
  11028. public LSL_Key llRequestSecureURL()
  11029. {
  11030. m_host.AddScriptLPS(1);
  11031. if (m_UrlModule != null)
  11032. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11033. return UUID.Zero.ToString();
  11034. }
  11035. public LSL_Key llRequestSimulatorData(string simulator, int data)
  11036. {
  11037. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  11038. try
  11039. {
  11040. m_host.AddScriptLPS(1);
  11041. string reply = String.Empty;
  11042. GridRegion info;
  11043. if (World.RegionInfo.RegionName == simulator)
  11044. info = new GridRegion(World.RegionInfo);
  11045. else
  11046. info = World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  11047. switch (data)
  11048. {
  11049. case ScriptBaseClass.DATA_SIM_POS:
  11050. if (info == null)
  11051. {
  11052. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11053. return UUID.Zero.ToString();
  11054. }
  11055. bool isHypergridRegion = false;
  11056. if (World.RegionInfo.RegionName != simulator && info.RegionSecret != "")
  11057. {
  11058. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  11059. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  11060. // anything is present we need to disambiguate.
  11061. //
  11062. // FIXME: Hypergrid should be storing this data in a different field.
  11063. RegionFlags regionFlags
  11064. = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  11065. info.ScopeID, info.RegionID);
  11066. isHypergridRegion = (regionFlags & RegionFlags.Hyperlink) != 0;
  11067. }
  11068. if (isHypergridRegion)
  11069. {
  11070. uint rx = 0, ry = 0;
  11071. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
  11072. reply = new LSL_Vector(
  11073. rx,
  11074. ry,
  11075. 0).ToString();
  11076. }
  11077. else
  11078. {
  11079. // Local grid co-oridnates
  11080. reply = new LSL_Vector(
  11081. info.RegionLocX,
  11082. info.RegionLocY,
  11083. 0).ToString();
  11084. }
  11085. break;
  11086. case ScriptBaseClass.DATA_SIM_STATUS:
  11087. if (info != null)
  11088. reply = "up"; // Duh!
  11089. else
  11090. reply = "unknown";
  11091. break;
  11092. case ScriptBaseClass.DATA_SIM_RATING:
  11093. if (info == null)
  11094. {
  11095. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11096. return UUID.Zero.ToString();
  11097. }
  11098. int access = info.Maturity;
  11099. if (access == 0)
  11100. reply = "PG";
  11101. else if (access == 1)
  11102. reply = "MATURE";
  11103. else if (access == 2)
  11104. reply = "ADULT";
  11105. else
  11106. reply = "UNKNOWN";
  11107. break;
  11108. case ScriptBaseClass.DATA_SIM_RELEASE:
  11109. if (ossl != null)
  11110. ossl.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData");
  11111. reply = "OpenSim";
  11112. break;
  11113. default:
  11114. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11115. return UUID.Zero.ToString(); // Raise no event
  11116. }
  11117. UUID rq = UUID.Random();
  11118. UUID tid = AsyncCommands.
  11119. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  11120. AsyncCommands.
  11121. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  11122. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11123. return tid.ToString();
  11124. }
  11125. catch(Exception)
  11126. {
  11127. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  11128. return UUID.Zero.ToString();
  11129. }
  11130. }
  11131. public LSL_Key llRequestURL()
  11132. {
  11133. m_host.AddScriptLPS(1);
  11134. if (m_UrlModule != null)
  11135. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11136. return UUID.Zero.ToString();
  11137. }
  11138. public void llForceMouselook(int mouselook)
  11139. {
  11140. m_host.AddScriptLPS(1);
  11141. m_host.SetForceMouselook(mouselook != 0);
  11142. }
  11143. public LSL_Float llGetObjectMass(LSL_Key id)
  11144. {
  11145. m_host.AddScriptLPS(1);
  11146. UUID key = new UUID();
  11147. if (!UUID.TryParse(id, out key))
  11148. return 0;
  11149. // return total object mass
  11150. SceneObjectPart part = World.GetSceneObjectPart(key);
  11151. if (part != null)
  11152. return part.ParentGroup.GetMass();
  11153. // the object is null so the key is for an avatar
  11154. ScenePresence avatar = World.GetScenePresence(key);
  11155. if (avatar != null)
  11156. {
  11157. if (avatar.IsChildAgent)
  11158. {
  11159. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  11160. // child agents have a mass of 1.0
  11161. return 1;
  11162. }
  11163. else
  11164. {
  11165. return avatar.GetMass();
  11166. }
  11167. }
  11168. return 0;
  11169. }
  11170. /// <summary>
  11171. /// llListReplaceList removes the sub-list defined by the inclusive indices
  11172. /// start and end and inserts the src list in its place. The inclusive
  11173. /// nature of the indices means that at least one element must be deleted
  11174. /// if the indices are within the bounds of the existing list. I.e. 2,2
  11175. /// will remove the element at index 2 and replace it with the source
  11176. /// list. Both indices may be negative, with the usual interpretation. An
  11177. /// interesting case is where end is lower than start. As these indices
  11178. /// bound the list to be removed, then 0->end, and start->lim are removed
  11179. /// and the source list is added as a suffix.
  11180. /// </summary>
  11181. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  11182. {
  11183. LSL_List pref;
  11184. m_host.AddScriptLPS(1);
  11185. // Note that although we have normalized, both
  11186. // indices could still be negative.
  11187. if (start < 0)
  11188. {
  11189. start = start+dest.Length;
  11190. }
  11191. if (end < 0)
  11192. {
  11193. end = end+dest.Length;
  11194. }
  11195. // The comventional case, remove a sequence starting with
  11196. // start and ending with end. And then insert the source
  11197. // list.
  11198. if (start <= end)
  11199. {
  11200. // If greater than zero, then there is going to be a
  11201. // surviving prefix. Otherwise the inclusive nature
  11202. // of the indices mean that we're going to add the
  11203. // source list as a prefix.
  11204. if (start > 0)
  11205. {
  11206. pref = dest.GetSublist(0,start-1);
  11207. // Only add a suffix if there is something
  11208. // beyond the end index (it's inclusive too).
  11209. if (end + 1 < dest.Length)
  11210. {
  11211. return pref + src + dest.GetSublist(end + 1, -1);
  11212. }
  11213. else
  11214. {
  11215. return pref + src;
  11216. }
  11217. }
  11218. // If start is less than or equal to zero, then
  11219. // the new list is simply a prefix. We still need to
  11220. // figure out any necessary surgery to the destination
  11221. // based upon end. Note that if end exceeds the upper
  11222. // bound in this case, the entire destination list
  11223. // is removed.
  11224. else if (start == 0)
  11225. {
  11226. if (end + 1 < dest.Length)
  11227. return src + dest.GetSublist(end + 1, -1);
  11228. else
  11229. return src;
  11230. }
  11231. else // Start < 0
  11232. {
  11233. if (end + 1 < dest.Length)
  11234. return dest.GetSublist(end + 1, -1);
  11235. else
  11236. return new LSL_List();
  11237. }
  11238. }
  11239. // Finally, if start > end, we strip away a prefix and
  11240. // a suffix, to leave the list that sits <between> ens
  11241. // and start, and then tag on the src list. AT least
  11242. // that's my interpretation. We can get sublist to do
  11243. // this for us. Note that one, or both of the indices
  11244. // might have been negative.
  11245. else
  11246. {
  11247. return dest.GetSublist(end + 1, start - 1) + src;
  11248. }
  11249. }
  11250. public void llLoadURL(string avatar_id, string message, string url)
  11251. {
  11252. m_host.AddScriptLPS(1);
  11253. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  11254. if (null != dm)
  11255. dm.SendUrlToUser(
  11256. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  11257. ScriptSleep(m_sleepMsOnLoadURL);
  11258. }
  11259. public void llParcelMediaCommandList(LSL_List commandList)
  11260. {
  11261. // TODO: Not implemented yet (missing in libomv?):
  11262. // 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)
  11263. m_host.AddScriptLPS(1);
  11264. // according to the docs, this command only works if script owner and land owner are the same
  11265. // lets add estate owners and gods, too, and use the generic permission check.
  11266. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11267. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false)) return;
  11268. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  11269. byte loop = 0;
  11270. LandData landData = landObject.LandData;
  11271. string url = landData.MediaURL;
  11272. string texture = landData.MediaID.ToString();
  11273. bool autoAlign = landData.MediaAutoScale != 0;
  11274. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  11275. string description = "";
  11276. int width = 0;
  11277. int height = 0;
  11278. ParcelMediaCommandEnum? commandToSend = null;
  11279. float time = 0.0f; // default is from start
  11280. uint cmndFlags = 0;
  11281. ScenePresence presence = null;
  11282. int cmd;
  11283. for (int i = 0; i < commandList.Data.Length; i++)
  11284. {
  11285. if(commandList.Data[i] is LSL_Integer)
  11286. cmd = (LSL_Integer)commandList.Data[i];
  11287. else
  11288. cmd = (int)commandList.Data[i];
  11289. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)cmd;
  11290. switch (command)
  11291. {
  11292. case ParcelMediaCommandEnum.Agent:
  11293. // we send only to one agent
  11294. if ((i + 1) < commandList.Length)
  11295. {
  11296. if (commandList.Data[i + 1] is LSL_String)
  11297. {
  11298. UUID agentID;
  11299. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  11300. {
  11301. presence = World.GetScenePresence(agentID);
  11302. }
  11303. }
  11304. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  11305. ++i;
  11306. }
  11307. break;
  11308. case ParcelMediaCommandEnum.Loop:
  11309. loop = 1;
  11310. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_LOOP);
  11311. commandToSend = command;
  11312. update = true; //need to send the media update packet to set looping
  11313. break;
  11314. case ParcelMediaCommandEnum.Play:
  11315. loop = 0;
  11316. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PLAY);
  11317. commandToSend = command;
  11318. update = true; //need to send the media update packet to make sure it doesn't loop
  11319. break;
  11320. case ParcelMediaCommandEnum.Pause:
  11321. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PAUSE);
  11322. commandToSend = command;
  11323. break;
  11324. case ParcelMediaCommandEnum.Stop:
  11325. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_STOP);
  11326. commandToSend = command;
  11327. break;
  11328. case ParcelMediaCommandEnum.Unload:
  11329. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_UNLOAD);
  11330. commandToSend = command;
  11331. break;
  11332. case ParcelMediaCommandEnum.Url:
  11333. if ((i + 1) < commandList.Length)
  11334. {
  11335. if (commandList.Data[i + 1] is LSL_String)
  11336. {
  11337. url = (LSL_String)commandList.Data[i + 1];
  11338. update = true;
  11339. }
  11340. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  11341. ++i;
  11342. }
  11343. break;
  11344. case ParcelMediaCommandEnum.Texture:
  11345. if ((i + 1) < commandList.Length)
  11346. {
  11347. if (commandList.Data[i + 1] is LSL_String)
  11348. {
  11349. texture = (LSL_String)commandList.Data[i + 1];
  11350. update = true;
  11351. }
  11352. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  11353. ++i;
  11354. }
  11355. break;
  11356. case ParcelMediaCommandEnum.Time:
  11357. if ((i + 1) < commandList.Length)
  11358. {
  11359. if (commandList.Data[i + 1] is LSL_Float)
  11360. {
  11361. time = (float)(LSL_Float)commandList.Data[i + 1];
  11362. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_TIME);
  11363. }
  11364. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  11365. ++i;
  11366. }
  11367. break;
  11368. case ParcelMediaCommandEnum.AutoAlign:
  11369. if ((i + 1) < commandList.Length)
  11370. {
  11371. if (commandList.Data[i + 1] is LSL_Integer)
  11372. {
  11373. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  11374. update = true;
  11375. }
  11376. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  11377. ++i;
  11378. }
  11379. break;
  11380. case ParcelMediaCommandEnum.Type:
  11381. if ((i + 1) < commandList.Length)
  11382. {
  11383. if (commandList.Data[i + 1] is LSL_String)
  11384. {
  11385. mediaType = (LSL_String)commandList.Data[i + 1];
  11386. update = true;
  11387. }
  11388. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  11389. ++i;
  11390. }
  11391. break;
  11392. case ParcelMediaCommandEnum.Desc:
  11393. if ((i + 1) < commandList.Length)
  11394. {
  11395. if (commandList.Data[i + 1] is LSL_String)
  11396. {
  11397. description = (LSL_String)commandList.Data[i + 1];
  11398. update = true;
  11399. }
  11400. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  11401. ++i;
  11402. }
  11403. break;
  11404. case ParcelMediaCommandEnum.Size:
  11405. if ((i + 2) < commandList.Length)
  11406. {
  11407. if (commandList.Data[i + 1] is LSL_Integer)
  11408. {
  11409. if (commandList.Data[i + 2] is LSL_Integer)
  11410. {
  11411. width = (LSL_Integer)commandList.Data[i + 1];
  11412. height = (LSL_Integer)commandList.Data[i + 2];
  11413. update = true;
  11414. }
  11415. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11416. }
  11417. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11418. i += 2;
  11419. }
  11420. break;
  11421. default:
  11422. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  11423. break;
  11424. }//end switch
  11425. }//end for
  11426. // if we didn't get a presence, we send to all and change the url
  11427. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  11428. // did something important change or do we only start/stop/pause?
  11429. if (update)
  11430. {
  11431. if (presence == null)
  11432. {
  11433. // we send to all
  11434. landData.MediaID = new UUID(texture);
  11435. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  11436. landData.MediaWidth = width;
  11437. landData.MediaHeight = height;
  11438. landData.MediaType = mediaType;
  11439. // do that one last, it will cause a ParcelPropertiesUpdate
  11440. landObject.SetMediaUrl(url);
  11441. // now send to all (non-child) agents in the parcel
  11442. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11443. {
  11444. if (sp.currentParcelUUID == landData.GlobalID)
  11445. {
  11446. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  11447. landData.MediaID,
  11448. landData.MediaAutoScale,
  11449. mediaType,
  11450. description,
  11451. width, height,
  11452. loop);
  11453. }
  11454. });
  11455. }
  11456. else if (!presence.IsChildAgent)
  11457. {
  11458. // we only send to one (root) agent
  11459. presence.ControllingClient.SendParcelMediaUpdate(url,
  11460. new UUID(texture),
  11461. autoAlign ? (byte)1 : (byte)0,
  11462. mediaType,
  11463. description,
  11464. width, height,
  11465. loop);
  11466. }
  11467. }
  11468. if (commandToSend != null)
  11469. {
  11470. // the commandList contained a start/stop/... command, too
  11471. if (presence == null)
  11472. {
  11473. // send to all (non-child) agents in the parcel
  11474. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11475. {
  11476. if (sp.currentParcelUUID == landData.GlobalID)
  11477. {
  11478. sp.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11479. commandToSend.Value, time);
  11480. }
  11481. });
  11482. }
  11483. else if (!presence.IsChildAgent)
  11484. {
  11485. presence.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11486. commandToSend.Value, time);
  11487. }
  11488. }
  11489. ScriptSleep(m_sleepMsOnParcelMediaCommandList);
  11490. }
  11491. public LSL_List llParcelMediaQuery(LSL_List aList)
  11492. {
  11493. m_host.AddScriptLPS(1);
  11494. LSL_List list = new LSL_List();
  11495. Vector3 pos = m_host.AbsolutePosition;
  11496. ILandObject landObject = World.LandChannel.GetLandObject(pos);
  11497. if(landObject == null)
  11498. return list;
  11499. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false))
  11500. return list;
  11501. LandData land = landObject.LandData;
  11502. if(land == null)
  11503. return list;
  11504. //TO DO: make the implementation for the missing commands
  11505. //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)
  11506. for (int i = 0; i < aList.Data.Length; i++)
  11507. {
  11508. if (aList.Data[i] != null)
  11509. {
  11510. switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
  11511. {
  11512. case ParcelMediaCommandEnum.Url:
  11513. list.Add(new LSL_String(land.MediaURL));
  11514. break;
  11515. case ParcelMediaCommandEnum.Desc:
  11516. list.Add(new LSL_String(land.MediaDescription));
  11517. break;
  11518. case ParcelMediaCommandEnum.Texture:
  11519. list.Add(new LSL_String(land.MediaID.ToString()));
  11520. break;
  11521. case ParcelMediaCommandEnum.Type:
  11522. list.Add(new LSL_String(land.MediaType));
  11523. break;
  11524. case ParcelMediaCommandEnum.Size:
  11525. list.Add(new LSL_String(land.MediaWidth));
  11526. list.Add(new LSL_String(land.MediaHeight));
  11527. break;
  11528. default:
  11529. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  11530. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  11531. break;
  11532. }
  11533. }
  11534. }
  11535. ScriptSleep(m_sleepMsOnParcelMediaQuery);
  11536. return list;
  11537. }
  11538. public LSL_Integer llModPow(int a, int b, int c)
  11539. {
  11540. m_host.AddScriptLPS(1);
  11541. Int64 tmp = 0;
  11542. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  11543. ScriptSleep(m_sleepMsOnModPow);
  11544. return Convert.ToInt32(tmp);
  11545. }
  11546. public LSL_Integer llGetInventoryType(string name)
  11547. {
  11548. m_host.AddScriptLPS(1);
  11549. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11550. if (item == null)
  11551. return -1;
  11552. return item.Type;
  11553. }
  11554. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  11555. {
  11556. m_host.AddScriptLPS(1);
  11557. if (quick_pay_buttons.Data.Length < 4)
  11558. {
  11559. int x;
  11560. for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
  11561. {
  11562. quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
  11563. }
  11564. }
  11565. int[] nPrice = new int[5];
  11566. nPrice[0] = price;
  11567. nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
  11568. nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
  11569. nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
  11570. nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
  11571. m_host.ParentGroup.RootPart.PayPrice = nPrice;
  11572. m_host.ParentGroup.HasGroupChanged = true;
  11573. }
  11574. public LSL_Vector llGetCameraPos()
  11575. {
  11576. m_host.AddScriptLPS(1);
  11577. if (m_item.PermsGranter == UUID.Zero)
  11578. return Vector3.Zero;
  11579. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11580. {
  11581. Error("llGetCameraPos", "No permissions to track the camera");
  11582. return Vector3.Zero;
  11583. }
  11584. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11585. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11586. if (presence != null)
  11587. {
  11588. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  11589. return pos;
  11590. }
  11591. return Vector3.Zero;
  11592. }
  11593. public LSL_Rotation llGetCameraRot()
  11594. {
  11595. m_host.AddScriptLPS(1);
  11596. if (m_item.PermsGranter == UUID.Zero)
  11597. return Quaternion.Identity;
  11598. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11599. {
  11600. Error("llGetCameraRot", "No permissions to track the camera");
  11601. return Quaternion.Identity;
  11602. }
  11603. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11604. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11605. if (presence != null)
  11606. {
  11607. return new LSL_Rotation(presence.CameraRotation);
  11608. }
  11609. return Quaternion.Identity;
  11610. }
  11611. public void llSetPrimURL(string url)
  11612. {
  11613. m_host.AddScriptLPS(1);
  11614. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  11615. ScriptSleep(m_sleepMsOnSetPrimURL);
  11616. }
  11617. public void llRefreshPrimURL()
  11618. {
  11619. m_host.AddScriptLPS(1);
  11620. Deprecated("llRefreshPrimURL");
  11621. ScriptSleep(m_sleepMsOnRefreshPrimURL);
  11622. }
  11623. public LSL_String llEscapeURL(string url)
  11624. {
  11625. m_host.AddScriptLPS(1);
  11626. try
  11627. {
  11628. return Uri.EscapeDataString(url);
  11629. }
  11630. catch (Exception ex)
  11631. {
  11632. return "llEscapeURL: " + ex.ToString();
  11633. }
  11634. }
  11635. public LSL_String llUnescapeURL(string url)
  11636. {
  11637. m_host.AddScriptLPS(1);
  11638. try
  11639. {
  11640. return Uri.UnescapeDataString(url);
  11641. }
  11642. catch (Exception ex)
  11643. {
  11644. return "llUnescapeURL: " + ex.ToString();
  11645. }
  11646. }
  11647. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  11648. {
  11649. m_host.AddScriptLPS(1);
  11650. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  11651. if (detectedParams == null)
  11652. {
  11653. if (m_host.ParentGroup.IsAttachment == true)
  11654. {
  11655. detectedParams = new DetectParams();
  11656. detectedParams.Key = m_host.OwnerID;
  11657. }
  11658. else
  11659. {
  11660. return;
  11661. }
  11662. }
  11663. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  11664. if (avatar != null)
  11665. {
  11666. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  11667. simname, pos, lookAt);
  11668. }
  11669. ScriptSleep(m_sleepMsOnMapDestination);
  11670. }
  11671. public void llAddToLandBanList(LSL_Key avatar, double hours)
  11672. {
  11673. m_host.AddScriptLPS(1);
  11674. UUID key;
  11675. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11676. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11677. {
  11678. int expires = 0;
  11679. if (hours != 0)
  11680. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  11681. if (UUID.TryParse(avatar, out key))
  11682. {
  11683. int idx = land.LandData.ParcelAccessList.FindIndex(
  11684. delegate(LandAccessEntry e)
  11685. {
  11686. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11687. return true;
  11688. return false;
  11689. });
  11690. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  11691. return;
  11692. if (idx != -1)
  11693. land.LandData.ParcelAccessList.RemoveAt(idx);
  11694. LandAccessEntry entry = new LandAccessEntry();
  11695. entry.AgentID = key;
  11696. entry.Flags = AccessList.Ban;
  11697. entry.Expires = expires;
  11698. land.LandData.ParcelAccessList.Add(entry);
  11699. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11700. }
  11701. }
  11702. ScriptSleep(m_sleepMsOnAddToLandBanList);
  11703. }
  11704. public void llRemoveFromLandPassList(string avatar)
  11705. {
  11706. m_host.AddScriptLPS(1);
  11707. UUID key;
  11708. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11709. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  11710. {
  11711. if (UUID.TryParse(avatar, out key))
  11712. {
  11713. int idx = land.LandData.ParcelAccessList.FindIndex(
  11714. delegate(LandAccessEntry e)
  11715. {
  11716. if (e.AgentID == key && e.Flags == AccessList.Access)
  11717. return true;
  11718. return false;
  11719. });
  11720. if (idx != -1)
  11721. {
  11722. land.LandData.ParcelAccessList.RemoveAt(idx);
  11723. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11724. }
  11725. }
  11726. }
  11727. ScriptSleep(m_sleepMsOnRemoveFromLandPassList);
  11728. }
  11729. public void llRemoveFromLandBanList(string avatar)
  11730. {
  11731. m_host.AddScriptLPS(1);
  11732. UUID key;
  11733. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11734. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11735. {
  11736. if (UUID.TryParse(avatar, out key))
  11737. {
  11738. int idx = land.LandData.ParcelAccessList.FindIndex(
  11739. delegate(LandAccessEntry e)
  11740. {
  11741. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11742. return true;
  11743. return false;
  11744. });
  11745. if (idx != -1)
  11746. {
  11747. land.LandData.ParcelAccessList.RemoveAt(idx);
  11748. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11749. }
  11750. }
  11751. }
  11752. ScriptSleep(m_sleepMsOnRemoveFromLandBanList);
  11753. }
  11754. public void llSetCameraParams(LSL_List rules)
  11755. {
  11756. m_host.AddScriptLPS(1);
  11757. // the object we are in
  11758. UUID objectID = m_host.ParentUUID;
  11759. if (objectID == UUID.Zero)
  11760. return;
  11761. // we need the permission first, to know which avatar we want to set the camera for
  11762. UUID agentID = m_item.PermsGranter;
  11763. if (agentID == UUID.Zero)
  11764. return;
  11765. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11766. return;
  11767. ScenePresence presence = World.GetScenePresence(agentID);
  11768. // we are not interested in child-agents
  11769. if (presence.IsChildAgent) return;
  11770. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  11771. object[] data = rules.Data;
  11772. for (int i = 0; i < data.Length; ++i)
  11773. {
  11774. int type;
  11775. try
  11776. {
  11777. type = Convert.ToInt32(data[i++].ToString());
  11778. }
  11779. catch
  11780. {
  11781. Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
  11782. return;
  11783. }
  11784. if (i >= data.Length) break; // odd number of entries => ignore the last
  11785. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  11786. switch (type)
  11787. {
  11788. case ScriptBaseClass.CAMERA_FOCUS:
  11789. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11790. case ScriptBaseClass.CAMERA_POSITION:
  11791. LSL_Vector v = (LSL_Vector)data[i];
  11792. try
  11793. {
  11794. parameters.Add(type + 1, (float)v.x);
  11795. }
  11796. catch
  11797. {
  11798. switch(type)
  11799. {
  11800. case ScriptBaseClass.CAMERA_FOCUS:
  11801. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
  11802. return;
  11803. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11804. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
  11805. return;
  11806. case ScriptBaseClass.CAMERA_POSITION:
  11807. Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
  11808. return;
  11809. }
  11810. }
  11811. try
  11812. {
  11813. parameters.Add(type + 2, (float)v.y);
  11814. }
  11815. catch
  11816. {
  11817. switch(type)
  11818. {
  11819. case ScriptBaseClass.CAMERA_FOCUS:
  11820. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
  11821. return;
  11822. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11823. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
  11824. return;
  11825. case ScriptBaseClass.CAMERA_POSITION:
  11826. Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
  11827. return;
  11828. }
  11829. }
  11830. try
  11831. {
  11832. parameters.Add(type + 3, (float)v.z);
  11833. }
  11834. catch
  11835. {
  11836. switch(type)
  11837. {
  11838. case ScriptBaseClass.CAMERA_FOCUS:
  11839. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
  11840. return;
  11841. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11842. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
  11843. return;
  11844. case ScriptBaseClass.CAMERA_POSITION:
  11845. Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
  11846. return;
  11847. }
  11848. }
  11849. break;
  11850. default:
  11851. // TODO: clean that up as soon as the implicit casts are in
  11852. if (data[i] is LSL_Float)
  11853. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  11854. else if (data[i] is LSL_Integer)
  11855. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  11856. else
  11857. {
  11858. try
  11859. {
  11860. parameters.Add(type, Convert.ToSingle(data[i]));
  11861. }
  11862. catch
  11863. {
  11864. Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
  11865. }
  11866. }
  11867. break;
  11868. }
  11869. }
  11870. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  11871. }
  11872. public void llClearCameraParams()
  11873. {
  11874. m_host.AddScriptLPS(1);
  11875. // the object we are in
  11876. UUID objectID = m_host.ParentUUID;
  11877. if (objectID == UUID.Zero)
  11878. return;
  11879. // we need the permission first, to know which avatar we want to clear the camera for
  11880. UUID agentID = m_item.PermsGranter;
  11881. if (agentID == UUID.Zero)
  11882. return;
  11883. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11884. return;
  11885. ScenePresence presence = World.GetScenePresence(agentID);
  11886. // we are not interested in child-agents
  11887. if (presence.IsChildAgent)
  11888. return;
  11889. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  11890. }
  11891. public LSL_Float llListStatistics(int operation, LSL_List src)
  11892. {
  11893. m_host.AddScriptLPS(1);
  11894. switch (operation)
  11895. {
  11896. case ScriptBaseClass.LIST_STAT_RANGE:
  11897. return src.Range();
  11898. case ScriptBaseClass.LIST_STAT_MIN:
  11899. return src.Min();
  11900. case ScriptBaseClass.LIST_STAT_MAX:
  11901. return src.Max();
  11902. case ScriptBaseClass.LIST_STAT_MEAN:
  11903. return src.Mean();
  11904. case ScriptBaseClass.LIST_STAT_MEDIAN:
  11905. return LSL_List.ToDoubleList(src).Median();
  11906. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  11907. return src.NumericLength();
  11908. case ScriptBaseClass.LIST_STAT_STD_DEV:
  11909. return src.StdDev();
  11910. case ScriptBaseClass.LIST_STAT_SUM:
  11911. return src.Sum();
  11912. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  11913. return src.SumSqrs();
  11914. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  11915. return src.GeometricMean();
  11916. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  11917. return src.HarmonicMean();
  11918. default:
  11919. return 0.0;
  11920. }
  11921. }
  11922. public LSL_Integer llGetUnixTime()
  11923. {
  11924. m_host.AddScriptLPS(1);
  11925. return Util.UnixTimeSinceEpoch();
  11926. }
  11927. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  11928. {
  11929. m_host.AddScriptLPS(1);
  11930. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  11931. }
  11932. public LSL_Integer llGetRegionFlags()
  11933. {
  11934. m_host.AddScriptLPS(1);
  11935. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  11936. if (estate == null)
  11937. return 67108864;
  11938. return (int)estate.GetRegionFlags();
  11939. }
  11940. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  11941. {
  11942. m_host.AddScriptLPS(1);
  11943. if (str1 == String.Empty)
  11944. return String.Empty;
  11945. if (str2 == String.Empty)
  11946. return str1;
  11947. int len = str2.Length;
  11948. if ((len % 4) != 0) // LL is EVIL!!!!
  11949. {
  11950. while (str2.EndsWith("="))
  11951. str2 = str2.Substring(0, str2.Length - 1);
  11952. len = str2.Length;
  11953. int mod = len % 4;
  11954. if (mod == 1)
  11955. str2 = str2.Substring(0, str2.Length - 1);
  11956. else if (mod == 2)
  11957. str2 += "==";
  11958. else if (mod == 3)
  11959. str2 += "=";
  11960. }
  11961. byte[] data1;
  11962. byte[] data2;
  11963. try
  11964. {
  11965. data1 = Convert.FromBase64String(str1);
  11966. data2 = Convert.FromBase64String(str2);
  11967. }
  11968. catch (Exception)
  11969. {
  11970. return new LSL_String(String.Empty);
  11971. }
  11972. byte[] d2 = new Byte[data1.Length];
  11973. int pos = 0;
  11974. if (data1.Length <= data2.Length)
  11975. {
  11976. Array.Copy(data2, 0, d2, 0, data1.Length);
  11977. }
  11978. else
  11979. {
  11980. while (pos < data1.Length)
  11981. {
  11982. len = data1.Length - pos;
  11983. if (len > data2.Length)
  11984. len = data2.Length;
  11985. Array.Copy(data2, 0, d2, pos, len);
  11986. pos += len;
  11987. }
  11988. }
  11989. for (pos = 0 ; pos < data1.Length ; pos++ )
  11990. data1[pos] ^= d2[pos];
  11991. return Convert.ToBase64String(data1);
  11992. }
  11993. public LSL_Key llHTTPRequest(string url, LSL_List parameters, string body)
  11994. {
  11995. m_host.AddScriptLPS(1);
  11996. IHttpRequestModule httpScriptMod = m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  11997. if(httpScriptMod == null)
  11998. return "";
  11999. if(!httpScriptMod.CheckThrottle(m_host.LocalId, m_host.OwnerID))
  12000. return UUID.Zero.ToString();
  12001. List<string> param = new List<string>();
  12002. bool ok;
  12003. Int32 flag;
  12004. int nCustomHeaders = 0;
  12005. for (int i = 0; i < parameters.Data.Length; i += 2)
  12006. {
  12007. ok = Int32.TryParse(parameters.Data[i].ToString(), out flag);
  12008. if (!ok || flag < 0 ||
  12009. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  12010. {
  12011. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  12012. }
  12013. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  12014. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  12015. {
  12016. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  12017. }
  12018. else
  12019. {
  12020. //Parameters are in pairs and custom header takes
  12021. //arguments in pairs so adjust for header marker.
  12022. ++i;
  12023. //Maximum of 8 headers are allowed based on the
  12024. //Second Life documentation for llHTTPRequest.
  12025. for (int count = 1; count <= 8; ++count)
  12026. {
  12027. if(nCustomHeaders >= 8)
  12028. {
  12029. Error("llHTTPRequest", "Max number of custom headers is 8, excess ignored");
  12030. break;
  12031. }
  12032. //Enough parameters remaining for (another) header?
  12033. if (parameters.Data.Length - i < 2)
  12034. {
  12035. //There must be at least one name/value pair for custom header
  12036. if (count == 1)
  12037. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  12038. break;
  12039. }
  12040. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString(), StringComparer.OrdinalIgnoreCase))
  12041. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  12042. param.Add(parameters.Data[i].ToString());
  12043. param.Add(parameters.Data[i+1].ToString());
  12044. nCustomHeaders++;
  12045. //Have we reached the end of the list of headers?
  12046. //End is marked by a string with a single digit.
  12047. if (i + 2 >= parameters.Data.Length ||
  12048. Char.IsDigit(parameters.Data[i + 2].ToString()[0]))
  12049. {
  12050. break;
  12051. }
  12052. i += 2;
  12053. }
  12054. }
  12055. }
  12056. Vector3 position = m_host.AbsolutePosition;
  12057. Vector3 velocity = m_host.Velocity;
  12058. Quaternion rotation = m_host.RotationOffset;
  12059. string ownerName = String.Empty;
  12060. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  12061. if (scenePresence == null)
  12062. ownerName = resolveName(m_host.OwnerID);
  12063. else
  12064. ownerName = scenePresence.Name;
  12065. RegionInfo regionInfo = World.RegionInfo;
  12066. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  12067. string shard = "OpenSim";
  12068. IConfigSource config = m_ScriptEngine.ConfigSource;
  12069. if (config.Configs["Network"] != null)
  12070. {
  12071. shard = config.Configs["Network"].GetString("shard", shard);
  12072. }
  12073. httpHeaders["X-SecondLife-Shard"] = shard;
  12074. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  12075. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  12076. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  12077. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  12078. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  12079. 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);
  12080. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  12081. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  12082. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  12083. if (userAgent != null)
  12084. httpHeaders["User-Agent"] = userAgent;
  12085. // See if the URL contains any header hacks
  12086. string[] urlParts = url.Split(new char[] {'\n'});
  12087. if (urlParts.Length > 1)
  12088. {
  12089. // Iterate the passed headers and parse them
  12090. for (int i = 1 ; i < urlParts.Length ; i++ )
  12091. {
  12092. // The rest of those would be added to the body in SL.
  12093. // Let's not do that.
  12094. if (urlParts[i] == String.Empty)
  12095. break;
  12096. // See if this could be a valid header
  12097. string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
  12098. if (headerParts.Length != 2)
  12099. continue;
  12100. string headerName = headerParts[0].Trim();
  12101. string headerValue = headerParts[1].Trim();
  12102. // Filter out headers that could be used to abuse
  12103. // another system or cloak the request
  12104. if (headerName.ToLower() == "x-secondlife-shard" ||
  12105. headerName.ToLower() == "x-secondlife-object-name" ||
  12106. headerName.ToLower() == "x-secondlife-object-key" ||
  12107. headerName.ToLower() == "x-secondlife-region" ||
  12108. headerName.ToLower() == "x-secondlife-local-position" ||
  12109. headerName.ToLower() == "x-secondlife-local-velocity" ||
  12110. headerName.ToLower() == "x-secondlife-local-rotation" ||
  12111. headerName.ToLower() == "x-secondlife-owner-name" ||
  12112. headerName.ToLower() == "x-secondlife-owner-key" ||
  12113. headerName.ToLower() == "connection" ||
  12114. headerName.ToLower() == "content-length" ||
  12115. headerName.ToLower() == "from" ||
  12116. headerName.ToLower() == "host" ||
  12117. headerName.ToLower() == "proxy-authorization" ||
  12118. headerName.ToLower() == "referer" ||
  12119. headerName.ToLower() == "trailer" ||
  12120. headerName.ToLower() == "transfer-encoding" ||
  12121. headerName.ToLower() == "via" ||
  12122. headerName.ToLower() == "authorization")
  12123. continue;
  12124. httpHeaders[headerName] = headerValue;
  12125. }
  12126. // Finally, strip any protocol specifier from the URL
  12127. url = urlParts[0].Trim();
  12128. int idx = url.IndexOf(" HTTP/");
  12129. if (idx != -1)
  12130. url = url.Substring(0, idx);
  12131. }
  12132. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  12133. Regex r = new Regex(authregex);
  12134. int[] gnums = r.GetGroupNumbers();
  12135. Match m = r.Match(url);
  12136. if (m.Success)
  12137. {
  12138. for (int i = 1; i < gnums.Length; i++)
  12139. {
  12140. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  12141. //CaptureCollection cc = g.Captures;
  12142. }
  12143. if (m.Groups.Count == 5)
  12144. {
  12145. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  12146. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  12147. }
  12148. }
  12149. HttpInitialRequestStatus status;
  12150. UUID reqID = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body, out status);
  12151. if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER)
  12152. Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url));
  12153. if (reqID != UUID.Zero)
  12154. return reqID.ToString();
  12155. else
  12156. return "";
  12157. }
  12158. public void llHTTPResponse(LSL_Key id, int status, string body)
  12159. {
  12160. // Partial implementation: support for parameter flags needed
  12161. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  12162. m_host.AddScriptLPS(1);
  12163. if (m_UrlModule != null)
  12164. m_UrlModule.HttpResponse(new UUID(id), status,body);
  12165. }
  12166. public void llResetLandBanList()
  12167. {
  12168. m_host.AddScriptLPS(1);
  12169. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12170. if (land.OwnerID == m_host.OwnerID)
  12171. {
  12172. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12173. {
  12174. if (entry.Flags == AccessList.Ban)
  12175. {
  12176. land.ParcelAccessList.Remove(entry);
  12177. }
  12178. }
  12179. }
  12180. ScriptSleep(m_sleepMsOnResetLandBanList);
  12181. }
  12182. public void llResetLandPassList()
  12183. {
  12184. m_host.AddScriptLPS(1);
  12185. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12186. if (land.OwnerID == m_host.OwnerID)
  12187. {
  12188. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12189. {
  12190. if (entry.Flags == AccessList.Access)
  12191. {
  12192. land.ParcelAccessList.Remove(entry);
  12193. }
  12194. }
  12195. }
  12196. ScriptSleep(m_sleepMsOnResetLandPassList);
  12197. }
  12198. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  12199. {
  12200. m_host.AddScriptLPS(1);
  12201. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12202. if (lo == null)
  12203. return 0;
  12204. IPrimCounts pc = lo.PrimCounts;
  12205. if (sim_wide != ScriptBaseClass.FALSE)
  12206. {
  12207. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12208. {
  12209. return pc.Simulator;
  12210. }
  12211. else
  12212. {
  12213. // counts not implemented yet
  12214. return 0;
  12215. }
  12216. }
  12217. else
  12218. {
  12219. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12220. return pc.Total;
  12221. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  12222. return pc.Owner;
  12223. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  12224. return pc.Group;
  12225. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  12226. return pc.Others;
  12227. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  12228. return pc.Selected;
  12229. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  12230. return 0; // counts not implemented yet
  12231. }
  12232. return 0;
  12233. }
  12234. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  12235. {
  12236. m_host.AddScriptLPS(1);
  12237. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12238. LSL_List ret = new LSL_List();
  12239. if (land != null)
  12240. {
  12241. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  12242. {
  12243. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  12244. ret.Add(new LSL_Integer(detectedParams.Value));
  12245. }
  12246. }
  12247. ScriptSleep(m_sleepMsOnGetParcelPrimOwners);
  12248. return ret;
  12249. }
  12250. public LSL_Integer llGetObjectPrimCount(LSL_Key object_id)
  12251. {
  12252. m_host.AddScriptLPS(1);
  12253. UUID id;
  12254. if(!UUID.TryParse(object_id, out id))
  12255. return 0;
  12256. SceneObjectPart part = World.GetSceneObjectPart(id);
  12257. if (part == null)
  12258. return 0;
  12259. return part.ParentGroup.PrimCount;
  12260. }
  12261. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  12262. {
  12263. m_host.AddScriptLPS(1);
  12264. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12265. if (lo == null)
  12266. return 0;
  12267. if (sim_wide != 0)
  12268. return lo.GetSimulatorMaxPrimCount();
  12269. else
  12270. return lo.GetParcelMaxPrimCount();
  12271. }
  12272. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  12273. {
  12274. m_host.AddScriptLPS(1);
  12275. LandData land = World.GetLandData(pos);
  12276. if (land == null)
  12277. {
  12278. return new LSL_List(0);
  12279. }
  12280. LSL_List ret = new LSL_List();
  12281. foreach (object o in param.Data)
  12282. {
  12283. switch (o.ToString())
  12284. {
  12285. case "0":
  12286. ret.Add(new LSL_String(land.Name));
  12287. break;
  12288. case "1":
  12289. ret.Add(new LSL_String(land.Description));
  12290. break;
  12291. case "2":
  12292. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  12293. break;
  12294. case "3":
  12295. ret.Add(new LSL_Key(land.GroupID.ToString()));
  12296. break;
  12297. case "4":
  12298. ret.Add(new LSL_Integer(land.Area));
  12299. break;
  12300. case "5":
  12301. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  12302. break;
  12303. default:
  12304. ret.Add(new LSL_Integer(0));
  12305. break;
  12306. }
  12307. }
  12308. return ret;
  12309. }
  12310. public LSL_String llStringTrim(LSL_String src, LSL_Integer type)
  12311. {
  12312. m_host.AddScriptLPS(1);
  12313. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return ((string)src).TrimStart(); }
  12314. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return ((string)src).TrimEnd(); }
  12315. if (type == (int)ScriptBaseClass.STRING_TRIM) { return ((string)src).Trim(); }
  12316. return src;
  12317. }
  12318. public LSL_List llGetObjectDetails(LSL_Key id, LSL_List args)
  12319. {
  12320. m_host.AddScriptLPS(1);
  12321. LSL_List ret = new LSL_List();
  12322. UUID key = new UUID();
  12323. if (!UUID.TryParse(id, out key))
  12324. return ret;
  12325. ScenePresence av = World.GetScenePresence(key);
  12326. if (av != null)
  12327. {
  12328. foreach (object o in args.Data)
  12329. {
  12330. switch (int.Parse(o.ToString()))
  12331. {
  12332. case ScriptBaseClass.OBJECT_NAME:
  12333. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  12334. break;
  12335. case ScriptBaseClass.OBJECT_DESC:
  12336. ret.Add(new LSL_String(""));
  12337. break;
  12338. case ScriptBaseClass.OBJECT_POS:
  12339. Vector3 avpos;
  12340. if (av.ParentID != 0 && av.ParentPart != null &&
  12341. av.ParentPart.ParentGroup != null && av.ParentPart.ParentGroup.RootPart != null )
  12342. {
  12343. avpos = av.OffsetPosition;
  12344. if(!av.LegacySitOffsets)
  12345. {
  12346. Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
  12347. avpos -= sitOffset;
  12348. }
  12349. SceneObjectPart sitRoot = av.ParentPart.ParentGroup.RootPart;
  12350. avpos = sitRoot.GetWorldPosition() + avpos * sitRoot.GetWorldRotation();
  12351. }
  12352. else
  12353. avpos = av.AbsolutePosition;
  12354. ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
  12355. break;
  12356. case ScriptBaseClass.OBJECT_ROT:
  12357. Quaternion avrot = av.GetWorldRotation();
  12358. ret.Add(new LSL_Rotation(avrot));
  12359. break;
  12360. case ScriptBaseClass.OBJECT_VELOCITY:
  12361. Vector3 avvel = av.GetWorldVelocity();
  12362. ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
  12363. break;
  12364. case ScriptBaseClass.OBJECT_OWNER:
  12365. ret.Add(new LSL_Key((string)id));
  12366. break;
  12367. case ScriptBaseClass.OBJECT_GROUP:
  12368. ret.Add(new LSL_String(UUID.Zero.ToString()));
  12369. break;
  12370. case ScriptBaseClass.OBJECT_CREATOR:
  12371. ret.Add(new LSL_Key(UUID.Zero.ToString()));
  12372. break;
  12373. // For the following 8 see the Object version below
  12374. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12375. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  12376. break;
  12377. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12378. ret.Add(new LSL_Integer(av.ScriptCount()));
  12379. break;
  12380. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12381. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  12382. break;
  12383. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12384. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  12385. break;
  12386. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12387. ret.Add(new LSL_Integer(1));
  12388. break;
  12389. case ScriptBaseClass.OBJECT_SERVER_COST:
  12390. ret.Add(new LSL_Float(0));
  12391. break;
  12392. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12393. ret.Add(new LSL_Float(0));
  12394. break;
  12395. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12396. ret.Add(new LSL_Float(0));
  12397. break;
  12398. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12399. ret.Add(new LSL_Float(0));
  12400. break;
  12401. case ScriptBaseClass.OBJECT_ROOT:
  12402. SceneObjectPart p = av.ParentPart;
  12403. if (p != null)
  12404. {
  12405. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  12406. }
  12407. else
  12408. {
  12409. ret.Add(new LSL_Key((string)id));
  12410. }
  12411. break;
  12412. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12413. ret.Add(new LSL_Integer(0));
  12414. break;
  12415. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  12416. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  12417. break;
  12418. case ScriptBaseClass.OBJECT_PHYSICS:
  12419. ret.Add(new LSL_Integer(0));
  12420. break;
  12421. case ScriptBaseClass.OBJECT_PHANTOM:
  12422. ret.Add(new LSL_Integer(0));
  12423. break;
  12424. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12425. ret.Add(new LSL_Integer(0));
  12426. break;
  12427. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12428. ret.Add(new LSL_Integer(-1));
  12429. break;
  12430. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12431. ret.Add(new LSL_Float(0));
  12432. break;
  12433. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12434. LSL_Float shapeType;
  12435. if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0)
  12436. shapeType = new LSL_Float(1);
  12437. else
  12438. shapeType = new LSL_Float(0);
  12439. ret.Add(shapeType);
  12440. break;
  12441. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12442. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12443. break;
  12444. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12445. ret.Add(new LSL_Integer(0));
  12446. break;
  12447. case ScriptBaseClass.OBJECT_OMEGA:
  12448. ret.Add(new LSL_Vector(Vector3.Zero));
  12449. break;
  12450. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12451. List<SceneObjectGroup> Attachments = av.GetAttachments();
  12452. int count = 0;
  12453. try
  12454. {
  12455. foreach (SceneObjectGroup Attachment in Attachments)
  12456. count += Attachment.PrimCount;
  12457. } catch { };
  12458. ret.Add(new LSL_Integer(count));
  12459. break;
  12460. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12461. List<SceneObjectGroup> invAttachments = av.GetAttachments();
  12462. int invcount = 0;
  12463. try
  12464. {
  12465. foreach (SceneObjectGroup Attachment in invAttachments)
  12466. {
  12467. SceneObjectPart[] parts = Attachment.Parts;
  12468. int nparts = parts.Count();
  12469. for(int i = 0; i < nparts; i++)
  12470. invcount += parts[i].Inventory.Count;
  12471. }
  12472. } catch { };
  12473. ret.Add(new LSL_Integer(invcount));
  12474. break;
  12475. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12476. ret.Add(new LSL_Key((string)id));
  12477. break;
  12478. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12479. ret.Add(new LSL_String(av.Grouptitle));
  12480. break;
  12481. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12482. ret.Add(new LSL_Integer(0));
  12483. break;
  12484. default:
  12485. // Invalid or unhandled constant.
  12486. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12487. break;
  12488. }
  12489. }
  12490. return ret;
  12491. }
  12492. SceneObjectPart obj = World.GetSceneObjectPart(key);
  12493. if (obj != null)
  12494. {
  12495. foreach (object o in args.Data)
  12496. {
  12497. switch (int.Parse(o.ToString()))
  12498. {
  12499. case ScriptBaseClass.OBJECT_NAME:
  12500. ret.Add(new LSL_String(obj.Name));
  12501. break;
  12502. case ScriptBaseClass.OBJECT_DESC:
  12503. ret.Add(new LSL_String(obj.Description));
  12504. break;
  12505. case ScriptBaseClass.OBJECT_POS:
  12506. Vector3 opos = obj.AbsolutePosition;
  12507. ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
  12508. break;
  12509. case ScriptBaseClass.OBJECT_ROT:
  12510. Quaternion rot = Quaternion.Identity;
  12511. if (obj.ParentGroup.IsAttachment)
  12512. {
  12513. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12514. if (sp != null)
  12515. rot = sp.GetWorldRotation();
  12516. }
  12517. else
  12518. {
  12519. if (obj.ParentGroup.RootPart == obj)
  12520. rot = obj.ParentGroup.GroupRotation;
  12521. else
  12522. rot = obj.GetWorldRotation();
  12523. }
  12524. LSL_Rotation objrot = new LSL_Rotation(rot);
  12525. ret.Add(objrot);
  12526. break;
  12527. case ScriptBaseClass.OBJECT_VELOCITY:
  12528. Vector3 vel = Vector3.Zero;
  12529. if (obj.ParentGroup.IsAttachment)
  12530. {
  12531. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12532. if (sp != null)
  12533. vel = sp.GetWorldVelocity();
  12534. }
  12535. else
  12536. {
  12537. vel = obj.Velocity;
  12538. }
  12539. ret.Add(vel);
  12540. break;
  12541. case ScriptBaseClass.OBJECT_OWNER:
  12542. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  12543. break;
  12544. case ScriptBaseClass.OBJECT_GROUP:
  12545. ret.Add(new LSL_String(obj.GroupID.ToString()));
  12546. break;
  12547. case ScriptBaseClass.OBJECT_CREATOR:
  12548. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  12549. break;
  12550. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12551. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  12552. break;
  12553. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12554. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  12555. break;
  12556. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12557. // The value returned in SL for mono scripts is 65536 * number of active scripts
  12558. // and 16384 * number of active scripts for LSO. since llGetFreememory
  12559. // is coded to give the LSO value use it here
  12560. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  12561. break;
  12562. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12563. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  12564. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  12565. break;
  12566. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12567. // according to the SL wiki A prim or linkset will have prim
  12568. // equivalent of the number of prims in a linkset if it does not
  12569. // contain a mesh anywhere in the link set or is not a normal prim
  12570. // The value returned in SL for normal prims is prim count
  12571. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12572. break;
  12573. // costs below may need to be diferent for root parts, need to check
  12574. case ScriptBaseClass.OBJECT_SERVER_COST:
  12575. // The linden calculation is here
  12576. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  12577. // The value returned in SL for normal prims looks like the prim count
  12578. ret.Add(new LSL_Float(0));
  12579. break;
  12580. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12581. // The value returned in SL for normal prims is prim count * 0.06
  12582. ret.Add(new LSL_Float(obj.StreamingCost));
  12583. break;
  12584. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12585. // The value returned in SL for normal prims is prim count
  12586. ret.Add(new LSL_Float(obj.PhysicsCost));
  12587. break;
  12588. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12589. ret.Add(new LSL_Float(0));
  12590. break;
  12591. case ScriptBaseClass.OBJECT_ROOT:
  12592. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  12593. break;
  12594. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12595. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  12596. break;
  12597. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  12598. byte pcode = obj.Shape.PCode;
  12599. if (obj.ParentGroup.AttachmentPoint != 0
  12600. || pcode == (byte)PCode.Grass
  12601. || pcode == (byte)PCode.Tree
  12602. || pcode == (byte)PCode.NewTree)
  12603. {
  12604. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  12605. }
  12606. else
  12607. {
  12608. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  12609. }
  12610. break;
  12611. case ScriptBaseClass.OBJECT_PHYSICS:
  12612. if (obj.ParentGroup.AttachmentPoint != 0)
  12613. {
  12614. ret.Add(new LSL_Integer(0)); // Always false if attached
  12615. }
  12616. else
  12617. {
  12618. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  12619. }
  12620. break;
  12621. case ScriptBaseClass.OBJECT_PHANTOM:
  12622. if (obj.ParentGroup.AttachmentPoint != 0)
  12623. {
  12624. ret.Add(new LSL_Integer(0)); // Always false if attached
  12625. }
  12626. else
  12627. {
  12628. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  12629. }
  12630. break;
  12631. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12632. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  12633. break;
  12634. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12635. ret.Add(new LSL_Integer(0));
  12636. break;
  12637. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12638. ret.Add(new LSL_Float(0));
  12639. break;
  12640. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12641. ret.Add(new LSL_Float(-1));
  12642. break;
  12643. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12644. ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString()));
  12645. break;
  12646. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12647. ret.Add(new LSL_Integer(obj.ClickAction));
  12648. break;
  12649. case ScriptBaseClass.OBJECT_OMEGA:
  12650. ret.Add(new LSL_Vector(obj.AngularVelocity));
  12651. break;
  12652. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12653. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12654. break;
  12655. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12656. SceneObjectPart[] parts = obj.ParentGroup.Parts;
  12657. int nparts = parts.Count();
  12658. int count = 0;
  12659. for(int i = 0; i < nparts; i++)
  12660. count += parts[i].Inventory.Count;
  12661. ret.Add(new LSL_Integer(count));
  12662. break;
  12663. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12664. ret.Add(new LSL_Key(obj.ParentGroup.RezzerID.ToString()));
  12665. break;
  12666. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12667. ret.Add(new LSL_String(String.Empty));
  12668. break;
  12669. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12670. if (obj.ParentGroup.AttachmentPoint != 0 && obj.ParentGroup.FromItemID == UUID.Zero)
  12671. {
  12672. ret.Add(new LSL_Integer(1));
  12673. }
  12674. else
  12675. {
  12676. ret.Add(new LSL_Integer(0));
  12677. }
  12678. break;
  12679. default:
  12680. // Invalid or unhandled constant.
  12681. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12682. break;
  12683. }
  12684. }
  12685. }
  12686. return ret;
  12687. }
  12688. internal UUID GetScriptByName(string name)
  12689. {
  12690. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12691. if (item == null || item.Type != 10)
  12692. return UUID.Zero;
  12693. return item.ItemID;
  12694. }
  12695. /// <summary>
  12696. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  12697. /// </summary>
  12698. /// <param name="command">The name of the command that generated the error.</param>
  12699. /// <param name="message">The error message to report to the user.</param>
  12700. internal void Error(string command, string message)
  12701. {
  12702. string text = command + ": " + message;
  12703. if (text.Length > 1023)
  12704. {
  12705. text = text.Substring(0, 1023);
  12706. }
  12707. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  12708. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  12709. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  12710. if (wComm != null)
  12711. {
  12712. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  12713. }
  12714. }
  12715. /// <summary>
  12716. /// Reports that the command is not implemented as a script error.
  12717. /// </summary>
  12718. /// <param name="command">The name of the command that is not implemented.</param>
  12719. /// <param name="message">Additional information to report to the user. (Optional)</param>
  12720. internal void NotImplemented(string command, string message = "")
  12721. {
  12722. if (throwErrorOnNotImplemented)
  12723. {
  12724. if (message != "")
  12725. {
  12726. message = " - " + message;
  12727. }
  12728. throw new NotImplementedException("Command not implemented: " + command + message);
  12729. }
  12730. else
  12731. {
  12732. string text = "Command not implemented";
  12733. if (message != "")
  12734. {
  12735. text = text + " - " + message;
  12736. }
  12737. Error(command, text);
  12738. }
  12739. }
  12740. /// <summary>
  12741. /// Reports that the command is deprecated as a script error.
  12742. /// </summary>
  12743. /// <param name="command">The name of the command that is deprecated.</param>
  12744. /// <param name="message">Additional information to report to the user. (Optional)</param>
  12745. internal void Deprecated(string command, string message = "")
  12746. {
  12747. string text = "Command deprecated";
  12748. if (message != "")
  12749. {
  12750. text = text + " - " + message;
  12751. }
  12752. Error(command, text);
  12753. }
  12754. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  12755. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  12756. {
  12757. World.AssetService.Get(assetID.ToString(), this,
  12758. delegate(string i, object sender, AssetBase a)
  12759. {
  12760. UUID uuid = UUID.Zero;
  12761. UUID.TryParse(i, out uuid);
  12762. cb(uuid, a);
  12763. });
  12764. }
  12765. public LSL_Key llGetNumberOfNotecardLines(string name)
  12766. {
  12767. m_host.AddScriptLPS(1);
  12768. UUID assetID = UUID.Zero;
  12769. if (!UUID.TryParse(name, out assetID))
  12770. {
  12771. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12772. if (item != null && item.Type == 7)
  12773. assetID = item.AssetID;
  12774. }
  12775. if (assetID == UUID.Zero)
  12776. {
  12777. // => complain loudly, as specified by the LSL docs
  12778. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  12779. return UUID.Zero.ToString();
  12780. }
  12781. string reqIdentifier = UUID.Random().ToString();
  12782. // was: UUID tid = tid = AsyncCommands.
  12783. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  12784. if (NotecardCache.IsCached(assetID))
  12785. {
  12786. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString());
  12787. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  12788. return tid.ToString();
  12789. }
  12790. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  12791. {
  12792. if (a == null || a.Type != 7)
  12793. {
  12794. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  12795. return;
  12796. }
  12797. NotecardCache.Cache(id, a.Data);
  12798. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString());
  12799. });
  12800. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  12801. return tid.ToString();
  12802. }
  12803. public LSL_Key llGetNotecardLine(string name, int line)
  12804. {
  12805. m_host.AddScriptLPS(1);
  12806. UUID assetID = UUID.Zero;
  12807. if (!UUID.TryParse(name, out assetID))
  12808. {
  12809. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12810. if (item != null && item.Type == 7)
  12811. assetID = item.AssetID;
  12812. }
  12813. if (assetID == UUID.Zero)
  12814. {
  12815. // => complain loudly, as specified by the LSL docs
  12816. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  12817. return UUID.Zero.ToString();
  12818. }
  12819. string reqIdentifier = UUID.Random().ToString();
  12820. // was: UUID tid = tid = AsyncCommands.
  12821. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  12822. if (NotecardCache.IsCached(assetID))
  12823. {
  12824. AsyncCommands.DataserverPlugin.DataserverReply(
  12825. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  12826. ScriptSleep(m_sleepMsOnGetNotecardLine);
  12827. return tid.ToString();
  12828. }
  12829. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  12830. {
  12831. if (a == null || a.Type != 7)
  12832. {
  12833. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  12834. return;
  12835. }
  12836. //string data = Encoding.UTF8.GetString(a.Data);
  12837. //m_log.Debug(data);
  12838. NotecardCache.Cache(id, a.Data);
  12839. AsyncCommands.DataserverPlugin.DataserverReply(
  12840. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  12841. });
  12842. ScriptSleep(m_sleepMsOnGetNotecardLine);
  12843. return tid.ToString();
  12844. }
  12845. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  12846. {
  12847. UUID id;
  12848. if (!UUID.TryParse(prim, out id))
  12849. return;
  12850. SceneObjectPart obj = World.GetSceneObjectPart(id);
  12851. if (obj == null || obj.OwnerID != m_host.OwnerID)
  12852. return;
  12853. uint rulesParsed = 0;
  12854. LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
  12855. while (remaining.Length > 2)
  12856. {
  12857. int linknumber;
  12858. try
  12859. {
  12860. linknumber = remaining.GetLSLIntegerItem(0);
  12861. }
  12862. catch (InvalidCastException)
  12863. {
  12864. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET parameter must be integer", rulesParsed));
  12865. return;
  12866. }
  12867. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  12868. if (entities.Count == 0)
  12869. break;
  12870. rules = remaining.GetSublist(1, -1);
  12871. foreach (ISceneEntity entity in entities)
  12872. {
  12873. if (entity is SceneObjectPart)
  12874. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  12875. else
  12876. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  12877. }
  12878. }
  12879. }
  12880. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  12881. {
  12882. LSL_List result = new LSL_List();
  12883. UUID id;
  12884. if (!UUID.TryParse(prim, out id))
  12885. return result;
  12886. SceneObjectPart obj = World.GetSceneObjectPart(id);
  12887. if (obj == null || obj.OwnerID != m_host.OwnerID)
  12888. return result;
  12889. LSL_List remaining = GetPrimParams(obj, rules, ref result);
  12890. while (remaining.Length > 1)
  12891. {
  12892. int linknumber;
  12893. try
  12894. {
  12895. linknumber = remaining.GetLSLIntegerItem(0);
  12896. }
  12897. catch (InvalidCastException)
  12898. {
  12899. Error("", string.Format("Error PRIM_LINK_TARGET: parameter must be integer"));
  12900. return result;
  12901. }
  12902. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  12903. if (entities.Count == 0)
  12904. break;
  12905. rules = remaining.GetSublist(1, -1);
  12906. foreach (ISceneEntity entity in entities)
  12907. {
  12908. if (entity is SceneObjectPart)
  12909. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  12910. else
  12911. remaining = GetPrimParams((ScenePresence)entity, rules, ref result);
  12912. }
  12913. }
  12914. return result;
  12915. }
  12916. public void print(string str)
  12917. {
  12918. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  12919. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  12920. if (ossl != null)
  12921. {
  12922. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  12923. m_log.Info("LSL print():" + str);
  12924. }
  12925. }
  12926. public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
  12927. {
  12928. List<SceneObjectPart> parts = GetLinkParts(link);
  12929. if (parts.Count < 1)
  12930. return 0;
  12931. return GetNumberOfSides(parts[0]);
  12932. }
  12933. private string Name2Username(string name)
  12934. {
  12935. string[] parts = name.Split(new char[] {' '});
  12936. if (parts.Length < 2)
  12937. return name.ToLower();
  12938. if (parts[1] == "Resident")
  12939. return parts[0].ToLower();
  12940. return name.Replace(" ", ".").ToLower();
  12941. }
  12942. public LSL_String llGetUsername(string id)
  12943. {
  12944. return Name2Username(llKey2Name(id));
  12945. }
  12946. public LSL_Key llRequestUsername(string id)
  12947. {
  12948. UUID rq = UUID.Random();
  12949. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  12950. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
  12951. return rq.ToString();
  12952. }
  12953. public LSL_String llGetDisplayName(string id)
  12954. {
  12955. return llKey2Name(id);
  12956. }
  12957. public LSL_Key llRequestDisplayName(string id)
  12958. {
  12959. UUID rq = UUID.Random();
  12960. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  12961. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
  12962. return rq.ToString();
  12963. }
  12964. /*
  12965. private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
  12966. {
  12967. m_SayShoutCount = 0;
  12968. }
  12969. */
  12970. private struct Tri
  12971. {
  12972. public Vector3 p1;
  12973. public Vector3 p2;
  12974. public Vector3 p3;
  12975. }
  12976. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  12977. {
  12978. float height = avatar.Appearance.AvatarHeight;
  12979. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  12980. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  12981. if (point.X > b1.X && point.X < b2.X &&
  12982. point.Y > b1.Y && point.Y < b2.Y &&
  12983. point.Z > b1.Z && point.Z < b2.Z)
  12984. return true;
  12985. return false;
  12986. }
  12987. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd, bool skipPhys)
  12988. {
  12989. List<ContactResult> contacts = new List<ContactResult>();
  12990. Vector3 ab = rayEnd - rayStart;
  12991. float ablen = ab.Length();
  12992. World.ForEachScenePresence(delegate(ScenePresence sp)
  12993. {
  12994. if(skipPhys && sp.PhysicsActor != null)
  12995. return;
  12996. Vector3 ac = sp.AbsolutePosition - rayStart;
  12997. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / ablen);
  12998. if (d > 1.5)
  12999. return;
  13000. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13001. if (d2 > 0)
  13002. return;
  13003. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  13004. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  13005. if (!InBoundingBox(sp, p))
  13006. return;
  13007. ContactResult result = new ContactResult ();
  13008. result.ConsumerID = sp.LocalId;
  13009. result.Depth = Vector3.Distance(rayStart, p);
  13010. result.Normal = Vector3.Zero;
  13011. result.Pos = p;
  13012. contacts.Add(result);
  13013. });
  13014. return contacts.ToArray();
  13015. }
  13016. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  13017. {
  13018. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13019. List<ContactResult> contacts = new List<ContactResult>();
  13020. Vector3 ab = rayEnd - rayStart;
  13021. World.ForEachSOG(delegate(SceneObjectGroup group)
  13022. {
  13023. if (m_host.ParentGroup == group)
  13024. return;
  13025. if (group.IsAttachment)
  13026. return;
  13027. if (group.RootPart.PhysActor == null)
  13028. {
  13029. if (!includePhantom)
  13030. return;
  13031. }
  13032. else
  13033. {
  13034. if (group.RootPart.PhysActor.IsPhysical)
  13035. {
  13036. if (!includePhysical)
  13037. return;
  13038. }
  13039. else
  13040. {
  13041. if (!includeNonPhysical)
  13042. return;
  13043. }
  13044. }
  13045. // Find the radius ouside of which we don't even need to hit test
  13046. float minX;
  13047. float maxX;
  13048. float minY;
  13049. float maxY;
  13050. float minZ;
  13051. float maxZ;
  13052. float radius = 0.0f;
  13053. group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  13054. if (Math.Abs(minX) > radius)
  13055. radius = Math.Abs(minX);
  13056. if (Math.Abs(minY) > radius)
  13057. radius = Math.Abs(minY);
  13058. if (Math.Abs(minZ) > radius)
  13059. radius = Math.Abs(minZ);
  13060. if (Math.Abs(maxX) > radius)
  13061. radius = Math.Abs(maxX);
  13062. if (Math.Abs(maxY) > radius)
  13063. radius = Math.Abs(maxY);
  13064. if (Math.Abs(maxZ) > radius)
  13065. radius = Math.Abs(maxZ);
  13066. radius = radius*1.413f;
  13067. Vector3 ac = group.AbsolutePosition - rayStart;
  13068. // Vector3 bc = group.AbsolutePosition - rayEnd;
  13069. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  13070. // Too far off ray, don't bother
  13071. if (d > radius)
  13072. return;
  13073. // Behind ray, drop
  13074. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13075. if (d2 > 0)
  13076. return;
  13077. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13078. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  13079. // Miss.
  13080. if (!intersection.HitTF)
  13081. return;
  13082. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  13083. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  13084. //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);
  13085. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  13086. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  13087. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  13088. return;
  13089. ContactResult result = new ContactResult ();
  13090. result.ConsumerID = group.LocalId;
  13091. // result.Depth = intersection.distance;
  13092. result.Normal = intersection.normal;
  13093. result.Pos = intersection.ipoint;
  13094. result.Depth = Vector3.Mag(rayStart - result.Pos);
  13095. contacts.Add(result);
  13096. });
  13097. return contacts.ToArray();
  13098. }
  13099. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  13100. {
  13101. double[,] heightfield = World.Heightmap.GetDoubles();
  13102. List<ContactResult> contacts = new List<ContactResult>();
  13103. double min = 2048.0;
  13104. double max = 0.0;
  13105. // Find the min and max of the heightfield
  13106. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  13107. {
  13108. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  13109. {
  13110. if (heightfield[x, y] > max)
  13111. max = heightfield[x, y];
  13112. if (heightfield[x, y] < min)
  13113. min = heightfield[x, y];
  13114. }
  13115. }
  13116. // A ray extends past rayEnd, but doesn't go back before
  13117. // rayStart. If the start is above the highest point of the ground
  13118. // and the ray goes up, we can't hit the ground. Ever.
  13119. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  13120. return null;
  13121. // Same for going down
  13122. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  13123. return null;
  13124. List<Tri> trilist = new List<Tri>();
  13125. // Create our triangle list
  13126. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  13127. {
  13128. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  13129. {
  13130. Tri t1 = new Tri();
  13131. Tri t2 = new Tri();
  13132. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  13133. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  13134. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  13135. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  13136. t1.p1 = p1;
  13137. t1.p2 = p2;
  13138. t1.p3 = p3;
  13139. t2.p1 = p3;
  13140. t2.p2 = p4;
  13141. t2.p3 = p1;
  13142. trilist.Add(t1);
  13143. trilist.Add(t2);
  13144. }
  13145. }
  13146. // Ray direction
  13147. Vector3 rayDirection = rayEnd - rayStart;
  13148. foreach (Tri t in trilist)
  13149. {
  13150. // Compute triangle plane normal and edges
  13151. Vector3 u = t.p2 - t.p1;
  13152. Vector3 v = t.p3 - t.p1;
  13153. Vector3 n = Vector3.Cross(u, v);
  13154. if (n == Vector3.Zero)
  13155. continue;
  13156. Vector3 w0 = rayStart - t.p1;
  13157. double a = -Vector3.Dot(n, w0);
  13158. double b = Vector3.Dot(n, rayDirection);
  13159. // Not intersecting the plane, or in plane (same thing)
  13160. // Ignoring this MAY cause the ground to not be detected
  13161. // sometimes
  13162. if (Math.Abs(b) < 0.000001)
  13163. continue;
  13164. double r = a / b;
  13165. // ray points away from plane
  13166. if (r < 0.0)
  13167. continue;
  13168. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  13169. float uu = Vector3.Dot(u, u);
  13170. float uv = Vector3.Dot(u, v);
  13171. float vv = Vector3.Dot(v, v);
  13172. Vector3 w = ip - t.p1;
  13173. float wu = Vector3.Dot(w, u);
  13174. float wv = Vector3.Dot(w, v);
  13175. float d = uv * uv - uu * vv;
  13176. float cs = (uv * wv - vv * wu) / d;
  13177. if (cs < 0 || cs > 1.0)
  13178. continue;
  13179. float ct = (uv * wu - uu * wv) / d;
  13180. if (ct < 0 || (cs + ct) > 1.0)
  13181. continue;
  13182. // Add contact point
  13183. ContactResult result = new ContactResult ();
  13184. result.ConsumerID = 0;
  13185. result.Depth = Vector3.Distance(rayStart, ip);
  13186. result.Normal = n;
  13187. result.Pos = ip;
  13188. contacts.Add(result);
  13189. }
  13190. if (contacts.Count == 0)
  13191. return null;
  13192. contacts.Sort(delegate(ContactResult a, ContactResult b)
  13193. {
  13194. return (int)(a.Depth - b.Depth);
  13195. });
  13196. return contacts[0];
  13197. }
  13198. /*
  13199. // not done:
  13200. private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
  13201. {
  13202. ContactResult[] contacts = null;
  13203. World.ForEachSOG(delegate(SceneObjectGroup group)
  13204. {
  13205. if (m_host.ParentGroup == group)
  13206. return;
  13207. if (group.IsAttachment)
  13208. return;
  13209. if(group.RootPart.PhysActor != null)
  13210. return;
  13211. contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
  13212. });
  13213. return contacts;
  13214. }
  13215. */
  13216. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  13217. {
  13218. // Use llCastRay V3 if configured
  13219. if (m_useCastRayV3)
  13220. return llCastRayV3(start, end, options);
  13221. LSL_List list = new LSL_List();
  13222. m_host.AddScriptLPS(1);
  13223. Vector3 rayStart = start;
  13224. Vector3 rayEnd = end;
  13225. Vector3 dir = rayEnd - rayStart;
  13226. float dist = dir.Length();
  13227. int count = 1;
  13228. bool detectPhantom = false;
  13229. int dataFlags = 0;
  13230. int rejectTypes = 0;
  13231. for (int i = 0; i < options.Length; i += 2)
  13232. {
  13233. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13234. count = options.GetLSLIntegerItem(i + 1);
  13235. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13236. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  13237. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13238. dataFlags = options.GetLSLIntegerItem(i + 1);
  13239. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13240. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13241. }
  13242. if (count > 16)
  13243. count = 16;
  13244. List<ContactResult> results = new List<ContactResult>();
  13245. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  13246. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  13247. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  13248. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  13249. bool rejectHost = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOST) != 0);
  13250. bool rejectHostGroup = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOSTGROUP) != 0);
  13251. if (World.SupportsRayCastFiltered())
  13252. {
  13253. if (dist == 0)
  13254. return list;
  13255. RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull;
  13256. if (checkTerrain)
  13257. rayfilter |= RayFilterFlags.land;
  13258. if (checkAgents)
  13259. rayfilter |= RayFilterFlags.agent;
  13260. if (checkPhysical)
  13261. rayfilter |= RayFilterFlags.physical;
  13262. if (checkNonPhysical)
  13263. rayfilter |= RayFilterFlags.nonphysical;
  13264. if (detectPhantom)
  13265. rayfilter |= RayFilterFlags.LSLPhantom;
  13266. Vector3 direction = dir * ( 1/dist);
  13267. if(rayfilter == 0)
  13268. {
  13269. list.Add(new LSL_Integer(0));
  13270. return list;
  13271. }
  13272. // get some more contacts to sort ???
  13273. int physcount = 4 * count;
  13274. if (physcount > 20)
  13275. physcount = 20;
  13276. object physresults;
  13277. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  13278. if (physresults == null)
  13279. {
  13280. // list.Add(new LSL_Integer(-3)); // timeout error
  13281. // return list;
  13282. results = new List<ContactResult>();
  13283. }
  13284. else
  13285. results = (List<ContactResult>)physresults;
  13286. // for now physics doesn't detect sitted avatars so do it outside physics
  13287. if (checkAgents)
  13288. {
  13289. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, true);
  13290. foreach (ContactResult r in agentHits)
  13291. results.Add(r);
  13292. }
  13293. // TODO: Replace this with a better solution. ObjectIntersection can only
  13294. // detect nonphysical phantoms. They are detected by virtue of being
  13295. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  13296. // physicsl phantoms as done by the physics scene
  13297. // We don't want anything else but phantoms here.
  13298. if (detectPhantom)
  13299. {
  13300. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  13301. foreach (ContactResult r in objectHits)
  13302. results.Add(r);
  13303. }
  13304. // Double check this because of current ODE distance problems
  13305. if (checkTerrain && dist > 60)
  13306. {
  13307. bool skipGroundCheck = false;
  13308. foreach (ContactResult c in results)
  13309. {
  13310. if (c.ConsumerID == 0) // Physics gave us a ground collision
  13311. skipGroundCheck = true;
  13312. }
  13313. if (!skipGroundCheck)
  13314. {
  13315. float tmp = dir.X * dir.X + dir.Y * dir.Y;
  13316. if(tmp > 2500)
  13317. {
  13318. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13319. if (groundContact != null)
  13320. results.Add((ContactResult)groundContact);
  13321. }
  13322. }
  13323. }
  13324. }
  13325. else
  13326. {
  13327. if (checkAgents)
  13328. {
  13329. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, false);
  13330. foreach (ContactResult r in agentHits)
  13331. results.Add(r);
  13332. }
  13333. if (checkPhysical || checkNonPhysical || detectPhantom)
  13334. {
  13335. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  13336. for (int iter = 0; iter < objectHits.Length; iter++)
  13337. {
  13338. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  13339. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  13340. results.Add(objectHits[iter]);
  13341. }
  13342. }
  13343. if (checkTerrain)
  13344. {
  13345. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13346. if (groundContact != null)
  13347. results.Add((ContactResult)groundContact);
  13348. }
  13349. }
  13350. results.Sort(delegate(ContactResult a, ContactResult b)
  13351. {
  13352. return a.Depth.CompareTo(b.Depth);
  13353. });
  13354. int values = 0;
  13355. SceneObjectGroup thisgrp = m_host.ParentGroup;
  13356. foreach (ContactResult result in results)
  13357. {
  13358. if (result.Depth > dist)
  13359. continue;
  13360. // physics ray can return colisions with host prim
  13361. if (rejectHost && m_host.LocalId == result.ConsumerID)
  13362. continue;
  13363. UUID itemID = UUID.Zero;
  13364. int linkNum = 0;
  13365. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  13366. // It's a prim!
  13367. if (part != null)
  13368. {
  13369. if (rejectHostGroup && part.ParentGroup == thisgrp)
  13370. continue;
  13371. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  13372. itemID = part.ParentGroup.UUID;
  13373. else
  13374. itemID = part.UUID;
  13375. linkNum = part.LinkNum;
  13376. }
  13377. else
  13378. {
  13379. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  13380. /// It it a boy? a girl?
  13381. if (sp != null)
  13382. itemID = sp.UUID;
  13383. }
  13384. list.Add(new LSL_String(itemID.ToString()));
  13385. list.Add(new LSL_String(result.Pos.ToString()));
  13386. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  13387. list.Add(new LSL_Integer(linkNum));
  13388. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  13389. list.Add(new LSL_Vector(result.Normal));
  13390. values++;
  13391. if (values >= count)
  13392. break;
  13393. }
  13394. list.Add(new LSL_Integer(values));
  13395. return list;
  13396. }
  13397. /// <summary>
  13398. /// Implementation of llCastRay similar to SL 2015-04-21.
  13399. /// http://wiki.secondlife.com/wiki/LlCastRay
  13400. /// Uses pure geometry, bounding shapes, meshing and no physics
  13401. /// for prims, sculpts, meshes, avatars and terrain.
  13402. /// Implements all flags, reject types and data flags.
  13403. /// Can handle both objects/groups and prims/parts, by config.
  13404. /// May sometimes be inaccurate owing to calculation precision,
  13405. /// meshing detail level and a bug in libopenmetaverse PrimMesher.
  13406. /// </summary>
  13407. public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options)
  13408. {
  13409. m_host.AddScriptLPS(1);
  13410. LSL_List result = new LSL_List();
  13411. // Prepare throttle data
  13412. int calledMs = Environment.TickCount;
  13413. Stopwatch stopWatch = new Stopwatch();
  13414. stopWatch.Start();
  13415. UUID regionId = World.RegionInfo.RegionID;
  13416. UUID userId = UUID.Zero;
  13417. int msAvailable = 0;
  13418. // Throttle per owner when attachment or "vehicle" (sat upon)
  13419. if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatarsCount() > 0)
  13420. {
  13421. userId = m_host.OwnerID;
  13422. msAvailable = m_msPerAvatarInCastRay;
  13423. }
  13424. // Throttle per parcel when not attachment or vehicle
  13425. else
  13426. {
  13427. LandData land = World.GetLandData(m_host.GetWorldPosition());
  13428. if (land != null)
  13429. msAvailable = m_msPerRegionInCastRay * land.Area / 65536;
  13430. }
  13431. // Clamp for "oversized" parcels on varregions
  13432. if (msAvailable > m_msMaxInCastRay)
  13433. msAvailable = m_msMaxInCastRay;
  13434. // Check throttle data
  13435. int fromCalledMs = calledMs - m_msThrottleInCastRay;
  13436. lock (m_castRayCalls)
  13437. {
  13438. for (int i = m_castRayCalls.Count - 1; i >= 0; i--)
  13439. {
  13440. // Delete old calls from throttle data
  13441. if (m_castRayCalls[i].CalledMs < fromCalledMs)
  13442. m_castRayCalls.RemoveAt(i);
  13443. // Use current region (in multi-region sims)
  13444. else if (m_castRayCalls[i].RegionId == regionId)
  13445. {
  13446. // Reduce available time with recent calls
  13447. if (m_castRayCalls[i].UserId == userId)
  13448. msAvailable -= m_castRayCalls[i].UsedMs;
  13449. }
  13450. }
  13451. // Return failure if not enough available time
  13452. if (msAvailable < m_msMinInCastRay)
  13453. {
  13454. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED));
  13455. return result;
  13456. }
  13457. }
  13458. // Initialize
  13459. List<RayHit> rayHits = new List<RayHit>();
  13460. float tol = m_floatToleranceInCastRay;
  13461. Vector3 pos1Ray = start;
  13462. Vector3 pos2Ray = end;
  13463. // Get input options
  13464. int rejectTypes = 0;
  13465. int dataFlags = 0;
  13466. int maxHits = 1;
  13467. bool notdetectPhantom = true;
  13468. for (int i = 0; i < options.Length; i += 2)
  13469. {
  13470. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13471. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13472. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13473. dataFlags = options.GetLSLIntegerItem(i + 1);
  13474. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13475. maxHits = options.GetLSLIntegerItem(i + 1);
  13476. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13477. notdetectPhantom = (options.GetLSLIntegerItem(i + 1) == 0);
  13478. }
  13479. if (maxHits > m_maxHitsInCastRay)
  13480. maxHits = m_maxHitsInCastRay;
  13481. bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0);
  13482. bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0);
  13483. bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0);
  13484. bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0);
  13485. bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0);
  13486. bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0);
  13487. bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0);
  13488. // Calculate some basic parameters
  13489. Vector3 vecRay = pos2Ray - pos1Ray;
  13490. float rayLength = vecRay.Length();
  13491. // Try to get a mesher and return failure if none, degenerate ray, or max 0 hits
  13492. IRendering primMesher = null;
  13493. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  13494. if (renderers.Count < 1 || rayLength < tol || m_maxHitsInCastRay < 1)
  13495. {
  13496. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN));
  13497. return result;
  13498. }
  13499. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  13500. // Iterate over all objects/groups and prims/parts in region
  13501. World.ForEachSOG(
  13502. delegate(SceneObjectGroup group)
  13503. {
  13504. if(group.IsDeleted || group.RootPart == null)
  13505. return;
  13506. // Check group filters unless part filters are configured
  13507. bool isPhysical = (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical);
  13508. bool isNonphysical = !isPhysical;
  13509. bool isPhantom = group.IsPhantom || group.IsVolumeDetect;
  13510. bool isAttachment = group.IsAttachment;
  13511. if (isPhysical && rejectPhysical)
  13512. return;
  13513. if (isNonphysical && rejectNonphysical)
  13514. return;
  13515. if (isPhantom && notdetectPhantom)
  13516. return;
  13517. if (isAttachment && !m_doAttachmentsInCastRay)
  13518. return;
  13519. // Parse object/group if passed filters
  13520. // Iterate over all prims/parts in object/group
  13521. foreach(SceneObjectPart part in group.Parts)
  13522. {
  13523. // ignore PhysicsShapeType.None as physics engines do
  13524. // or we will get into trouble in future
  13525. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  13526. continue;
  13527. isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical);
  13528. isNonphysical = !isPhysical;
  13529. isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) ||
  13530. (part.VolumeDetectActive);
  13531. if (isPhysical && rejectPhysical)
  13532. continue;
  13533. if (isNonphysical && rejectNonphysical)
  13534. continue;
  13535. if (isPhantom && notdetectPhantom)
  13536. continue;
  13537. // Parse prim/part and project ray if passed filters
  13538. Vector3 scalePart = part.Scale;
  13539. Vector3 posPart = part.GetWorldPosition();
  13540. Quaternion rotPart = part.GetWorldRotation();
  13541. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  13542. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  13543. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  13544. // Filter parts by shape bounding boxes
  13545. Vector3 shapeBoxMax = new Vector3(0.5f, 0.5f, 0.5f);
  13546. if (!part.Shape.SculptEntry)
  13547. shapeBoxMax = shapeBoxMax * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ));
  13548. shapeBoxMax = shapeBoxMax + (new Vector3(tol, tol, tol));
  13549. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  13550. {
  13551. // Prepare data needed to check for ray hits
  13552. RayTrans rayTrans = new RayTrans();
  13553. rayTrans.PartId = part.UUID;
  13554. rayTrans.GroupId = part.ParentGroup.UUID;
  13555. rayTrans.Link = group.PrimCount > 1 ? part.LinkNum : 0;
  13556. rayTrans.ScalePart = scalePart;
  13557. rayTrans.PositionPart = posPart;
  13558. rayTrans.RotationPart = rotPart;
  13559. rayTrans.ShapeNeedsEnds = true;
  13560. rayTrans.Position1Ray = pos1Ray;
  13561. rayTrans.Position1RayProj = pos1RayProj;
  13562. rayTrans.VectorRayProj = pos2RayProj - pos1RayProj;
  13563. // Get detail level depending on type
  13564. int lod = 0;
  13565. // Mesh detail level
  13566. if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13567. lod = (int)m_meshLodInCastRay;
  13568. // Sculpt detail level
  13569. else if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13570. lod = (int)m_sculptLodInCastRay;
  13571. // Shape detail level
  13572. else if (!part.Shape.SculptEntry)
  13573. lod = (int)m_primLodInCastRay;
  13574. // Try to get cached mesh if configured
  13575. ulong meshKey = 0;
  13576. FacetedMesh mesh = null;
  13577. if (m_useMeshCacheInCastRay)
  13578. {
  13579. meshKey = part.Shape.GetMeshKey(Vector3.One, (float)(4 << lod));
  13580. lock (m_cachedMeshes)
  13581. {
  13582. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  13583. }
  13584. }
  13585. // Create mesh if no cached mesh
  13586. if (mesh == null)
  13587. {
  13588. // Make an OMV prim to be able to mesh part
  13589. Primitive omvPrim = part.Shape.ToOmvPrimitive(posPart, rotPart);
  13590. byte[] sculptAsset = null;
  13591. if (omvPrim.Sculpt != null)
  13592. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  13593. // When part is mesh, get mesh
  13594. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  13595. {
  13596. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  13597. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, m_meshLodInCastRay, out mesh);
  13598. meshAsset = null;
  13599. }
  13600. // When part is sculpt, create mesh
  13601. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  13602. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  13603. {
  13604. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  13605. if (imgDecoder != null)
  13606. {
  13607. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  13608. if (sculpt != null)
  13609. {
  13610. mesh = primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, m_sculptLodInCastRay);
  13611. sculpt.Dispose();
  13612. }
  13613. }
  13614. }
  13615. // When part is shape, create mesh
  13616. else if (omvPrim.Sculpt == null)
  13617. {
  13618. if (
  13619. omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 &&
  13620. omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 &&
  13621. omvPrim.PrimData.PathSkew == 0.0 &&
  13622. omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0
  13623. )
  13624. rayTrans.ShapeNeedsEnds = false;
  13625. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_primLodInCastRay);
  13626. }
  13627. // Cache mesh if configured
  13628. if (m_useMeshCacheInCastRay && mesh != null)
  13629. {
  13630. lock(m_cachedMeshes)
  13631. {
  13632. if (!m_cachedMeshes.ContainsKey(meshKey))
  13633. m_cachedMeshes.Add(meshKey, mesh);
  13634. }
  13635. }
  13636. }
  13637. // Check mesh for ray hits
  13638. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  13639. mesh = null;
  13640. }
  13641. }
  13642. }
  13643. );
  13644. // Check avatar filter
  13645. if (!rejectAgents)
  13646. {
  13647. // Iterate over all avatars in region
  13648. World.ForEachRootScenePresence(
  13649. delegate (ScenePresence sp)
  13650. {
  13651. // Get bounding box
  13652. Vector3 lower;
  13653. Vector3 upper;
  13654. BoundingBoxOfScenePresence(sp, out lower, out upper);
  13655. // Parse avatar
  13656. Vector3 scalePart = upper - lower;
  13657. Vector3 posPart = sp.AbsolutePosition;
  13658. Quaternion rotPart = sp.GetWorldRotation();
  13659. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  13660. posPart = posPart + (lower + upper) * 0.5f * rotPart;
  13661. // Project ray
  13662. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  13663. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  13664. // Filter avatars by shape bounding boxes
  13665. Vector3 shapeBoxMax = new Vector3(0.5f + tol, 0.5f + tol, 0.5f + tol);
  13666. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  13667. {
  13668. // Prepare data needed to check for ray hits
  13669. RayTrans rayTrans = new RayTrans();
  13670. rayTrans.PartId = sp.UUID;
  13671. rayTrans.GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID;
  13672. rayTrans.Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0;
  13673. rayTrans.ScalePart = scalePart;
  13674. rayTrans.PositionPart = posPart;
  13675. rayTrans.RotationPart = rotPart;
  13676. rayTrans.ShapeNeedsEnds = false;
  13677. rayTrans.Position1Ray = pos1Ray;
  13678. rayTrans.Position1RayProj = pos1RayProj;
  13679. rayTrans.VectorRayProj = pos2RayProj - pos1RayProj;
  13680. // Try to get cached mesh if configured
  13681. PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere();
  13682. int lod = (int)m_avatarLodInCastRay;
  13683. ulong meshKey = prim.GetMeshKey(Vector3.One, (float)(4 << lod));
  13684. FacetedMesh mesh = null;
  13685. if (m_useMeshCacheInCastRay)
  13686. {
  13687. lock (m_cachedMeshes)
  13688. {
  13689. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  13690. }
  13691. }
  13692. // Create mesh if no cached mesh
  13693. if (mesh == null)
  13694. {
  13695. // Make OMV prim and create mesh
  13696. prim.Scale = scalePart;
  13697. Primitive omvPrim = prim.ToOmvPrimitive(posPart, rotPart);
  13698. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_avatarLodInCastRay);
  13699. // Cache mesh if configured
  13700. if (m_useMeshCacheInCastRay && mesh != null)
  13701. {
  13702. lock(m_cachedMeshes)
  13703. {
  13704. if (!m_cachedMeshes.ContainsKey(meshKey))
  13705. m_cachedMeshes.Add(meshKey, mesh);
  13706. }
  13707. }
  13708. }
  13709. // Check mesh for ray hits
  13710. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  13711. mesh = null;
  13712. }
  13713. }
  13714. );
  13715. }
  13716. // Check terrain filter
  13717. if (!rejectLand)
  13718. {
  13719. // Parse terrain
  13720. // Mesh terrain and check bounding box
  13721. Vector3 lower;
  13722. Vector3 upper;
  13723. List<Tri> triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out lower, out upper);
  13724. lower.Z -= tol;
  13725. upper.Z += tol;
  13726. if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z))
  13727. {
  13728. // Prepare data needed to check for ray hits
  13729. RayTrans rayTrans = new RayTrans();
  13730. rayTrans.PartId = UUID.Zero;
  13731. rayTrans.GroupId = UUID.Zero;
  13732. rayTrans.Link = 0;
  13733. rayTrans.ScalePart = new Vector3 (1.0f, 1.0f, 1.0f);
  13734. rayTrans.PositionPart = Vector3.Zero;
  13735. rayTrans.RotationPart = Quaternion.Identity;
  13736. rayTrans.ShapeNeedsEnds = true;
  13737. rayTrans.Position1Ray = pos1Ray;
  13738. rayTrans.Position1RayProj = pos1Ray;
  13739. rayTrans.VectorRayProj = vecRay;
  13740. // Check mesh
  13741. AddRayInTris(triangles, rayTrans, ref rayHits);
  13742. triangles = null;
  13743. }
  13744. }
  13745. // Sort hits by ascending distance
  13746. rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance));
  13747. // Check excess hits per part and group
  13748. for (int t = 0; t < 2; t++)
  13749. {
  13750. int maxHitsPerType = 0;
  13751. UUID id = UUID.Zero;
  13752. if (t == 0)
  13753. maxHitsPerType = m_maxHitsPerPrimInCastRay;
  13754. else
  13755. maxHitsPerType = m_maxHitsPerObjectInCastRay;
  13756. // Handle excess hits only when needed
  13757. if (maxHitsPerType < m_maxHitsInCastRay)
  13758. {
  13759. // Find excess hits
  13760. Hashtable hits = new Hashtable();
  13761. for (int i = rayHits.Count - 1; i >= 0; i--)
  13762. {
  13763. if (t == 0)
  13764. id = rayHits[i].PartId;
  13765. else
  13766. id = rayHits[i].GroupId;
  13767. if (hits.ContainsKey(id))
  13768. hits[id] = (int)hits[id] + 1;
  13769. else
  13770. hits[id] = 1;
  13771. }
  13772. // Remove excess hits
  13773. for (int i = rayHits.Count - 1; i >= 0; i--)
  13774. {
  13775. if (t == 0)
  13776. id = rayHits[i].PartId;
  13777. else
  13778. id = rayHits[i].GroupId;
  13779. int hit = (int)hits[id];
  13780. if (hit > m_maxHitsPerPrimInCastRay)
  13781. {
  13782. rayHits.RemoveAt(i);
  13783. hit--;
  13784. hits[id] = hit;
  13785. }
  13786. }
  13787. }
  13788. }
  13789. // Parse hits into result list according to data flags
  13790. int hitCount = rayHits.Count;
  13791. if (hitCount > maxHits)
  13792. hitCount = maxHits;
  13793. for (int i = 0; i < hitCount; i++)
  13794. {
  13795. RayHit rayHit = rayHits[i];
  13796. if (getRootKey)
  13797. result.Add(new LSL_Key(rayHit.GroupId.ToString()));
  13798. else
  13799. result.Add(new LSL_Key(rayHit.PartId.ToString()));
  13800. result.Add(new LSL_Vector(rayHit.Position));
  13801. if (getLinkNum)
  13802. result.Add(new LSL_Integer(rayHit.Link));
  13803. if (getNormal)
  13804. result.Add(new LSL_Vector(rayHit.Normal));
  13805. }
  13806. result.Add(new LSL_Integer(hitCount));
  13807. // Add to throttle data
  13808. stopWatch.Stop();
  13809. lock (m_castRayCalls)
  13810. {
  13811. CastRayCall castRayCall = new CastRayCall();
  13812. castRayCall.RegionId = regionId;
  13813. castRayCall.UserId = userId;
  13814. castRayCall.CalledMs = calledMs;
  13815. castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds;
  13816. m_castRayCalls.Add(castRayCall);
  13817. }
  13818. // Return hits
  13819. return result;
  13820. }
  13821. /// <summary>
  13822. /// Struct for transmitting parameters required for finding llCastRay ray hits.
  13823. /// </summary>
  13824. public struct RayTrans
  13825. {
  13826. public UUID PartId;
  13827. public UUID GroupId;
  13828. public int Link;
  13829. public Vector3 ScalePart;
  13830. public Vector3 PositionPart;
  13831. public Quaternion RotationPart;
  13832. public bool ShapeNeedsEnds;
  13833. public Vector3 Position1Ray;
  13834. public Vector3 Position1RayProj;
  13835. public Vector3 VectorRayProj;
  13836. }
  13837. /// <summary>
  13838. /// Struct for llCastRay ray hits.
  13839. /// </summary>
  13840. public struct RayHit
  13841. {
  13842. public UUID PartId;
  13843. public UUID GroupId;
  13844. public int Link;
  13845. public Vector3 Position;
  13846. public Vector3 Normal;
  13847. public float Distance;
  13848. }
  13849. /// <summary>
  13850. /// Struct for llCastRay throttle data.
  13851. /// </summary>
  13852. public struct CastRayCall
  13853. {
  13854. public UUID RegionId;
  13855. public UUID UserId;
  13856. public int CalledMs;
  13857. public int UsedMs;
  13858. }
  13859. /// <summary>
  13860. /// Helper to check if a ray intersects a shape bounding box.
  13861. /// </summary>
  13862. private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax)
  13863. {
  13864. // Skip if ray can't intersect bounding box;
  13865. Vector3 rayBoxProjMin = Vector3.Min(pos1RayProj, pos2RayProj);
  13866. Vector3 rayBoxProjMax = Vector3.Max(pos1RayProj, pos2RayProj);
  13867. if (
  13868. rayBoxProjMin.X > shapeBoxMax.X || rayBoxProjMin.Y > shapeBoxMax.Y || rayBoxProjMin.Z > shapeBoxMax.Z ||
  13869. rayBoxProjMax.X < -shapeBoxMax.X || rayBoxProjMax.Y < -shapeBoxMax.Y || rayBoxProjMax.Z < -shapeBoxMax.Z
  13870. )
  13871. return false;
  13872. // Check if ray intersect any bounding box side
  13873. int sign = 0;
  13874. float dist = 0.0f;
  13875. Vector3 posProj = Vector3.Zero;
  13876. Vector3 vecRayProj = pos2RayProj - pos1RayProj;
  13877. // Check both X sides unless ray is parallell to them
  13878. if (Math.Abs(vecRayProj.X) > m_floatToleranceInCastRay)
  13879. {
  13880. for (sign = -1; sign <= 1; sign += 2)
  13881. {
  13882. dist = ((float)sign * shapeBoxMax.X - pos1RayProj.X) / vecRayProj.X;
  13883. posProj = pos1RayProj + vecRayProj * dist;
  13884. if (Math.Abs(posProj.Y) <= shapeBoxMax.Y && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  13885. return true;
  13886. }
  13887. }
  13888. // Check both Y sides unless ray is parallell to them
  13889. if (Math.Abs(vecRayProj.Y) > m_floatToleranceInCastRay)
  13890. {
  13891. for (sign = -1; sign <= 1; sign += 2)
  13892. {
  13893. dist = ((float)sign * shapeBoxMax.Y - pos1RayProj.Y) / vecRayProj.Y;
  13894. posProj = pos1RayProj + vecRayProj * dist;
  13895. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  13896. return true;
  13897. }
  13898. }
  13899. // Check both Z sides unless ray is parallell to them
  13900. if (Math.Abs(vecRayProj.Z) > m_floatToleranceInCastRay)
  13901. {
  13902. for (sign = -1; sign <= 1; sign += 2)
  13903. {
  13904. dist = ((float)sign * shapeBoxMax.Z - pos1RayProj.Z) / vecRayProj.Z;
  13905. posProj = pos1RayProj + vecRayProj * dist;
  13906. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Y) <= shapeBoxMax.Y)
  13907. return true;
  13908. }
  13909. }
  13910. // No hits on bounding box so return false
  13911. return false;
  13912. }
  13913. /// <summary>
  13914. /// Helper to parse FacetedMesh for ray hits.
  13915. /// </summary>
  13916. private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  13917. {
  13918. if (mesh != null)
  13919. {
  13920. foreach (Face face in mesh.Faces)
  13921. {
  13922. for (int i = 0; i < face.Indices.Count; i += 3)
  13923. {
  13924. Tri triangle = new Tri();
  13925. triangle.p1 = face.Vertices[face.Indices[i]].Position;
  13926. triangle.p2 = face.Vertices[face.Indices[i + 1]].Position;
  13927. triangle.p3 = face.Vertices[face.Indices[i + 2]].Position;
  13928. AddRayInTri(triangle, rayTrans, ref rayHits);
  13929. }
  13930. }
  13931. }
  13932. }
  13933. /// <summary>
  13934. /// Helper to parse Tri (triangle) List for ray hits.
  13935. /// </summary>
  13936. private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits)
  13937. {
  13938. foreach (Tri triangle in triangles)
  13939. {
  13940. AddRayInTri(triangle, rayTrans, ref rayHits);
  13941. }
  13942. }
  13943. /// <summary>
  13944. /// Helper to add ray hit in a Tri (triangle).
  13945. /// </summary>
  13946. private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits)
  13947. {
  13948. // Check for hit in triangle
  13949. Vector3 posHitProj;
  13950. Vector3 normalProj;
  13951. if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out posHitProj, out normalProj))
  13952. {
  13953. // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center
  13954. if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds)
  13955. return;
  13956. // Transform hit and normal to region coordinate system
  13957. Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart;
  13958. Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart);
  13959. // Remove duplicate hits at triangle intersections
  13960. float distance = Vector3.Distance(rayTrans.Position1Ray, posHit);
  13961. for (int i = rayHits.Count - 1; i >= 0; i--)
  13962. {
  13963. if (rayHits[i].PartId != rayTrans.PartId)
  13964. break;
  13965. if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay)
  13966. return;
  13967. }
  13968. // Build result data set
  13969. RayHit rayHit = new RayHit();
  13970. rayHit.PartId = rayTrans.PartId;
  13971. rayHit.GroupId = rayTrans.GroupId;
  13972. rayHit.Link = rayTrans.Link;
  13973. rayHit.Position = posHit;
  13974. rayHit.Normal = normal;
  13975. rayHit.Distance = distance;
  13976. rayHits.Add(rayHit);
  13977. }
  13978. }
  13979. /// <summary>
  13980. /// Helper to find ray hit in triangle
  13981. /// </summary>
  13982. bool HitRayInTri(Tri triProj, Vector3 pos1RayProj, Vector3 vecRayProj, out Vector3 posHitProj, out Vector3 normalProj)
  13983. {
  13984. float tol = m_floatToleranceInCastRay;
  13985. posHitProj = Vector3.Zero;
  13986. // Calculate triangle edge vectors
  13987. Vector3 vec1Proj = triProj.p2 - triProj.p1;
  13988. Vector3 vec2Proj = triProj.p3 - triProj.p2;
  13989. Vector3 vec3Proj = triProj.p1 - triProj.p3;
  13990. // Calculate triangle normal
  13991. normalProj = Vector3.Cross(vec1Proj, vec2Proj);
  13992. // Skip if degenerate triangle or ray parallell with triangle plane
  13993. float divisor = Vector3.Dot(vecRayProj, normalProj);
  13994. if (Math.Abs(divisor) < tol)
  13995. return false;
  13996. // Skip if exit and not configured to detect
  13997. if (divisor > tol && !m_detectExitsInCastRay)
  13998. return false;
  13999. // Skip if outside ray ends
  14000. float distanceProj = Vector3.Dot(triProj.p1 - pos1RayProj, normalProj) / divisor;
  14001. if (distanceProj < -tol || distanceProj > 1 + tol)
  14002. return false;
  14003. // Calculate hit position in triangle
  14004. posHitProj = pos1RayProj + vecRayProj * distanceProj;
  14005. // Skip if outside triangle bounding box
  14006. Vector3 triProjMin = Vector3.Min(Vector3.Min(triProj.p1, triProj.p2), triProj.p3);
  14007. Vector3 triProjMax = Vector3.Max(Vector3.Max(triProj.p1, triProj.p2), triProj.p3);
  14008. if (
  14009. posHitProj.X < triProjMin.X - tol || posHitProj.Y < triProjMin.Y - tol || posHitProj.Z < triProjMin.Z - tol ||
  14010. posHitProj.X > triProjMax.X + tol || posHitProj.Y > triProjMax.Y + tol || posHitProj.Z > triProjMax.Z + tol
  14011. )
  14012. return false;
  14013. // Skip if outside triangle
  14014. if (
  14015. Vector3.Dot(Vector3.Cross(vec1Proj, normalProj), posHitProj - triProj.p1) > tol ||
  14016. Vector3.Dot(Vector3.Cross(vec2Proj, normalProj), posHitProj - triProj.p2) > tol ||
  14017. Vector3.Dot(Vector3.Cross(vec3Proj, normalProj), posHitProj - triProj.p3) > tol
  14018. )
  14019. return false;
  14020. // Return hit
  14021. return true;
  14022. }
  14023. /// <summary>
  14024. /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box.
  14025. /// </summary>
  14026. private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper)
  14027. {
  14028. // Get bounding X-Y rectangle of terrain under ray
  14029. lower = Vector3.Min(posStart, posEnd);
  14030. upper = Vector3.Max(posStart, posEnd);
  14031. lower.X = (float)Math.Floor(lower.X);
  14032. lower.Y = (float)Math.Floor(lower.Y);
  14033. float zLower = float.MaxValue;
  14034. upper.X = (float)Math.Ceiling(upper.X);
  14035. upper.Y = (float)Math.Ceiling(upper.Y);
  14036. float zUpper = float.MinValue;
  14037. // Initialize Tri (triangle) List
  14038. List<Tri> triangles = new List<Tri>();
  14039. // Set parsing lane direction to major ray X-Y axis
  14040. Vector3 vec = posEnd - posStart;
  14041. float xAbs = Math.Abs(vec.X);
  14042. float yAbs = Math.Abs(vec.Y);
  14043. bool bigX = true;
  14044. if (yAbs > xAbs)
  14045. {
  14046. bigX = false;
  14047. vec = vec / yAbs;
  14048. }
  14049. else if (xAbs > yAbs || xAbs > 0.0f)
  14050. vec = vec / xAbs;
  14051. else
  14052. vec = new Vector3(1.0f, 1.0f, 0.0f);
  14053. // Simplify by start parsing in lower end of lane
  14054. if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f))
  14055. {
  14056. Vector3 posTemp = posStart;
  14057. posStart = posEnd;
  14058. posEnd = posTemp;
  14059. vec = vec * -1.0f;
  14060. }
  14061. // First 1x1 rectangle under ray
  14062. float xFloorOld = 0.0f;
  14063. float yFloorOld = 0.0f;
  14064. Vector3 pos = posStart;
  14065. float xFloor = (float)Math.Floor(pos.X);
  14066. float yFloor = (float)Math.Floor(pos.Y);
  14067. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14068. // Parse every remaining 1x1 rectangle under ray
  14069. while (pos != posEnd)
  14070. {
  14071. // Next 1x1 rectangle under ray
  14072. xFloorOld = xFloor;
  14073. yFloorOld = yFloor;
  14074. pos = pos + vec;
  14075. // Clip position to 1x1 rectangle border
  14076. xFloor = (float)Math.Floor(pos.X);
  14077. yFloor = (float)Math.Floor(pos.Y);
  14078. if (bigX && pos.X > xFloor)
  14079. {
  14080. pos.Y -= vec.Y * (pos.X - xFloor);
  14081. pos.X = xFloor;
  14082. }
  14083. else if (!bigX && pos.Y > yFloor)
  14084. {
  14085. pos.X -= vec.X * (pos.Y - yFloor);
  14086. pos.Y = yFloor;
  14087. }
  14088. // Last 1x1 rectangle under ray
  14089. if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y))
  14090. {
  14091. pos = posEnd;
  14092. xFloor = (float)Math.Floor(pos.X);
  14093. yFloor = (float)Math.Floor(pos.Y);
  14094. }
  14095. // Add new 1x1 rectangle in lane
  14096. if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld))
  14097. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14098. // Add last 1x1 rectangle in old lane at lane shift
  14099. if (bigX && yFloor != yFloorOld)
  14100. AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper);
  14101. if (!bigX && xFloor != xFloorOld)
  14102. AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper);
  14103. }
  14104. // Finalize bounding box Z
  14105. lower.Z = zLower;
  14106. upper.Z = zUpper;
  14107. // Done and returning Tri (triangle)List
  14108. return triangles;
  14109. }
  14110. /// <summary>
  14111. /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box.
  14112. /// </summary>
  14113. private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper)
  14114. {
  14115. int xInt = (int)xPos;
  14116. int yInt = (int)yPos;
  14117. // Corner 1 of 1x1 rectangle
  14118. int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14119. int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14120. Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14121. // Adjust bounding box
  14122. zLower = Math.Min(zLower, pos1.Z);
  14123. zUpper = Math.Max(zUpper, pos1.Z);
  14124. // Corner 2 of 1x1 rectangle
  14125. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14126. y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14127. Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14128. // Adjust bounding box
  14129. zLower = Math.Min(zLower, pos2.Z);
  14130. zUpper = Math.Max(zUpper, pos2.Z);
  14131. // Corner 3 of 1x1 rectangle
  14132. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14133. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14134. Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14135. // Adjust bounding box
  14136. zLower = Math.Min(zLower, pos3.Z);
  14137. zUpper = Math.Max(zUpper, pos3.Z);
  14138. // Corner 4 of 1x1 rectangle
  14139. x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14140. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14141. Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14142. // Adjust bounding box
  14143. zLower = Math.Min(zLower, pos4.Z);
  14144. zUpper = Math.Max(zUpper, pos4.Z);
  14145. // Add triangle 1
  14146. Tri triangle1 = new Tri();
  14147. triangle1.p1 = pos1;
  14148. triangle1.p2 = pos2;
  14149. triangle1.p3 = pos3;
  14150. triangles.Add(triangle1);
  14151. // Add triangle 2
  14152. Tri triangle2 = new Tri();
  14153. triangle2.p1 = pos3;
  14154. triangle2.p2 = pos4;
  14155. triangle2.p3 = pos1;
  14156. triangles.Add(triangle2);
  14157. }
  14158. /// <summary>
  14159. /// Helper to get link number for a UUID.
  14160. /// </summary>
  14161. private int UUID2LinkNumber(SceneObjectPart part, UUID id)
  14162. {
  14163. SceneObjectGroup group = part.ParentGroup;
  14164. if (group != null)
  14165. {
  14166. // Parse every link for UUID
  14167. int linkCount = group.PrimCount + group.GetSittingAvatarsCount();
  14168. for (int link = linkCount; link > 0; link--)
  14169. {
  14170. ISceneEntity entity = GetLinkEntity(part, link);
  14171. // Return link number if UUID match
  14172. if (entity != null && entity.UUID == id)
  14173. return link;
  14174. }
  14175. }
  14176. // Return link number 0 if no links or UUID matches
  14177. return 0;
  14178. }
  14179. public LSL_Integer llManageEstateAccess(int action, string avatar)
  14180. {
  14181. m_host.AddScriptLPS(1);
  14182. EstateSettings estate = World.RegionInfo.EstateSettings;
  14183. bool isAccount = false;
  14184. bool isGroup = false;
  14185. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  14186. return 0;
  14187. UUID id = new UUID();
  14188. if (!UUID.TryParse(avatar, out id))
  14189. return 0;
  14190. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, id);
  14191. isAccount = account != null ? true : false;
  14192. if (!isAccount)
  14193. {
  14194. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  14195. if (groups != null)
  14196. {
  14197. GroupRecord group = groups.GetGroupRecord(id);
  14198. isGroup = group != null ? true : false;
  14199. if (!isGroup)
  14200. return 0;
  14201. }
  14202. else
  14203. return 0;
  14204. }
  14205. switch (action)
  14206. {
  14207. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  14208. if (!isAccount) return 0;
  14209. if (estate.HasAccess(id)) return 1;
  14210. if (estate.IsBanned(id, World.GetUserFlags(id)))
  14211. estate.RemoveBan(id);
  14212. estate.AddEstateUser(id);
  14213. break;
  14214. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  14215. if (!isAccount || !estate.HasAccess(id)) return 0;
  14216. estate.RemoveEstateUser(id);
  14217. break;
  14218. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  14219. if (!isGroup) return 0;
  14220. if (estate.GroupAccess(id)) return 1;
  14221. estate.AddEstateGroup(id);
  14222. break;
  14223. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  14224. if (!isGroup || !estate.GroupAccess(id)) return 0;
  14225. estate.RemoveEstateGroup(id);
  14226. break;
  14227. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  14228. if (!isAccount) return 0;
  14229. if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
  14230. EstateBan ban = new EstateBan();
  14231. ban.EstateID = estate.EstateID;
  14232. ban.BannedUserID = id;
  14233. estate.AddBan(ban);
  14234. break;
  14235. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  14236. if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
  14237. estate.RemoveBan(id);
  14238. break;
  14239. default: return 0;
  14240. }
  14241. return 1;
  14242. }
  14243. public LSL_Integer llGetMemoryLimit()
  14244. {
  14245. m_host.AddScriptLPS(1);
  14246. // The value returned for Mono scripts in SL
  14247. return 65536;
  14248. }
  14249. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  14250. {
  14251. m_host.AddScriptLPS(1);
  14252. // Treat as an LSO script
  14253. return ScriptBaseClass.FALSE;
  14254. }
  14255. public LSL_Integer llGetSPMaxMemory()
  14256. {
  14257. m_host.AddScriptLPS(1);
  14258. // The value returned for Mono scripts in SL
  14259. return 65536;
  14260. }
  14261. public virtual LSL_Integer llGetUsedMemory()
  14262. {
  14263. m_host.AddScriptLPS(1);
  14264. // The value returned for Mono scripts in SL
  14265. return 65536;
  14266. }
  14267. public void llScriptProfiler(LSL_Integer flags)
  14268. {
  14269. m_host.AddScriptLPS(1);
  14270. // This does nothing for LSO scripts in SL
  14271. }
  14272. #region Not Implemented
  14273. //
  14274. // Listing the unimplemented lsl functions here, please move
  14275. // them from this region as they are completed
  14276. //
  14277. public void llSetSoundQueueing(int queue)
  14278. {
  14279. m_host.AddScriptLPS(1);
  14280. if (m_SoundModule != null)
  14281. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  14282. }
  14283. public void llCollisionSprite(string impact_sprite)
  14284. {
  14285. m_host.AddScriptLPS(1);
  14286. // Viewer 2.0 broke this and it's likely LL has no intention
  14287. // of fixing it. Therefore, letting this be a NOP seems appropriate.
  14288. }
  14289. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  14290. {
  14291. m_host.AddScriptLPS(1);
  14292. if (!World.Permissions.IsGod(m_host.OwnerID))
  14293. NotImplemented("llGodLikeRezObject");
  14294. AssetBase rezAsset = World.AssetService.Get(inventory);
  14295. if (rezAsset == null)
  14296. {
  14297. llSay(0, "Asset not found");
  14298. return;
  14299. }
  14300. SceneObjectGroup group = null;
  14301. try
  14302. {
  14303. string xmlData = Utils.BytesToString(rezAsset.Data);
  14304. group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
  14305. }
  14306. catch
  14307. {
  14308. llSay(0, "Asset not found");
  14309. return;
  14310. }
  14311. if (group == null)
  14312. {
  14313. llSay(0, "Asset not found");
  14314. return;
  14315. }
  14316. group.RootPart.AttachedPos = group.AbsolutePosition;
  14317. group.ResetIDs();
  14318. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  14319. World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
  14320. group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
  14321. group.ScheduleGroupForFullUpdate();
  14322. // objects rezzed with this method are die_at_edge by default.
  14323. group.RootPart.SetDieAtEdge(true);
  14324. group.ResumeScripts();
  14325. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  14326. "object_rez", new Object[] {
  14327. new LSL_String(
  14328. group.RootPart.UUID.ToString()) },
  14329. new DetectParams[0]));
  14330. }
  14331. public LSL_Key llTransferLindenDollars(string destination, int amount)
  14332. {
  14333. UUID txn = UUID.Random();
  14334. Util.FireAndForget(delegate(object x)
  14335. {
  14336. int replycode = 0;
  14337. string replydata = destination + "," + amount.ToString();
  14338. try
  14339. {
  14340. if (amount <= 0)
  14341. {
  14342. replydata = "INVALID_AMOUNT";
  14343. return;
  14344. }
  14345. TaskInventoryItem item = m_item;
  14346. if (item == null)
  14347. {
  14348. replydata = "SERVICE_ERROR";
  14349. return;
  14350. }
  14351. if (m_host.OwnerID == m_host.GroupID)
  14352. {
  14353. replydata = "GROUP_OWNED";
  14354. return;
  14355. }
  14356. m_host.AddScriptLPS(1);
  14357. if (item.PermsGranter == UUID.Zero)
  14358. {
  14359. replydata = "MISSING_PERMISSION_DEBIT";
  14360. return;
  14361. }
  14362. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  14363. {
  14364. replydata = "MISSING_PERMISSION_DEBIT";
  14365. return;
  14366. }
  14367. UUID toID = new UUID();
  14368. if (!UUID.TryParse(destination, out toID))
  14369. {
  14370. replydata = "INVALID_AGENT";
  14371. return;
  14372. }
  14373. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, toID);
  14374. if (account == null)
  14375. {
  14376. replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST";
  14377. return;
  14378. }
  14379. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  14380. if (money == null)
  14381. {
  14382. replydata = "TRANSFERS_DISABLED";
  14383. return;
  14384. }
  14385. string reason;
  14386. bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, txn, out reason);
  14387. if (result)
  14388. {
  14389. replycode = 1;
  14390. return;
  14391. }
  14392. replydata = reason;
  14393. }
  14394. finally
  14395. {
  14396. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14397. "transaction_result", new Object[] {
  14398. new LSL_String(txn.ToString()),
  14399. new LSL_Integer(replycode),
  14400. new LSL_String(replydata) },
  14401. new DetectParams[0]));
  14402. }
  14403. }, null, "LSL_Api.llTransferLindenDollars");
  14404. return txn.ToString();
  14405. }
  14406. #endregion
  14407. protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
  14408. {
  14409. //This is a special version of SetPrimParams to deal with avatars which are sitting on the linkset.
  14410. int idx = 0;
  14411. int idxStart = 0;
  14412. bool positionChanged = false;
  14413. try
  14414. {
  14415. while (idx < rules.Length)
  14416. {
  14417. ++rulesParsed;
  14418. int code = rules.GetLSLIntegerItem(idx++);
  14419. int remain = rules.Length - idx;
  14420. idxStart = idx;
  14421. switch (code)
  14422. {
  14423. case (int)ScriptBaseClass.PRIM_POSITION:
  14424. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14425. {
  14426. if (remain < 1)
  14427. return new LSL_List();
  14428. LSL_Vector v;
  14429. v = rules.GetVector3Item(idx++);
  14430. if(!av.LegacySitOffsets)
  14431. {
  14432. LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
  14433. v = v + 2 * sitOffset;
  14434. }
  14435. av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
  14436. positionChanged = true;
  14437. }
  14438. break;
  14439. case (int)ScriptBaseClass.PRIM_ROTATION:
  14440. {
  14441. if (remain < 1)
  14442. return new LSL_List();
  14443. Quaternion r;
  14444. r = rules.GetQuaternionItem(idx++);
  14445. av.Rotation = m_host.GetWorldRotation() * r;
  14446. positionChanged = true;
  14447. }
  14448. break;
  14449. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14450. {
  14451. if (remain < 1)
  14452. return new LSL_List();
  14453. LSL_Rotation r;
  14454. r = rules.GetQuaternionItem(idx++);
  14455. av.Rotation = r;
  14456. positionChanged = true;
  14457. }
  14458. break;
  14459. // parse rest doing nothing but number of parameters error check
  14460. case (int)ScriptBaseClass.PRIM_SIZE:
  14461. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14462. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14463. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14464. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  14465. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14466. case (int)ScriptBaseClass.PRIM_NAME:
  14467. case (int)ScriptBaseClass.PRIM_DESC:
  14468. if (remain < 1)
  14469. return new LSL_List();
  14470. idx++;
  14471. break;
  14472. case (int)ScriptBaseClass.PRIM_GLOW:
  14473. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14474. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14475. if (remain < 2)
  14476. return new LSL_List();
  14477. idx += 2;
  14478. break;
  14479. case (int)ScriptBaseClass.PRIM_TYPE:
  14480. if (remain < 3)
  14481. return new LSL_List();
  14482. code = (int)rules.GetLSLIntegerItem(idx++);
  14483. remain = rules.Length - idx;
  14484. switch (code)
  14485. {
  14486. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  14487. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  14488. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  14489. if (remain < 6)
  14490. return new LSL_List();
  14491. idx += 6;
  14492. break;
  14493. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  14494. if (remain < 5)
  14495. return new LSL_List();
  14496. idx += 5;
  14497. break;
  14498. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  14499. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  14500. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  14501. if (remain < 11)
  14502. return new LSL_List();
  14503. idx += 11;
  14504. break;
  14505. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  14506. if (remain < 2)
  14507. return new LSL_List();
  14508. idx += 2;
  14509. break;
  14510. }
  14511. break;
  14512. case (int)ScriptBaseClass.PRIM_COLOR:
  14513. case (int)ScriptBaseClass.PRIM_TEXT:
  14514. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  14515. case (int)ScriptBaseClass.PRIM_OMEGA:
  14516. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  14517. if (remain < 3)
  14518. return new LSL_List();
  14519. idx += 3;
  14520. break;
  14521. case (int)ScriptBaseClass.PRIM_TEXTURE:
  14522. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  14523. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  14524. if (remain < 5)
  14525. return new LSL_List();
  14526. idx += 5;
  14527. break;
  14528. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  14529. if (remain < 7)
  14530. return new LSL_List();
  14531. idx += 7;
  14532. break;
  14533. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  14534. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  14535. return new LSL_List();
  14536. return rules.GetSublist(idx, -1);
  14537. }
  14538. }
  14539. }
  14540. catch (InvalidCastException e)
  14541. {
  14542. Error(originFunc,string.Format(
  14543. " error running rule #{0}: arg #{1} {2}",
  14544. rulesParsed, idx - idxStart, e.Message));
  14545. }
  14546. finally
  14547. {
  14548. if (positionChanged)
  14549. av.SendTerseUpdateToAllClients();
  14550. }
  14551. return new LSL_List();
  14552. }
  14553. public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
  14554. {
  14555. // avatars case
  14556. // replies as SL wiki
  14557. // SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
  14558. SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
  14559. int idx = 0;
  14560. while (idx < rules.Length)
  14561. {
  14562. int code = (int)rules.GetLSLIntegerItem(idx++);
  14563. int remain = rules.Length - idx;
  14564. switch (code)
  14565. {
  14566. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14567. res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
  14568. break;
  14569. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14570. res.Add(new LSL_Integer(0));
  14571. break;
  14572. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14573. res.Add(new LSL_Integer(0));
  14574. break;
  14575. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14576. res.Add(new LSL_Integer(0));
  14577. break;
  14578. case (int)ScriptBaseClass.PRIM_POSITION:
  14579. Vector3 pos;
  14580. if (sitPart.ParentGroup.RootPart != null)
  14581. {
  14582. pos = avatar.OffsetPosition;
  14583. if(!avatar.LegacySitOffsets)
  14584. {
  14585. Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
  14586. pos -= sitOffset;
  14587. }
  14588. SceneObjectPart sitroot = sitPart.ParentGroup.RootPart;
  14589. pos = sitroot.AbsolutePosition + pos * sitroot.GetWorldRotation();
  14590. }
  14591. else
  14592. pos = avatar.AbsolutePosition;
  14593. res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
  14594. break;
  14595. case (int)ScriptBaseClass.PRIM_SIZE:
  14596. Vector3 s = avatar.Appearance.AvatarSize;
  14597. res.Add(new LSL_Vector(s.X, s.Y, s.Z));
  14598. break;
  14599. case (int)ScriptBaseClass.PRIM_ROTATION:
  14600. res.Add(new LSL_Rotation(avatar.GetWorldRotation()));
  14601. break;
  14602. case (int)ScriptBaseClass.PRIM_TYPE:
  14603. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  14604. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  14605. res.Add(new LSL_Vector(0f,1.0f,0f));
  14606. res.Add(new LSL_Float(0.0f));
  14607. res.Add(new LSL_Vector(0, 0, 0));
  14608. res.Add(new LSL_Vector(1.0f,1.0f,0f));
  14609. res.Add(new LSL_Vector(0, 0, 0));
  14610. break;
  14611. case (int)ScriptBaseClass.PRIM_TEXTURE:
  14612. if (remain < 1)
  14613. return new LSL_List();
  14614. int face = (int)rules.GetLSLIntegerItem(idx++);
  14615. if (face == ScriptBaseClass.ALL_SIDES)
  14616. {
  14617. for (face = 0; face < 21; face++)
  14618. {
  14619. res.Add(new LSL_String(""));
  14620. res.Add(new LSL_Vector(0,0,0));
  14621. res.Add(new LSL_Vector(0,0,0));
  14622. res.Add(new LSL_Float(0.0));
  14623. }
  14624. }
  14625. else
  14626. {
  14627. if (face >= 0 && face < 21)
  14628. {
  14629. res.Add(new LSL_String(""));
  14630. res.Add(new LSL_Vector(0,0,0));
  14631. res.Add(new LSL_Vector(0,0,0));
  14632. res.Add(new LSL_Float(0.0));
  14633. }
  14634. }
  14635. break;
  14636. case (int)ScriptBaseClass.PRIM_COLOR:
  14637. if (remain < 1)
  14638. return new LSL_List();
  14639. face = (int)rules.GetLSLIntegerItem(idx++);
  14640. if (face == ScriptBaseClass.ALL_SIDES)
  14641. {
  14642. for (face = 0; face < 21; face++)
  14643. {
  14644. res.Add(new LSL_Vector(0,0,0));
  14645. res.Add(new LSL_Float(0));
  14646. }
  14647. }
  14648. else
  14649. {
  14650. res.Add(new LSL_Vector(0,0,0));
  14651. res.Add(new LSL_Float(0));
  14652. }
  14653. break;
  14654. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  14655. if (remain < 1)
  14656. return new LSL_List();
  14657. face = (int)rules.GetLSLIntegerItem(idx++);
  14658. if (face == ScriptBaseClass.ALL_SIDES)
  14659. {
  14660. for (face = 0; face < 21; face++)
  14661. {
  14662. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  14663. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  14664. }
  14665. }
  14666. else
  14667. {
  14668. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  14669. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  14670. }
  14671. break;
  14672. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14673. if (remain < 1)
  14674. return new LSL_List();
  14675. face = (int)rules.GetLSLIntegerItem(idx++);
  14676. if (face == ScriptBaseClass.ALL_SIDES)
  14677. {
  14678. for (face = 0; face < 21; face++)
  14679. {
  14680. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  14681. }
  14682. }
  14683. else
  14684. {
  14685. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  14686. }
  14687. break;
  14688. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  14689. res.Add(new LSL_Integer(0));
  14690. res.Add(new LSL_Integer(0));// softness
  14691. res.Add(new LSL_Float(0.0f)); // gravity
  14692. res.Add(new LSL_Float(0.0f)); // friction
  14693. res.Add(new LSL_Float(0.0f)); // wind
  14694. res.Add(new LSL_Float(0.0f)); // tension
  14695. res.Add(new LSL_Vector(0f,0f,0f));
  14696. break;
  14697. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14698. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  14699. if (remain < 1)
  14700. return new LSL_List();
  14701. face = (int)rules.GetLSLIntegerItem(idx++);
  14702. if (face == ScriptBaseClass.ALL_SIDES)
  14703. {
  14704. for (face = 0; face < 21; face++)
  14705. {
  14706. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  14707. }
  14708. }
  14709. else
  14710. {
  14711. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  14712. }
  14713. break;
  14714. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  14715. res.Add(new LSL_Integer(0));
  14716. res.Add(new LSL_Vector(0f,0f,0f));
  14717. res.Add(new LSL_Float(0f)); // intensity
  14718. res.Add(new LSL_Float(0f)); // radius
  14719. res.Add(new LSL_Float(0f)); // falloff
  14720. break;
  14721. case (int)ScriptBaseClass.PRIM_GLOW:
  14722. if (remain < 1)
  14723. return new LSL_List();
  14724. face = (int)rules.GetLSLIntegerItem(idx++);
  14725. if (face == ScriptBaseClass.ALL_SIDES)
  14726. {
  14727. for (face = 0; face < 21; face++)
  14728. {
  14729. res.Add(new LSL_Float(0f));
  14730. }
  14731. }
  14732. else
  14733. {
  14734. res.Add(new LSL_Float(0f));
  14735. }
  14736. break;
  14737. case (int)ScriptBaseClass.PRIM_TEXT:
  14738. res.Add(new LSL_String(""));
  14739. res.Add(new LSL_Vector(0f,0f,0f));
  14740. res.Add(new LSL_Float(1.0f));
  14741. break;
  14742. case (int)ScriptBaseClass.PRIM_NAME:
  14743. res.Add(new LSL_String(avatar.Name));
  14744. break;
  14745. case (int)ScriptBaseClass.PRIM_DESC:
  14746. res.Add(new LSL_String(""));
  14747. break;
  14748. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14749. Quaternion lrot = avatar.Rotation;
  14750. res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
  14751. break;
  14752. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14753. Vector3 lpos = avatar.OffsetPosition;
  14754. if(!avatar.LegacySitOffsets)
  14755. {
  14756. Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
  14757. lpos -= lsitOffset;
  14758. }
  14759. res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
  14760. break;
  14761. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  14762. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  14763. return new LSL_List();
  14764. return rules.GetSublist(idx, -1);
  14765. }
  14766. }
  14767. return new LSL_List();
  14768. }
  14769. public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
  14770. {
  14771. string state = String.Empty;
  14772. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14773. {
  14774. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14775. {
  14776. state = kvp.Key;
  14777. break;
  14778. }
  14779. }
  14780. if (state == String.Empty)
  14781. {
  14782. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Invalid animation state " + animState);
  14783. return;
  14784. }
  14785. if (m_item.PermsGranter == UUID.Zero)
  14786. {
  14787. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14788. return;
  14789. }
  14790. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  14791. {
  14792. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14793. return;
  14794. }
  14795. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14796. if (presence == null)
  14797. return;
  14798. UUID animID;
  14799. animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  14800. if (animID == UUID.Zero)
  14801. {
  14802. String animupper = ((string)anim).ToUpperInvariant();
  14803. DefaultAvatarAnimations.AnimsUUID.TryGetValue(animupper, out animID);
  14804. }
  14805. if (animID == UUID.Zero)
  14806. {
  14807. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Animation not found");
  14808. return;
  14809. }
  14810. presence.SetAnimationOverride(state, animID);
  14811. }
  14812. public void llResetAnimationOverride(LSL_String animState)
  14813. {
  14814. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14815. if (presence == null)
  14816. return;
  14817. if (m_item.PermsGranter == UUID.Zero)
  14818. {
  14819. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14820. return;
  14821. }
  14822. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  14823. {
  14824. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14825. return;
  14826. }
  14827. if (animState == "ALL")
  14828. {
  14829. presence.SetAnimationOverride("ALL", UUID.Zero);
  14830. return;
  14831. }
  14832. string state = String.Empty;
  14833. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14834. {
  14835. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14836. {
  14837. state = kvp.Key;
  14838. break;
  14839. }
  14840. }
  14841. if (state == String.Empty)
  14842. {
  14843. return;
  14844. }
  14845. presence.SetAnimationOverride(state, UUID.Zero);
  14846. }
  14847. public LSL_String llGetAnimationOverride(LSL_String animState)
  14848. {
  14849. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14850. if (presence == null)
  14851. return String.Empty;
  14852. if (m_item.PermsGranter == UUID.Zero)
  14853. {
  14854. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14855. return String.Empty;
  14856. }
  14857. if ((m_item.PermsMask & (ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION)) == 0)
  14858. {
  14859. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14860. return String.Empty;
  14861. }
  14862. string state = String.Empty;
  14863. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14864. {
  14865. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14866. {
  14867. state = kvp.Key;
  14868. break;
  14869. }
  14870. }
  14871. if (state == String.Empty)
  14872. {
  14873. return String.Empty;
  14874. }
  14875. UUID animID = presence.GetAnimationOverride(state);
  14876. if (animID == UUID.Zero)
  14877. return animState;
  14878. foreach (KeyValuePair<string, UUID> kvp in DefaultAvatarAnimations.AnimsUUID)
  14879. {
  14880. if (kvp.Value == animID)
  14881. return kvp.Key.ToLower();
  14882. }
  14883. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  14884. {
  14885. if (item.AssetID == animID)
  14886. return item.Name;
  14887. }
  14888. return String.Empty;
  14889. }
  14890. public LSL_List llJson2List(LSL_String json)
  14891. {
  14892. if(String.IsNullOrEmpty(json))
  14893. return new LSL_List();
  14894. if(json == "[]")
  14895. return new LSL_List();
  14896. if(json == "{}")
  14897. return new LSL_List();
  14898. char first = ((string)json)[0];
  14899. if(first != '[' && first !='{')
  14900. {
  14901. // we already have a single element
  14902. LSL_List l = new LSL_List();
  14903. l.Add(json);
  14904. return l;
  14905. }
  14906. LitJson.JsonData jsdata;
  14907. try
  14908. {
  14909. jsdata = LitJson.JsonMapper.ToObject(json);
  14910. }
  14911. catch (Exception e)
  14912. {
  14913. string m = e.Message; // debug point
  14914. return json;
  14915. }
  14916. try
  14917. {
  14918. return JsonParseTop(jsdata);
  14919. }
  14920. catch (Exception e)
  14921. {
  14922. string m = e.Message; // debug point
  14923. return (LSL_String)ScriptBaseClass.JSON_INVALID;
  14924. }
  14925. }
  14926. private LSL_List JsonParseTop(LitJson.JsonData elem)
  14927. {
  14928. LSL_List retl = new LSL_List();
  14929. if(elem == null)
  14930. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  14931. LitJson.JsonType elemType = elem.GetJsonType();
  14932. switch (elemType)
  14933. {
  14934. case LitJson.JsonType.Int:
  14935. retl.Add(new LSL_Integer((int)elem));
  14936. return retl;
  14937. case LitJson.JsonType.Boolean:
  14938. retl.Add((LSL_String)((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE));
  14939. return retl;
  14940. case LitJson.JsonType.Double:
  14941. retl.Add(new LSL_Float((double)elem));
  14942. return retl;
  14943. case LitJson.JsonType.None:
  14944. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  14945. return retl;
  14946. case LitJson.JsonType.String:
  14947. retl.Add(new LSL_String((string)elem));
  14948. return retl;
  14949. case LitJson.JsonType.Array:
  14950. foreach (LitJson.JsonData subelem in elem)
  14951. retl.Add(JsonParseTopNodes(subelem));
  14952. return retl;
  14953. case LitJson.JsonType.Object:
  14954. IDictionaryEnumerator e = ((IOrderedDictionary)elem).GetEnumerator();
  14955. while (e.MoveNext())
  14956. {
  14957. retl.Add(new LSL_String((string)e.Key));
  14958. retl.Add(JsonParseTopNodes((LitJson.JsonData)e.Value));
  14959. }
  14960. return retl;
  14961. default:
  14962. throw new Exception(ScriptBaseClass.JSON_INVALID);
  14963. }
  14964. }
  14965. private object JsonParseTopNodes(LitJson.JsonData elem)
  14966. {
  14967. if(elem == null)
  14968. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  14969. LitJson.JsonType elemType = elem.GetJsonType();
  14970. switch (elemType)
  14971. {
  14972. case LitJson.JsonType.Int:
  14973. return (new LSL_Integer((int)elem));
  14974. case LitJson.JsonType.Boolean:
  14975. return ((bool)elem ? (LSL_String)ScriptBaseClass.JSON_TRUE : (LSL_String)ScriptBaseClass.JSON_FALSE);
  14976. case LitJson.JsonType.Double:
  14977. return (new LSL_Float((double)elem));
  14978. case LitJson.JsonType.None:
  14979. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  14980. case LitJson.JsonType.String:
  14981. return (new LSL_String((string)elem));
  14982. case LitJson.JsonType.Array:
  14983. case LitJson.JsonType.Object:
  14984. string s = LitJson.JsonMapper.ToJson(elem);
  14985. return (LSL_String)s;
  14986. default:
  14987. throw new Exception(ScriptBaseClass.JSON_INVALID);
  14988. }
  14989. }
  14990. public LSL_String llList2Json(LSL_String type, LSL_List values)
  14991. {
  14992. try
  14993. {
  14994. StringBuilder sb = new StringBuilder();
  14995. if (type == ScriptBaseClass.JSON_ARRAY)
  14996. {
  14997. sb.Append("[");
  14998. int i= 0;
  14999. foreach (object o in values.Data)
  15000. {
  15001. sb.Append(ListToJson(o));
  15002. if((i++) < values.Data.Length - 1)
  15003. sb.Append(",");
  15004. }
  15005. sb.Append("]");
  15006. return (LSL_String)sb.ToString();;
  15007. }
  15008. else if (type == ScriptBaseClass.JSON_OBJECT)
  15009. {
  15010. sb.Append("{");
  15011. for (int i = 0; i < values.Data.Length; i += 2)
  15012. {
  15013. if (!(values.Data[i] is LSL_String))
  15014. return ScriptBaseClass.JSON_INVALID;
  15015. string key = ((LSL_String)values.Data[i]).m_string;
  15016. key = EscapeForJSON(key, true);
  15017. sb.Append(key);
  15018. sb.Append(":");
  15019. sb.Append(ListToJson(values.Data[i+1]));
  15020. if(i < values.Data.Length - 2)
  15021. sb.Append(",");
  15022. }
  15023. sb.Append("}");
  15024. return (LSL_String)sb.ToString();
  15025. }
  15026. return ScriptBaseClass.JSON_INVALID;
  15027. }
  15028. catch
  15029. {
  15030. return ScriptBaseClass.JSON_INVALID;
  15031. }
  15032. }
  15033. private string ListToJson(object o)
  15034. {
  15035. if (o is LSL_Float || o is double)
  15036. {
  15037. double float_val;
  15038. if (o is double)
  15039. float_val = ((double)o);
  15040. else
  15041. float_val = ((LSL_Float)o).value;
  15042. if(double.IsInfinity(float_val))
  15043. return "\"Inf\"";
  15044. if(double.IsNaN(float_val))
  15045. return "\"NaN\"";
  15046. return ((LSL_Float)float_val).ToString();
  15047. }
  15048. if (o is LSL_Integer || o is int)
  15049. {
  15050. int i;
  15051. if (o is int)
  15052. i = ((int)o);
  15053. else
  15054. i = ((LSL_Integer)o).value;
  15055. return i.ToString();
  15056. }
  15057. if (o is LSL_Rotation)
  15058. {
  15059. StringBuilder sb = new StringBuilder(128);
  15060. sb.Append("\"");
  15061. LSL_Rotation r = (LSL_Rotation)o;
  15062. sb.Append(r.ToString());
  15063. sb.Append("\"");
  15064. return sb.ToString();
  15065. }
  15066. if (o is LSL_Vector)
  15067. {
  15068. StringBuilder sb = new StringBuilder(128);
  15069. sb.Append("\"");
  15070. LSL_Vector v = (LSL_Vector)o;
  15071. sb.Append(v.ToString());
  15072. sb.Append("\"");
  15073. return sb.ToString();
  15074. }
  15075. if (o is LSL_String || o is string)
  15076. {
  15077. string str;
  15078. if (o is string)
  15079. str = ((string)o);
  15080. else
  15081. str = ((LSL_String)o).m_string;
  15082. if(str == ScriptBaseClass.JSON_TRUE || str == "true")
  15083. return "true";
  15084. if(str == ScriptBaseClass.JSON_FALSE ||str == "false")
  15085. return "false";
  15086. if(str == ScriptBaseClass.JSON_NULL || str == "null")
  15087. return "null";
  15088. str.Trim();
  15089. if (str[0] == '{')
  15090. return str;
  15091. if (str[0] == '[')
  15092. return str;
  15093. return EscapeForJSON(str, true);
  15094. }
  15095. throw new IndexOutOfRangeException();
  15096. }
  15097. private string EscapeForJSON(string s, bool AddOuter)
  15098. {
  15099. int i;
  15100. char c;
  15101. String t;
  15102. int len = s.Length;
  15103. StringBuilder sb = new StringBuilder(len + 64);
  15104. if(AddOuter)
  15105. sb.Append("\"");
  15106. for (i = 0; i < len; i++)
  15107. {
  15108. c = s[i];
  15109. switch (c)
  15110. {
  15111. case '\\':
  15112. case '"':
  15113. case '/':
  15114. sb.Append('\\');
  15115. sb.Append(c);
  15116. break;
  15117. case '\b':
  15118. sb.Append("\\b");
  15119. break;
  15120. case '\t':
  15121. sb.Append("\\t");
  15122. break;
  15123. case '\n':
  15124. sb.Append("\\n");
  15125. break;
  15126. case '\f':
  15127. sb.Append("\\f");
  15128. break;
  15129. case '\r':
  15130. sb.Append("\\r");
  15131. break;
  15132. default:
  15133. if (c < ' ')
  15134. {
  15135. t = "000" + String.Format("{0:X}", c);
  15136. sb.Append("\\u" + t.Substring(t.Length - 4));
  15137. }
  15138. else
  15139. {
  15140. sb.Append(c);
  15141. }
  15142. break;
  15143. }
  15144. }
  15145. if(AddOuter)
  15146. sb.Append("\"");
  15147. return sb.ToString();
  15148. }
  15149. public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
  15150. {
  15151. bool noSpecifiers = specifiers.Length == 0;
  15152. LitJson.JsonData workData;
  15153. try
  15154. {
  15155. if(noSpecifiers)
  15156. specifiers.Add(new LSL_Integer(0));
  15157. if(!String.IsNullOrEmpty(json))
  15158. workData = LitJson.JsonMapper.ToObject(json);
  15159. else
  15160. {
  15161. workData = new LitJson.JsonData();
  15162. workData.SetJsonType(LitJson.JsonType.Array);
  15163. }
  15164. }
  15165. catch (Exception e)
  15166. {
  15167. string m = e.Message; // debug point
  15168. return ScriptBaseClass.JSON_INVALID;
  15169. }
  15170. try
  15171. {
  15172. LitJson.JsonData replace = JsonSetSpecific(workData, specifiers, 0, value);
  15173. if(replace != null)
  15174. workData = replace;
  15175. }
  15176. catch (Exception e)
  15177. {
  15178. string m = e.Message; // debug point
  15179. return ScriptBaseClass.JSON_INVALID;
  15180. }
  15181. try
  15182. {
  15183. string r = LitJson.JsonMapper.ToJson(workData);
  15184. if(noSpecifiers)
  15185. r = r.Substring(1,r.Length -2); // strip leading and trailing brakets
  15186. return r;
  15187. }
  15188. catch (Exception e)
  15189. {
  15190. string m = e.Message; // debug point
  15191. }
  15192. return ScriptBaseClass.JSON_INVALID;
  15193. }
  15194. private LitJson.JsonData JsonSetSpecific(LitJson.JsonData elem, LSL_List specifiers, int level, LSL_String val)
  15195. {
  15196. object spec = specifiers.Data[level];
  15197. if(spec is LSL_String)
  15198. spec = ((LSL_String)spec).m_string;
  15199. else if (spec is LSL_Integer)
  15200. spec = ((LSL_Integer)spec).value;
  15201. if(!(spec is string || spec is int))
  15202. throw new IndexOutOfRangeException();
  15203. int speclen = specifiers.Data.Length - 1;
  15204. bool hasvalue = false;
  15205. LitJson.JsonData value = null;
  15206. LitJson.JsonType elemType = elem.GetJsonType();
  15207. if (elemType == LitJson.JsonType.Array)
  15208. {
  15209. if (spec is int)
  15210. {
  15211. int v = (int)spec;
  15212. int c = elem.Count;
  15213. if(v < 0 || (v != 0 && v > c))
  15214. throw new IndexOutOfRangeException();
  15215. if(v == c)
  15216. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15217. else
  15218. {
  15219. hasvalue = true;
  15220. value = elem[v];
  15221. }
  15222. }
  15223. else if (spec is string)
  15224. {
  15225. if((string)spec == ScriptBaseClass.JSON_APPEND)
  15226. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15227. else if(elem.Count < 2)
  15228. {
  15229. // our initial guess of array was wrong
  15230. LitJson.JsonData newdata = new LitJson.JsonData();
  15231. newdata.SetJsonType(LitJson.JsonType.Object);
  15232. IOrderedDictionary no = newdata as IOrderedDictionary;
  15233. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15234. return newdata;
  15235. }
  15236. }
  15237. }
  15238. else if (elemType == LitJson.JsonType.Object)
  15239. {
  15240. if (spec is string)
  15241. {
  15242. IOrderedDictionary e = elem as IOrderedDictionary;
  15243. string key = (string)spec;
  15244. if(e.Contains(key))
  15245. {
  15246. hasvalue = true;
  15247. value = (LitJson.JsonData)e[key];
  15248. }
  15249. else
  15250. e.Add(key, JsonBuildRestOfSpec(specifiers, level + 1, val));
  15251. }
  15252. else if(spec is int && (int)spec == 0)
  15253. {
  15254. //we are replacing a object by a array
  15255. LitJson.JsonData newData = new LitJson.JsonData();
  15256. newData.SetJsonType(LitJson.JsonType.Array);
  15257. newData.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15258. return newData;
  15259. }
  15260. }
  15261. else
  15262. {
  15263. LitJson.JsonData newData = JsonBuildRestOfSpec(specifiers, level, val);
  15264. return newData;
  15265. }
  15266. if (hasvalue)
  15267. {
  15268. if (level < speclen)
  15269. {
  15270. LitJson.JsonData replace = JsonSetSpecific(value, specifiers, level + 1, val);
  15271. if(replace != null)
  15272. {
  15273. if(elemType == LitJson.JsonType.Array)
  15274. {
  15275. if(spec is int)
  15276. elem[(int)spec] = replace;
  15277. else if( spec is string)
  15278. {
  15279. LitJson.JsonData newdata = new LitJson.JsonData();
  15280. newdata.SetJsonType(LitJson.JsonType.Object);
  15281. IOrderedDictionary no = newdata as IOrderedDictionary;
  15282. no.Add((string)spec, replace);
  15283. return newdata;
  15284. }
  15285. }
  15286. else if(elemType == LitJson.JsonType.Object)
  15287. {
  15288. if(spec is string)
  15289. elem[(string)spec] = replace;
  15290. else if(spec is int && (int)spec == 0)
  15291. {
  15292. LitJson.JsonData newdata = new LitJson.JsonData();
  15293. newdata.SetJsonType(LitJson.JsonType.Array);
  15294. newdata.Add(replace);
  15295. return newdata;
  15296. }
  15297. }
  15298. }
  15299. return null;
  15300. }
  15301. else if(speclen == level)
  15302. {
  15303. if(val == ScriptBaseClass.JSON_DELETE)
  15304. {
  15305. if(elemType == LitJson.JsonType.Array)
  15306. {
  15307. if(spec is int)
  15308. {
  15309. IList el = elem as IList;
  15310. el.RemoveAt((int)spec);
  15311. }
  15312. }
  15313. else if(elemType == LitJson.JsonType.Object)
  15314. {
  15315. if(spec is string)
  15316. {
  15317. IOrderedDictionary eo = elem as IOrderedDictionary;
  15318. eo.Remove((string) spec);
  15319. }
  15320. }
  15321. return null;
  15322. }
  15323. LitJson.JsonData newval = null;
  15324. float num;
  15325. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15326. newval = null;
  15327. else if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15328. newval = new LitJson.JsonData(true);
  15329. else if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15330. newval = new LitJson.JsonData(false);
  15331. else if(float.TryParse(val, out num))
  15332. {
  15333. // assuming we are at en.us already
  15334. if(num - (int)num == 0.0f && !val.Contains("."))
  15335. newval = new LitJson.JsonData((int)num);
  15336. else
  15337. {
  15338. num = (float)Math.Round(num,6);
  15339. newval = new LitJson.JsonData((double)num);
  15340. }
  15341. }
  15342. else
  15343. {
  15344. string str = val.m_string;
  15345. newval = new LitJson.JsonData(str);
  15346. }
  15347. if(elemType == LitJson.JsonType.Array)
  15348. {
  15349. if(spec is int)
  15350. elem[(int)spec] = newval;
  15351. else if( spec is string)
  15352. {
  15353. LitJson.JsonData newdata = new LitJson.JsonData();
  15354. newdata.SetJsonType(LitJson.JsonType.Object);
  15355. IOrderedDictionary no = newdata as IOrderedDictionary;
  15356. no.Add((string)spec,newval);
  15357. return newdata;
  15358. }
  15359. }
  15360. else if(elemType == LitJson.JsonType.Object)
  15361. {
  15362. if(spec is string)
  15363. elem[(string)spec] = newval;
  15364. else if(spec is int && (int)spec == 0)
  15365. {
  15366. LitJson.JsonData newdata = new LitJson.JsonData();
  15367. newdata.SetJsonType(LitJson.JsonType.Array);
  15368. newdata.Add(newval);
  15369. return newdata;
  15370. }
  15371. }
  15372. }
  15373. }
  15374. if(val == ScriptBaseClass.JSON_DELETE)
  15375. throw new IndexOutOfRangeException();
  15376. return null;
  15377. }
  15378. private LitJson.JsonData JsonBuildRestOfSpec(LSL_List specifiers, int level, LSL_String val)
  15379. {
  15380. object spec = level >= specifiers.Data.Length ? null : specifiers.Data[level];
  15381. // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
  15382. float num;
  15383. if (spec == null)
  15384. {
  15385. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15386. return null;
  15387. if(val == ScriptBaseClass.JSON_DELETE)
  15388. throw new IndexOutOfRangeException();
  15389. if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15390. return new LitJson.JsonData(true);
  15391. if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15392. return new LitJson.JsonData(false);
  15393. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15394. return null;
  15395. if(float.TryParse(val, out num))
  15396. {
  15397. // assuming we are at en.us already
  15398. if(num - (int)num == 0.0f && !val.Contains("."))
  15399. return new LitJson.JsonData((int)num);
  15400. else
  15401. {
  15402. num = (float)Math.Round(num,6);
  15403. return new LitJson.JsonData(num);
  15404. }
  15405. }
  15406. else
  15407. {
  15408. string str = val.m_string;
  15409. return new LitJson.JsonData(str);
  15410. }
  15411. throw new IndexOutOfRangeException();
  15412. }
  15413. if(spec is LSL_String)
  15414. spec = ((LSL_String)spec).m_string;
  15415. else if (spec is LSL_Integer)
  15416. spec = ((LSL_Integer)spec).value;
  15417. if (spec is int ||
  15418. (spec is string && ((string)spec) == ScriptBaseClass.JSON_APPEND) )
  15419. {
  15420. if(spec is int && (int)spec != 0)
  15421. throw new IndexOutOfRangeException();
  15422. LitJson.JsonData newdata = new LitJson.JsonData();
  15423. newdata.SetJsonType(LitJson.JsonType.Array);
  15424. newdata.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15425. return newdata;
  15426. }
  15427. else if (spec is string)
  15428. {
  15429. LitJson.JsonData newdata = new LitJson.JsonData();
  15430. newdata.SetJsonType(LitJson.JsonType.Object);
  15431. IOrderedDictionary no = newdata as IOrderedDictionary;
  15432. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15433. return newdata;
  15434. }
  15435. throw new IndexOutOfRangeException();
  15436. }
  15437. private bool JsonFind(LitJson.JsonData elem, LSL_List specifiers, int level, out LitJson.JsonData value)
  15438. {
  15439. value = null;
  15440. if(elem == null)
  15441. return false;
  15442. object spec;
  15443. spec = specifiers.Data[level];
  15444. bool haveVal = false;
  15445. LitJson.JsonData next = null;
  15446. if (elem.GetJsonType() == LitJson.JsonType.Array)
  15447. {
  15448. if (spec is LSL_Integer)
  15449. {
  15450. int indx = (LSL_Integer)spec;
  15451. if(indx >= 0 && indx < elem.Count)
  15452. {
  15453. haveVal = true;
  15454. next = (LitJson.JsonData)elem[indx];
  15455. }
  15456. }
  15457. }
  15458. else if (elem.GetJsonType() == LitJson.JsonType.Object)
  15459. {
  15460. if (spec is LSL_String)
  15461. {
  15462. IOrderedDictionary e = elem as IOrderedDictionary;
  15463. string key = (LSL_String)spec;
  15464. if(e.Contains(key))
  15465. {
  15466. haveVal = true;
  15467. next = (LitJson.JsonData)e[key];
  15468. }
  15469. }
  15470. }
  15471. if (haveVal)
  15472. {
  15473. if(level == specifiers.Data.Length - 1)
  15474. {
  15475. value = next;
  15476. return true;
  15477. }
  15478. level++;
  15479. if(next == null)
  15480. return false;
  15481. LitJson.JsonType nextType = next.GetJsonType();
  15482. if(nextType != LitJson.JsonType.Object && nextType != LitJson.JsonType.Array)
  15483. return false;
  15484. return JsonFind(next, specifiers, level, out value);
  15485. }
  15486. return false;
  15487. }
  15488. public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
  15489. {
  15490. if(String.IsNullOrWhiteSpace(json))
  15491. return ScriptBaseClass.JSON_INVALID;
  15492. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  15493. return ScriptBaseClass.JSON_INVALID;
  15494. char first = ((string)json)[0];
  15495. if((first != '[' && first !='{'))
  15496. {
  15497. if(specifiers.Length > 0)
  15498. return ScriptBaseClass.JSON_INVALID;
  15499. json = "[" + json + "]"; // could handle single element case.. but easier like this
  15500. specifiers.Add((LSL_Integer)0);
  15501. }
  15502. LitJson.JsonData jsonData;
  15503. try
  15504. {
  15505. jsonData = LitJson.JsonMapper.ToObject(json);
  15506. }
  15507. catch (Exception e)
  15508. {
  15509. string m = e.Message; // debug point
  15510. return ScriptBaseClass.JSON_INVALID;
  15511. }
  15512. LitJson.JsonData elem = null;
  15513. if(specifiers.Length == 0)
  15514. elem = jsonData;
  15515. else
  15516. {
  15517. if(!JsonFind(jsonData, specifiers, 0, out elem))
  15518. return ScriptBaseClass.JSON_INVALID;
  15519. }
  15520. return JsonElementToString(elem);
  15521. }
  15522. private LSL_String JsonElementToString(LitJson.JsonData elem)
  15523. {
  15524. if(elem == null)
  15525. return ScriptBaseClass.JSON_NULL;
  15526. LitJson.JsonType elemType = elem.GetJsonType();
  15527. switch(elemType)
  15528. {
  15529. case LitJson.JsonType.Array:
  15530. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  15531. case LitJson.JsonType.Boolean:
  15532. return new LSL_String((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE);
  15533. case LitJson.JsonType.Double:
  15534. double d= (double)elem;
  15535. string sd = String.Format(Culture.FormatProvider, "{0:0.0#####}",d);
  15536. return new LSL_String(sd);
  15537. case LitJson.JsonType.Int:
  15538. int i = (int)elem;
  15539. return new LSL_String(i.ToString());
  15540. case LitJson.JsonType.Long:
  15541. long l = (long)elem;
  15542. return new LSL_String(l.ToString());
  15543. case LitJson.JsonType.Object:
  15544. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  15545. case LitJson.JsonType.String:
  15546. string s = (string)elem;
  15547. return new LSL_String(s);
  15548. case LitJson.JsonType.None:
  15549. return ScriptBaseClass.JSON_NULL;
  15550. default:
  15551. return ScriptBaseClass.JSON_INVALID;
  15552. }
  15553. }
  15554. public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
  15555. {
  15556. if(String.IsNullOrWhiteSpace(json))
  15557. return ScriptBaseClass.JSON_INVALID;
  15558. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  15559. return ScriptBaseClass.JSON_INVALID;
  15560. char first = ((string)json)[0];
  15561. if((first != '[' && first !='{'))
  15562. {
  15563. if(specifiers.Length > 0)
  15564. return ScriptBaseClass.JSON_INVALID;
  15565. json = "[" + json + "]"; // could handle single element case.. but easier like this
  15566. specifiers.Add((LSL_Integer)0);
  15567. }
  15568. LitJson.JsonData jsonData;
  15569. try
  15570. {
  15571. jsonData = LitJson.JsonMapper.ToObject(json);
  15572. }
  15573. catch (Exception e)
  15574. {
  15575. string m = e.Message; // debug point
  15576. return ScriptBaseClass.JSON_INVALID;
  15577. }
  15578. LitJson.JsonData elem = null;
  15579. if(specifiers.Length == 0)
  15580. elem = jsonData;
  15581. else
  15582. {
  15583. if(!JsonFind(jsonData, specifiers, 0, out elem))
  15584. return ScriptBaseClass.JSON_INVALID;
  15585. }
  15586. if(elem == null)
  15587. return ScriptBaseClass.JSON_NULL;
  15588. LitJson.JsonType elemType = elem.GetJsonType();
  15589. switch(elemType)
  15590. {
  15591. case LitJson.JsonType.Array:
  15592. return ScriptBaseClass.JSON_ARRAY;
  15593. case LitJson.JsonType.Boolean:
  15594. return (bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
  15595. case LitJson.JsonType.Double:
  15596. case LitJson.JsonType.Int:
  15597. case LitJson.JsonType.Long:
  15598. return ScriptBaseClass.JSON_NUMBER;
  15599. case LitJson.JsonType.Object:
  15600. return ScriptBaseClass.JSON_OBJECT;
  15601. case LitJson.JsonType.String:
  15602. string s = (string)elem;
  15603. if(s == ScriptBaseClass.JSON_NULL)
  15604. return ScriptBaseClass.JSON_NULL;
  15605. if(s == ScriptBaseClass.JSON_TRUE)
  15606. return ScriptBaseClass.JSON_TRUE;
  15607. if(s == ScriptBaseClass.JSON_FALSE)
  15608. return ScriptBaseClass.JSON_FALSE;
  15609. return ScriptBaseClass.JSON_STRING;
  15610. case LitJson.JsonType.None:
  15611. return ScriptBaseClass.JSON_NULL;
  15612. default:
  15613. return ScriptBaseClass.JSON_INVALID;
  15614. }
  15615. }
  15616. }
  15617. public class NotecardCache
  15618. {
  15619. protected class Notecard
  15620. {
  15621. public string[] text;
  15622. public DateTime lastRef;
  15623. }
  15624. private static Dictionary<UUID, Notecard> m_Notecards =
  15625. new Dictionary<UUID, Notecard>();
  15626. public static void Cache(UUID assetID, byte[] text)
  15627. {
  15628. CheckCache();
  15629. lock (m_Notecards)
  15630. {
  15631. if (m_Notecards.ContainsKey(assetID))
  15632. return;
  15633. Notecard nc = new Notecard();
  15634. nc.lastRef = DateTime.Now;
  15635. try
  15636. {
  15637. nc.text = SLUtil.ParseNotecardToArray(text);
  15638. }
  15639. catch(SLUtil.NotANotecardFormatException)
  15640. {
  15641. nc.text = new string[0];
  15642. }
  15643. m_Notecards[assetID] = nc;
  15644. }
  15645. }
  15646. public static bool IsCached(UUID assetID)
  15647. {
  15648. lock (m_Notecards)
  15649. {
  15650. return m_Notecards.ContainsKey(assetID);
  15651. }
  15652. }
  15653. public static int GetLines(UUID assetID)
  15654. {
  15655. if (!IsCached(assetID))
  15656. return -1;
  15657. lock (m_Notecards)
  15658. {
  15659. m_Notecards[assetID].lastRef = DateTime.Now;
  15660. return m_Notecards[assetID].text.Length;
  15661. }
  15662. }
  15663. /// <summary>
  15664. /// Get a notecard line.
  15665. /// </summary>
  15666. /// <param name="assetID"></param>
  15667. /// <param name="lineNumber">Lines start at index 0</param>
  15668. /// <returns></returns>
  15669. public static string GetLine(UUID assetID, int lineNumber)
  15670. {
  15671. if (lineNumber < 0)
  15672. return "";
  15673. string data;
  15674. if (!IsCached(assetID))
  15675. return "";
  15676. lock (m_Notecards)
  15677. {
  15678. m_Notecards[assetID].lastRef = DateTime.Now;
  15679. if (lineNumber >= m_Notecards[assetID].text.Length)
  15680. return "\n\n\n";
  15681. data = m_Notecards[assetID].text[lineNumber];
  15682. return data;
  15683. }
  15684. }
  15685. /// <summary>
  15686. /// Get a notecard line.
  15687. /// </summary>
  15688. /// <param name="assetID"></param>
  15689. /// <param name="lineNumber">Lines start at index 0</param>
  15690. /// <param name="maxLength">
  15691. /// Maximum length of the returned line.
  15692. /// </param>
  15693. /// <returns>
  15694. /// If the line length is longer than <paramref name="maxLength"/>,
  15695. /// the return string will be truncated.
  15696. /// </returns>
  15697. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  15698. {
  15699. string line = GetLine(assetID, lineNumber);
  15700. if (line.Length > maxLength)
  15701. line = line.Substring(0, maxLength);
  15702. return line;
  15703. }
  15704. public static void CheckCache()
  15705. {
  15706. lock (m_Notecards)
  15707. {
  15708. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  15709. {
  15710. Notecard nc = m_Notecards[key];
  15711. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  15712. m_Notecards.Remove(key);
  15713. }
  15714. }
  15715. }
  15716. }
  15717. }