LSL_Api.cs 359 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963
  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.Runtime.Remoting.Lifetime;
  31. using System.Text;
  32. using System.Threading;
  33. using System.Text.RegularExpressions;
  34. using Nini.Config;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Packets;
  38. using OpenSim;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.CoreModules;
  41. using OpenSim.Region.CoreModules.World.Land;
  42. using OpenSim.Region.CoreModules.World.Terrain;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using OpenSim.Region.Framework.Scenes.Animation;
  46. using OpenSim.Region.Physics.Manager;
  47. using OpenSim.Region.ScriptEngine.Shared;
  48. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  49. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  50. using OpenSim.Region.ScriptEngine.Interfaces;
  51. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  52. using OpenSim.Services.Interfaces;
  53. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  54. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  55. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  56. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  57. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  58. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  59. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  60. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  61. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  62. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  63. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  64. using System.Reflection;
  65. namespace OpenSim.Region.ScriptEngine.Shared.Api
  66. {
  67. /// <summary>
  68. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  69. /// </summary>
  70. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  71. {
  72. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  73. protected IScriptEngine m_ScriptEngine;
  74. protected SceneObjectPart m_host;
  75. protected uint m_localID;
  76. protected UUID m_itemID;
  77. protected bool throwErrorOnNotImplemented = true;
  78. protected AsyncCommandManager AsyncCommands = null;
  79. protected float m_ScriptDelayFactor = 1.0f;
  80. protected float m_ScriptDistanceFactor = 1.0f;
  81. protected float m_MinTimerInterval = 0.5f;
  82. protected DateTime m_timer = DateTime.Now;
  83. protected bool m_waitingForScriptAnswer = false;
  84. protected bool m_automaticLinkPermission = false;
  85. protected IMessageTransferModule m_TransferModule = null;
  86. protected int m_notecardLineReadCharsMax = 255;
  87. protected int m_scriptConsoleChannel = 0;
  88. protected bool m_scriptConsoleChannelEnabled = false;
  89. protected IUrlModule m_UrlModule = null;
  90. public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
  91. {
  92. m_ScriptEngine = ScriptEngine;
  93. m_host = host;
  94. m_localID = localID;
  95. m_itemID = itemID;
  96. m_ScriptDelayFactor =
  97. m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
  98. m_ScriptDistanceFactor =
  99. m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
  100. m_MinTimerInterval =
  101. m_ScriptEngine.Config.GetFloat("MinTimerInterval", 0.5f);
  102. m_automaticLinkPermission =
  103. m_ScriptEngine.Config.GetBoolean("AutomaticLinkPermission", false);
  104. m_notecardLineReadCharsMax =
  105. m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255);
  106. if (m_notecardLineReadCharsMax > 65535)
  107. m_notecardLineReadCharsMax = 65535;
  108. m_TransferModule =
  109. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  110. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  111. if (m_UrlModule != null)
  112. {
  113. m_ScriptEngine.OnScriptRemoved += m_UrlModule.ScriptRemoved;
  114. m_ScriptEngine.OnObjectRemoved += m_UrlModule.ObjectRemoved;
  115. }
  116. AsyncCommands = new AsyncCommandManager(ScriptEngine);
  117. }
  118. public override Object InitializeLifetimeService()
  119. {
  120. ILease lease = (ILease)base.InitializeLifetimeService();
  121. if (lease.CurrentState == LeaseState.Initial)
  122. {
  123. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  124. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  125. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  126. }
  127. return lease;
  128. }
  129. protected virtual void ScriptSleep(int delay)
  130. {
  131. delay = (int)((float)delay * m_ScriptDelayFactor);
  132. if (delay == 0)
  133. return;
  134. System.Threading.Thread.Sleep(delay);
  135. }
  136. public Scene World
  137. {
  138. get { return m_ScriptEngine.World; }
  139. }
  140. public void state(string newState)
  141. {
  142. m_ScriptEngine.SetState(m_itemID, newState);
  143. }
  144. /// <summary>
  145. /// Reset the named script. The script must be present
  146. /// in the same prim.
  147. /// </summary>
  148. public void llResetScript()
  149. {
  150. m_host.AddScriptLPS(1);
  151. m_ScriptEngine.ApiResetScript(m_itemID);
  152. }
  153. public void llResetOtherScript(string name)
  154. {
  155. UUID item;
  156. m_host.AddScriptLPS(1);
  157. if ((item = ScriptByName(name)) != UUID.Zero)
  158. m_ScriptEngine.ResetScript(item);
  159. else
  160. ShoutError("llResetOtherScript: script "+name+" not found");
  161. }
  162. public LSL_Integer llGetScriptState(string name)
  163. {
  164. UUID item;
  165. m_host.AddScriptLPS(1);
  166. if ((item = ScriptByName(name)) != UUID.Zero)
  167. {
  168. return m_ScriptEngine.GetScriptState(item) ?1:0;
  169. }
  170. ShoutError("llGetScriptState: script "+name+" not found");
  171. // If we didn't find it, then it's safe to
  172. // assume it is not running.
  173. return 0;
  174. }
  175. public void llSetScriptState(string name, int run)
  176. {
  177. UUID item;
  178. m_host.AddScriptLPS(1);
  179. // These functions are supposed to be robust,
  180. // so get the state one step at a time.
  181. if ((item = ScriptByName(name)) != UUID.Zero)
  182. {
  183. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
  184. }
  185. else
  186. {
  187. ShoutError("llSetScriptState: script "+name+" not found");
  188. }
  189. }
  190. public List<SceneObjectPart> GetLinkParts(int linkType)
  191. {
  192. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  193. ret.Add(m_host);
  194. switch (linkType)
  195. {
  196. case ScriptBaseClass.LINK_SET:
  197. if (m_host.ParentGroup != null)
  198. return new List<SceneObjectPart>(m_host.ParentGroup.Children.Values);
  199. return ret;
  200. case ScriptBaseClass.LINK_ROOT:
  201. if (m_host.ParentGroup != null)
  202. {
  203. ret = new List<SceneObjectPart>();
  204. ret.Add(m_host.ParentGroup.RootPart);
  205. return ret;
  206. }
  207. return ret;
  208. case ScriptBaseClass.LINK_ALL_OTHERS:
  209. if (m_host.ParentGroup == null)
  210. return new List<SceneObjectPart>();
  211. ret = new List<SceneObjectPart>(m_host.ParentGroup.Children.Values);
  212. if (ret.Contains(m_host))
  213. ret.Remove(m_host);
  214. return ret;
  215. case ScriptBaseClass.LINK_ALL_CHILDREN:
  216. if (m_host.ParentGroup == null)
  217. return new List<SceneObjectPart>();
  218. ret = new List<SceneObjectPart>(m_host.ParentGroup.Children.Values);
  219. if (ret.Contains(m_host.ParentGroup.RootPart))
  220. ret.Remove(m_host.ParentGroup.RootPart);
  221. return ret;
  222. case ScriptBaseClass.LINK_THIS:
  223. return ret;
  224. default:
  225. if (linkType < 0 || m_host.ParentGroup == null)
  226. return new List<SceneObjectPart>();
  227. SceneObjectPart target = m_host.ParentGroup.GetLinkNumPart(linkType);
  228. if (target == null)
  229. return new List<SceneObjectPart>();
  230. ret = new List<SceneObjectPart>();
  231. ret.Add(target);
  232. return ret;
  233. }
  234. }
  235. protected UUID InventorySelf()
  236. {
  237. UUID invItemID = new UUID();
  238. lock (m_host.TaskInventory)
  239. {
  240. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  241. {
  242. if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
  243. {
  244. invItemID = inv.Key;
  245. break;
  246. }
  247. }
  248. }
  249. return invItemID;
  250. }
  251. protected UUID InventoryKey(string name, int type)
  252. {
  253. m_host.AddScriptLPS(1);
  254. lock (m_host.TaskInventory)
  255. {
  256. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  257. {
  258. if (inv.Value.Name == name)
  259. {
  260. if (inv.Value.Type != type)
  261. return UUID.Zero;
  262. return inv.Value.AssetID;
  263. }
  264. }
  265. }
  266. return UUID.Zero;
  267. }
  268. protected UUID InventoryKey(string name)
  269. {
  270. m_host.AddScriptLPS(1);
  271. lock (m_host.TaskInventory)
  272. {
  273. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  274. {
  275. if (inv.Value.Name == name)
  276. {
  277. return inv.Value.AssetID;
  278. }
  279. }
  280. }
  281. return UUID.Zero;
  282. }
  283. /// <summary>
  284. /// accepts a valid UUID, -or- a name of an inventory item.
  285. /// Returns a valid UUID or UUID.Zero if key invalid and item not found
  286. /// in prim inventory.
  287. /// </summary>
  288. /// <param name="k"></param>
  289. /// <returns></returns>
  290. protected UUID KeyOrName(string k)
  291. {
  292. UUID key = UUID.Zero;
  293. // if we can parse the string as a key, use it.
  294. if (UUID.TryParse(k, out key))
  295. {
  296. return key;
  297. }
  298. // else try to locate the name in inventory of object. found returns key,
  299. // not found returns UUID.Zero which will translate to the default particle texture
  300. else
  301. {
  302. return InventoryKey(k);
  303. }
  304. }
  305. // convert a LSL_Rotation to a Quaternion
  306. protected Quaternion Rot2Quaternion(LSL_Rotation r)
  307. {
  308. Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
  309. q.Normalize();
  310. return q;
  311. }
  312. //These are the implementations of the various ll-functions used by the LSL scripts.
  313. public LSL_Float llSin(double f)
  314. {
  315. m_host.AddScriptLPS(1);
  316. return (double)Math.Sin(f);
  317. }
  318. public LSL_Float llCos(double f)
  319. {
  320. m_host.AddScriptLPS(1);
  321. return (double)Math.Cos(f);
  322. }
  323. public LSL_Float llTan(double f)
  324. {
  325. m_host.AddScriptLPS(1);
  326. return (double)Math.Tan(f);
  327. }
  328. public LSL_Float llAtan2(double x, double y)
  329. {
  330. m_host.AddScriptLPS(1);
  331. return (double)Math.Atan2(x, y);
  332. }
  333. public LSL_Float llSqrt(double f)
  334. {
  335. m_host.AddScriptLPS(1);
  336. return (double)Math.Sqrt(f);
  337. }
  338. public LSL_Float llPow(double fbase, double fexponent)
  339. {
  340. m_host.AddScriptLPS(1);
  341. return (double)Math.Pow(fbase, fexponent);
  342. }
  343. public LSL_Integer llAbs(int i)
  344. {
  345. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  346. m_host.AddScriptLPS(1);
  347. if (i == Int32.MinValue)
  348. return i;
  349. else
  350. return (int)Math.Abs(i);
  351. }
  352. public LSL_Float llFabs(double f)
  353. {
  354. m_host.AddScriptLPS(1);
  355. return (double)Math.Abs(f);
  356. }
  357. public LSL_Float llFrand(double mag)
  358. {
  359. m_host.AddScriptLPS(1);
  360. lock (Util.RandomClass)
  361. {
  362. return Util.RandomClass.NextDouble() * mag;
  363. }
  364. }
  365. public LSL_Integer llFloor(double f)
  366. {
  367. m_host.AddScriptLPS(1);
  368. return (int)Math.Floor(f);
  369. }
  370. public LSL_Integer llCeil(double f)
  371. {
  372. m_host.AddScriptLPS(1);
  373. return (int)Math.Ceiling(f);
  374. }
  375. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  376. public LSL_Integer llRound(double f)
  377. {
  378. m_host.AddScriptLPS(1);
  379. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  380. }
  381. //This next group are vector operations involving squaring and square root. ckrinke
  382. public LSL_Float llVecMag(LSL_Vector v)
  383. {
  384. m_host.AddScriptLPS(1);
  385. return LSL_Vector.Mag(v);
  386. }
  387. public LSL_Vector llVecNorm(LSL_Vector v)
  388. {
  389. m_host.AddScriptLPS(1);
  390. return LSL_Vector.Norm(v);
  391. }
  392. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  393. {
  394. m_host.AddScriptLPS(1);
  395. double dx = a.x - b.x;
  396. double dy = a.y - b.y;
  397. double dz = a.z - b.z;
  398. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  399. }
  400. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  401. // Old implementation of llRot2Euler. Normalization not required as Atan2 function will
  402. // only return values >= -PI (-180 degrees) and <= PI (180 degrees).
  403. public LSL_Vector llRot2Euler(LSL_Rotation r)
  404. {
  405. m_host.AddScriptLPS(1);
  406. //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke
  407. LSL_Rotation t = new LSL_Rotation(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s);
  408. double m = (t.x + t.y + t.z + t.s);
  409. if (m == 0) return new LSL_Vector();
  410. double n = 2 * (r.y * r.s + r.x * r.z);
  411. double p = m * m - n * n;
  412. if (p > 0)
  413. return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)),
  414. Math.Atan2(n, Math.Sqrt(p)),
  415. Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)));
  416. else if (n > 0)
  417. return new LSL_Vector(0.0, Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
  418. else
  419. return new LSL_Vector(0.0, -Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
  420. }
  421. /* From wiki:
  422. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  423. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  424. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  425. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  426. */
  427. /* How we arrived at this llEuler2Rot
  428. *
  429. * Experiment in SL to determine conventions:
  430. * llEuler2Rot(<PI,0,0>)=<1,0,0,0>
  431. * llEuler2Rot(<0,PI,0>)=<0,1,0,0>
  432. * llEuler2Rot(<0,0,PI>)=<0,0,1,0>
  433. *
  434. * Important facts about Quaternions
  435. * - multiplication is non-commutative (a*b != b*a)
  436. * - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
  437. *
  438. * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
  439. * Qx = c1+i*s1
  440. * Qy = c2+j*s2;
  441. * Qz = c3+k*s3;
  442. *
  443. * Rotations applied in order (from above) Z, Y, X
  444. * Q = (Qz * Qy) * Qx
  445. * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
  446. * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
  447. * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
  448. * 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
  449. * 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
  450. * regroup: x=i*(s1*c2*c3+c1*s2*s3)
  451. * y=j*(c1*s2*c3-s1*c2*s3)
  452. * z=k*(s1*s2*c3+c1*c2*s3)
  453. * s= c1*c2*c3-s1*s2*s3
  454. *
  455. * This implementation agrees with the functions found here:
  456. * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
  457. * And with the results in SL.
  458. *
  459. * It's also possible to calculate llEuler2Rot by direct multiplication of
  460. * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
  461. * from the wiki).
  462. * Apparently in some cases this is better from a numerical precision perspective?
  463. */
  464. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  465. {
  466. m_host.AddScriptLPS(1);
  467. double x,y,z,s;
  468. double c1 = Math.Cos(v.x * 0.5);
  469. double c2 = Math.Cos(v.y * 0.5);
  470. double c3 = Math.Cos(v.z * 0.5);
  471. double s1 = Math.Sin(v.x * 0.5);
  472. double s2 = Math.Sin(v.y * 0.5);
  473. double s3 = Math.Sin(v.z * 0.5);
  474. x = s1 * c2 * c3 + c1 * s2 * s3;
  475. y = c1 * s2 * c3 - s1 * c2 * s3;
  476. z = s1 * s2 * c3 + c1 * c2 * s3;
  477. s = c1 * c2 * c3 - s1 * s2 * s3;
  478. return new LSL_Rotation(x, y, z, s);
  479. }
  480. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  481. {
  482. m_host.AddScriptLPS(1);
  483. double s;
  484. double tr = fwd.x + left.y + up.z + 1.0;
  485. if (tr >= 1.0)
  486. {
  487. s = 0.5 / Math.Sqrt(tr);
  488. return new LSL_Rotation(
  489. (left.z - up.y) * s,
  490. (up.x - fwd.z) * s,
  491. (fwd.y - left.x) * s,
  492. 0.25 / s);
  493. }
  494. else
  495. {
  496. double max = (left.y > up.z) ? left.y : up.z;
  497. if (max < fwd.x)
  498. {
  499. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  500. double x = s * 0.5;
  501. s = 0.5 / s;
  502. return new LSL_Rotation(
  503. x,
  504. (fwd.y + left.x) * s,
  505. (up.x + fwd.z) * s,
  506. (left.z - up.y) * s);
  507. }
  508. else if (max == left.y)
  509. {
  510. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  511. double y = s * 0.5;
  512. s = 0.5 / s;
  513. return new LSL_Rotation(
  514. (fwd.y + left.x) * s,
  515. y,
  516. (left.z + up.y) * s,
  517. (up.x - fwd.z) * s);
  518. }
  519. else
  520. {
  521. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  522. double z = s * 0.5;
  523. s = 0.5 / s;
  524. return new LSL_Rotation(
  525. (up.x + fwd.z) * s,
  526. (left.z + up.y) * s,
  527. z,
  528. (fwd.y - left.x) * s);
  529. }
  530. }
  531. }
  532. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  533. {
  534. m_host.AddScriptLPS(1);
  535. double x, y, z, m;
  536. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  537. // m is always greater than zero
  538. // if m is not equal to 1 then Rotation needs to be normalized
  539. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  540. {
  541. m = 1.0 / Math.Sqrt(m);
  542. r.x *= m;
  543. r.y *= m;
  544. r.z *= m;
  545. r.s *= m;
  546. }
  547. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  548. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  549. y = 2 * (r.x * r.y + r.z * r.s);
  550. z = 2 * (r.x * r.z - r.y * r.s);
  551. return (new LSL_Vector(x, y, z));
  552. }
  553. public LSL_Vector llRot2Left(LSL_Rotation r)
  554. {
  555. m_host.AddScriptLPS(1);
  556. double x, y, z, m;
  557. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  558. // m is always greater than zero
  559. // if m is not equal to 1 then Rotation needs to be normalized
  560. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  561. {
  562. m = 1.0 / Math.Sqrt(m);
  563. r.x *= m;
  564. r.y *= m;
  565. r.z *= m;
  566. r.s *= m;
  567. }
  568. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  569. x = 2 * (r.x * r.y - r.z * r.s);
  570. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  571. z = 2 * (r.x * r.s + r.y * r.z);
  572. return (new LSL_Vector(x, y, z));
  573. }
  574. public LSL_Vector llRot2Up(LSL_Rotation r)
  575. {
  576. m_host.AddScriptLPS(1);
  577. double x, y, z, m;
  578. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  579. // m is always greater than zero
  580. // if m is not equal to 1 then Rotation needs to be normalized
  581. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  582. {
  583. m = 1.0 / Math.Sqrt(m);
  584. r.x *= m;
  585. r.y *= m;
  586. r.z *= m;
  587. r.s *= m;
  588. }
  589. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  590. x = 2 * (r.x * r.z + r.y * r.s);
  591. y = 2 * (-r.x * r.s + r.y * r.z);
  592. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  593. return (new LSL_Vector(x, y, z));
  594. }
  595. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  596. {
  597. //A and B should both be normalized
  598. m_host.AddScriptLPS(1);
  599. LSL_Rotation rotBetween;
  600. // Check for zero vectors. If either is zero, return zero rotation. Otherwise,
  601. // continue calculation.
  602. if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f))
  603. {
  604. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  605. }
  606. else
  607. {
  608. a = LSL_Vector.Norm(a);
  609. b = LSL_Vector.Norm(b);
  610. double dotProduct = LSL_Vector.Dot(a, b);
  611. // There are two degenerate cases possible. These are for vectors 180 or
  612. // 0 degrees apart. These have to be detected and handled individually.
  613. //
  614. // Check for vectors 180 degrees apart.
  615. // A dot product of -1 would mean the angle between vectors is 180 degrees.
  616. if (dotProduct < -0.9999999f)
  617. {
  618. // First assume X axis is orthogonal to the vectors.
  619. LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f);
  620. orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a));
  621. // Check for near zero vector. A very small non-zero number here will create
  622. // a rotation in an undesired direction.
  623. if (LSL_Vector.Mag(orthoVector) > 0.0001)
  624. {
  625. rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f);
  626. }
  627. // If the magnitude of the vector was near zero, then assume the X axis is not
  628. // orthogonal and use the Z axis instead.
  629. else
  630. {
  631. // Set 180 z rotation.
  632. rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
  633. }
  634. }
  635. // Check for parallel vectors.
  636. // A dot product of 1 would mean the angle between vectors is 0 degrees.
  637. else if (dotProduct > 0.9999999f)
  638. {
  639. // Set zero rotation.
  640. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  641. }
  642. else
  643. {
  644. // All special checks have been performed so get the axis of rotation.
  645. LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
  646. // Quarternion s value is the length of the unit vector + dot product.
  647. double qs = 1.0 + dotProduct;
  648. rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
  649. // Normalize the rotation.
  650. double mag = LSL_Rotation.Mag(rotBetween);
  651. // We shouldn't have to worry about a divide by zero here. The qs value will be
  652. // non-zero because we already know if we're here, then the dotProduct is not -1 so
  653. // qs will not be zero. Also, we've already handled the input vectors being zero so the
  654. // crossProduct vector should also not be zero.
  655. rotBetween.x = rotBetween.x / mag;
  656. rotBetween.y = rotBetween.y / mag;
  657. rotBetween.z = rotBetween.z / mag;
  658. rotBetween.s = rotBetween.s / mag;
  659. // Check for undefined values and set zero rotation if any found. This code might not actually be required
  660. // any longer since zero vectors are checked for at the top.
  661. if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
  662. {
  663. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  664. }
  665. }
  666. }
  667. return rotBetween;
  668. }
  669. public void llWhisper(int channelID, string text)
  670. {
  671. m_host.AddScriptLPS(1);
  672. if (text.Length > 1023)
  673. text = text.Substring(0, 1023);
  674. World.SimChat(Utils.StringToBytes(text),
  675. ChatTypeEnum.Whisper, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  676. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  677. if (wComm != null)
  678. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  679. }
  680. public void llSay(int channelID, string text)
  681. {
  682. m_host.AddScriptLPS(1);
  683. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  684. {
  685. Console.WriteLine(text);
  686. }
  687. else
  688. {
  689. if (text.Length > 1023)
  690. text = text.Substring(0, 1023);
  691. World.SimChat(Utils.StringToBytes(text),
  692. ChatTypeEnum.Say, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  693. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  694. if (wComm != null)
  695. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  696. }
  697. }
  698. public void llShout(int channelID, string text)
  699. {
  700. m_host.AddScriptLPS(1);
  701. if (text.Length > 1023)
  702. text = text.Substring(0, 1023);
  703. World.SimChat(Utils.StringToBytes(text),
  704. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  705. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  706. if (wComm != null)
  707. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  708. }
  709. public void llRegionSay(int channelID, string text)
  710. {
  711. if (channelID == 0)
  712. {
  713. LSLError("Cannot use llRegionSay() on channel 0");
  714. return;
  715. }
  716. if (text.Length > 1023)
  717. text = text.Substring(0, 1023);
  718. m_host.AddScriptLPS(1);
  719. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  720. if (wComm != null)
  721. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  722. }
  723. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  724. {
  725. m_host.AddScriptLPS(1);
  726. UUID keyID;
  727. UUID.TryParse(ID, out keyID);
  728. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  729. if (wComm != null)
  730. return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg);
  731. else
  732. return -1;
  733. }
  734. public void llListenControl(int number, int active)
  735. {
  736. m_host.AddScriptLPS(1);
  737. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  738. if (wComm != null)
  739. wComm.ListenControl(m_itemID, number, active);
  740. }
  741. public void llListenRemove(int number)
  742. {
  743. m_host.AddScriptLPS(1);
  744. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  745. if (wComm != null)
  746. wComm.ListenRemove(m_itemID, number);
  747. }
  748. public void llSensor(string name, string id, int type, double range, double arc)
  749. {
  750. m_host.AddScriptLPS(1);
  751. UUID keyID = UUID.Zero;
  752. UUID.TryParse(id, out keyID);
  753. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host);
  754. }
  755. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  756. {
  757. m_host.AddScriptLPS(1);
  758. UUID keyID = UUID.Zero;
  759. UUID.TryParse(id, out keyID);
  760. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host);
  761. }
  762. public void llSensorRemove()
  763. {
  764. m_host.AddScriptLPS(1);
  765. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID);
  766. }
  767. public string resolveName(UUID objecUUID)
  768. {
  769. // try avatar username surname
  770. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, objecUUID);
  771. if (account != null)
  772. {
  773. string avatarname = account.Name;
  774. return avatarname;
  775. }
  776. // try an scene object
  777. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  778. if (SOP != null)
  779. {
  780. string objectname = SOP.Name;
  781. return objectname;
  782. }
  783. EntityBase SensedObject;
  784. World.Entities.TryGetValue(objecUUID, out SensedObject);
  785. if (SensedObject == null)
  786. {
  787. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  788. if (groups != null)
  789. {
  790. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  791. if (gr != null)
  792. return gr.GroupName;
  793. }
  794. return String.Empty;
  795. }
  796. return SensedObject.Name;
  797. }
  798. public LSL_String llDetectedName(int number)
  799. {
  800. m_host.AddScriptLPS(1);
  801. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  802. if (detectedParams == null)
  803. return String.Empty;
  804. return detectedParams.Name;
  805. }
  806. public LSL_String llDetectedKey(int number)
  807. {
  808. m_host.AddScriptLPS(1);
  809. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  810. if (detectedParams == null)
  811. return String.Empty;
  812. return detectedParams.Key.ToString();
  813. }
  814. public LSL_String llDetectedOwner(int number)
  815. {
  816. m_host.AddScriptLPS(1);
  817. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  818. if (detectedParams == null)
  819. return String.Empty;
  820. return detectedParams.Owner.ToString();
  821. }
  822. public LSL_Integer llDetectedType(int number)
  823. {
  824. m_host.AddScriptLPS(1);
  825. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  826. if (detectedParams == null)
  827. return 0;
  828. return new LSL_Integer(detectedParams.Type);
  829. }
  830. public LSL_Vector llDetectedPos(int number)
  831. {
  832. m_host.AddScriptLPS(1);
  833. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  834. if (detectedParams == null)
  835. return new LSL_Vector();
  836. return detectedParams.Position;
  837. }
  838. public LSL_Vector llDetectedVel(int number)
  839. {
  840. m_host.AddScriptLPS(1);
  841. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  842. if (detectedParams == null)
  843. return new LSL_Vector();
  844. return detectedParams.Velocity;
  845. }
  846. public LSL_Vector llDetectedGrab(int number)
  847. {
  848. m_host.AddScriptLPS(1);
  849. DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number);
  850. if (parms == null)
  851. return new LSL_Vector(0, 0, 0);
  852. return parms.OffsetPos;
  853. }
  854. public LSL_Rotation llDetectedRot(int number)
  855. {
  856. m_host.AddScriptLPS(1);
  857. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  858. if (detectedParams == null)
  859. return new LSL_Rotation();
  860. return detectedParams.Rotation;
  861. }
  862. public LSL_Integer llDetectedGroup(int number)
  863. {
  864. m_host.AddScriptLPS(1);
  865. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  866. if (detectedParams == null)
  867. return new LSL_Integer(0);
  868. if (m_host.GroupID == detectedParams.Group)
  869. return new LSL_Integer(1);
  870. return new LSL_Integer(0);
  871. }
  872. public LSL_Integer llDetectedLinkNumber(int number)
  873. {
  874. m_host.AddScriptLPS(1);
  875. DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number);
  876. if (parms == null)
  877. return new LSL_Integer(0);
  878. return new LSL_Integer(parms.LinkNum);
  879. }
  880. /// <summary>
  881. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  882. /// </summary>
  883. public LSL_Vector llDetectedTouchBinormal(int index)
  884. {
  885. m_host.AddScriptLPS(1);
  886. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  887. if (detectedParams == null)
  888. return new LSL_Vector();
  889. return detectedParams.TouchBinormal;
  890. }
  891. /// <summary>
  892. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  893. /// </summary>
  894. public LSL_Integer llDetectedTouchFace(int index)
  895. {
  896. m_host.AddScriptLPS(1);
  897. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  898. if (detectedParams == null)
  899. return new LSL_Integer(-1);
  900. return new LSL_Integer(detectedParams.TouchFace);
  901. }
  902. /// <summary>
  903. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  904. /// </summary>
  905. public LSL_Vector llDetectedTouchNormal(int index)
  906. {
  907. m_host.AddScriptLPS(1);
  908. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  909. if (detectedParams == null)
  910. return new LSL_Vector();
  911. return detectedParams.TouchNormal;
  912. }
  913. /// <summary>
  914. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  915. /// </summary>
  916. public LSL_Vector llDetectedTouchPos(int index)
  917. {
  918. m_host.AddScriptLPS(1);
  919. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  920. if (detectedParams == null)
  921. return new LSL_Vector();
  922. return detectedParams.TouchPos;
  923. }
  924. /// <summary>
  925. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  926. /// </summary>
  927. public LSL_Vector llDetectedTouchST(int index)
  928. {
  929. m_host.AddScriptLPS(1);
  930. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  931. if (detectedParams == null)
  932. return new LSL_Vector(-1.0, -1.0, 0.0);
  933. return detectedParams.TouchST;
  934. }
  935. /// <summary>
  936. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  937. /// </summary>
  938. public LSL_Vector llDetectedTouchUV(int index)
  939. {
  940. m_host.AddScriptLPS(1);
  941. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  942. if (detectedParams == null)
  943. return new LSL_Vector(-1.0, -1.0, 0.0);
  944. return detectedParams.TouchUV;
  945. }
  946. public virtual void llDie()
  947. {
  948. m_host.AddScriptLPS(1);
  949. throw new SelfDeleteException();
  950. }
  951. public LSL_Float llGround(LSL_Vector offset)
  952. {
  953. m_host.AddScriptLPS(1);
  954. Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x,
  955. (float)offset.y,
  956. (float)offset.z);
  957. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  958. LSL_Vector vsn = llGroundNormal(offset);
  959. // Clamp to valid position
  960. if (pos.X < 0)
  961. pos.X = 0;
  962. else if (pos.X >= World.Heightmap.Width)
  963. pos.X = World.Heightmap.Width - 1;
  964. if (pos.Y < 0)
  965. pos.Y = 0;
  966. else if (pos.Y >= World.Heightmap.Height)
  967. pos.Y = World.Heightmap.Height - 1;
  968. //Get the height for the integer coordinates from the Heightmap
  969. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  970. //Calculate the difference between the actual coordinates and the integer coordinates
  971. float xdiff = pos.X - (float)((int)pos.X);
  972. float ydiff = pos.Y - (float)((int)pos.Y);
  973. //Use the equation of the tangent plane to adjust the height to account for slope
  974. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  975. }
  976. public LSL_Float llCloud(LSL_Vector offset)
  977. {
  978. m_host.AddScriptLPS(1);
  979. float cloudCover = 0f;
  980. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  981. if (module != null)
  982. {
  983. Vector3 pos = m_host.GetWorldPosition();
  984. int x = (int)(pos.X + offset.x);
  985. int y = (int)(pos.Y + offset.y);
  986. cloudCover = module.CloudCover(x, y, 0);
  987. }
  988. return cloudCover;
  989. }
  990. public LSL_Vector llWind(LSL_Vector offset)
  991. {
  992. m_host.AddScriptLPS(1);
  993. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  994. IWindModule module = World.RequestModuleInterface<IWindModule>();
  995. if (module != null)
  996. {
  997. Vector3 pos = m_host.GetWorldPosition();
  998. int x = (int)(pos.X + offset.x);
  999. int y = (int)(pos.Y + offset.y);
  1000. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1001. wind.x = windSpeed.X;
  1002. wind.y = windSpeed.Y;
  1003. }
  1004. return wind;
  1005. }
  1006. public void llSetStatus(int status, int value)
  1007. {
  1008. m_host.AddScriptLPS(1);
  1009. int statusrotationaxis = 0;
  1010. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1011. {
  1012. if (value != 0)
  1013. {
  1014. SceneObjectGroup group = m_host.ParentGroup;
  1015. if (group == null)
  1016. return;
  1017. bool allow = true;
  1018. foreach (SceneObjectPart part in group.Children.Values)
  1019. {
  1020. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1021. {
  1022. allow = false;
  1023. break;
  1024. }
  1025. }
  1026. if (!allow)
  1027. return;
  1028. m_host.ScriptSetPhysicsStatus(true);
  1029. }
  1030. else
  1031. m_host.ScriptSetPhysicsStatus(false);
  1032. }
  1033. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1034. {
  1035. if (value != 0)
  1036. m_host.ScriptSetPhantomStatus(true);
  1037. else
  1038. m_host.ScriptSetPhantomStatus(false);
  1039. }
  1040. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1041. {
  1042. m_host.AddFlag(PrimFlags.CastShadows);
  1043. }
  1044. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1045. {
  1046. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1047. }
  1048. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1049. {
  1050. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1051. }
  1052. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1053. {
  1054. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1055. }
  1056. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1057. {
  1058. if (value != 0)
  1059. m_host.SetBlockGrab(true);
  1060. else
  1061. m_host.SetBlockGrab(false);
  1062. }
  1063. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1064. {
  1065. if (value != 0)
  1066. m_host.SetDieAtEdge(true);
  1067. else
  1068. m_host.SetDieAtEdge(false);
  1069. }
  1070. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1071. {
  1072. if (value != 0)
  1073. m_host.SetReturnAtEdge(true);
  1074. else
  1075. m_host.SetReturnAtEdge(false);
  1076. }
  1077. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1078. {
  1079. if (value != 0)
  1080. m_host.SetStatusSandbox(true);
  1081. else
  1082. m_host.SetStatusSandbox(false);
  1083. }
  1084. if (statusrotationaxis != 0)
  1085. {
  1086. m_host.SetAxisRotation(statusrotationaxis, value);
  1087. }
  1088. }
  1089. public LSL_Integer llGetStatus(int status)
  1090. {
  1091. m_host.AddScriptLPS(1);
  1092. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1093. switch (status)
  1094. {
  1095. case ScriptBaseClass.STATUS_PHYSICS:
  1096. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics)
  1097. {
  1098. return 1;
  1099. }
  1100. return 0;
  1101. case ScriptBaseClass.STATUS_PHANTOM:
  1102. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1103. {
  1104. return 1;
  1105. }
  1106. return 0;
  1107. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1108. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1109. {
  1110. return 1;
  1111. }
  1112. return 0;
  1113. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1114. if (m_host.GetBlockGrab())
  1115. return 1;
  1116. else
  1117. return 0;
  1118. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1119. if (m_host.GetDieAtEdge())
  1120. return 1;
  1121. else
  1122. return 0;
  1123. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1124. if (m_host.GetReturnAtEdge())
  1125. return 1;
  1126. else
  1127. return 0;
  1128. case ScriptBaseClass.STATUS_ROTATE_X:
  1129. if (m_host.GetAxisRotation(2) == 2)
  1130. return 1;
  1131. else
  1132. return 0;
  1133. case ScriptBaseClass.STATUS_ROTATE_Y:
  1134. if (m_host.GetAxisRotation(4) == 4)
  1135. return 1;
  1136. else
  1137. return 0;
  1138. case ScriptBaseClass.STATUS_ROTATE_Z:
  1139. if (m_host.GetAxisRotation(8) == 8)
  1140. return 1;
  1141. else
  1142. return 0;
  1143. case ScriptBaseClass.STATUS_SANDBOX:
  1144. if (m_host.GetStatusSandbox())
  1145. return 1;
  1146. else
  1147. return 0;
  1148. }
  1149. return 0;
  1150. }
  1151. public void llSetScale(LSL_Vector scale)
  1152. {
  1153. m_host.AddScriptLPS(1);
  1154. SetScale(m_host, scale);
  1155. }
  1156. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1157. {
  1158. // TODO: this needs to trigger a persistance save as well
  1159. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1160. return;
  1161. if (scale.x < 0.01)
  1162. scale.x = 0.01;
  1163. if (scale.y < 0.01)
  1164. scale.y = 0.01;
  1165. if (scale.z < 0.01)
  1166. scale.z = 0.01;
  1167. if (part.ParentGroup.RootPart.PhysActor != null && part.ParentGroup.RootPart.PhysActor.IsPhysical)
  1168. {
  1169. if (scale.x > World.m_maxPhys)
  1170. scale.x = World.m_maxPhys;
  1171. if (scale.y > World.m_maxPhys)
  1172. scale.y = World.m_maxPhys;
  1173. if (scale.z > World.m_maxPhys)
  1174. scale.z = World.m_maxPhys;
  1175. }
  1176. if (scale.x > World.m_maxNonphys)
  1177. scale.x = World.m_maxNonphys;
  1178. if (scale.y > World.m_maxNonphys)
  1179. scale.y = World.m_maxNonphys;
  1180. if (scale.z > World.m_maxNonphys)
  1181. scale.z = World.m_maxNonphys;
  1182. Vector3 tmp = part.Scale;
  1183. tmp.X = (float)scale.x;
  1184. tmp.Y = (float)scale.y;
  1185. tmp.Z = (float)scale.z;
  1186. part.Scale = tmp;
  1187. part.SendFullUpdateToAllClients();
  1188. }
  1189. public LSL_Vector llGetScale()
  1190. {
  1191. m_host.AddScriptLPS(1);
  1192. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1193. }
  1194. public void llSetClickAction(int action)
  1195. {
  1196. m_host.AddScriptLPS(1);
  1197. m_host.ClickAction = (byte)action;
  1198. if (m_host.ParentGroup != null) m_host.ParentGroup.HasGroupChanged = true;
  1199. m_host.ScheduleFullUpdate();
  1200. return;
  1201. }
  1202. public void llSetColor(LSL_Vector color, int face)
  1203. {
  1204. m_host.AddScriptLPS(1);
  1205. if (face == ScriptBaseClass.ALL_SIDES)
  1206. face = SceneObjectPart.ALL_SIDES;
  1207. m_host.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
  1208. }
  1209. public void SetTexGen(SceneObjectPart part, int face,int style)
  1210. {
  1211. Primitive.TextureEntry tex = part.Shape.Textures;
  1212. MappingType textype;
  1213. textype = MappingType.Default;
  1214. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1215. textype = MappingType.Planar;
  1216. if (face >= 0 && face < GetNumberOfSides(part))
  1217. {
  1218. tex.CreateFace((uint) face);
  1219. tex.FaceTextures[face].TexMapType = textype;
  1220. part.UpdateTexture(tex);
  1221. return;
  1222. }
  1223. else if (face == ScriptBaseClass.ALL_SIDES)
  1224. {
  1225. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1226. {
  1227. if (tex.FaceTextures[i] != null)
  1228. {
  1229. tex.FaceTextures[i].TexMapType = textype;
  1230. }
  1231. tex.DefaultTexture.TexMapType = textype;
  1232. }
  1233. part.UpdateTexture(tex);
  1234. return;
  1235. }
  1236. }
  1237. public void SetGlow(SceneObjectPart part, int face, float glow)
  1238. {
  1239. Primitive.TextureEntry tex = part.Shape.Textures;
  1240. if (face >= 0 && face < GetNumberOfSides(part))
  1241. {
  1242. tex.CreateFace((uint) face);
  1243. tex.FaceTextures[face].Glow = glow;
  1244. part.UpdateTexture(tex);
  1245. return;
  1246. }
  1247. else if (face == ScriptBaseClass.ALL_SIDES)
  1248. {
  1249. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1250. {
  1251. if (tex.FaceTextures[i] != null)
  1252. {
  1253. tex.FaceTextures[i].Glow = glow;
  1254. }
  1255. tex.DefaultTexture.Glow = glow;
  1256. }
  1257. part.UpdateTexture(tex);
  1258. return;
  1259. }
  1260. }
  1261. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1262. {
  1263. Shininess sval = new Shininess();
  1264. switch (shiny)
  1265. {
  1266. case 0:
  1267. sval = Shininess.None;
  1268. break;
  1269. case 1:
  1270. sval = Shininess.Low;
  1271. break;
  1272. case 2:
  1273. sval = Shininess.Medium;
  1274. break;
  1275. case 3:
  1276. sval = Shininess.High;
  1277. break;
  1278. default:
  1279. sval = Shininess.None;
  1280. break;
  1281. }
  1282. Primitive.TextureEntry tex = part.Shape.Textures;
  1283. if (face >= 0 && face < GetNumberOfSides(part))
  1284. {
  1285. tex.CreateFace((uint) face);
  1286. tex.FaceTextures[face].Shiny = sval;
  1287. tex.FaceTextures[face].Bump = bump;
  1288. part.UpdateTexture(tex);
  1289. return;
  1290. }
  1291. else if (face == ScriptBaseClass.ALL_SIDES)
  1292. {
  1293. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1294. {
  1295. if (tex.FaceTextures[i] != null)
  1296. {
  1297. tex.FaceTextures[i].Shiny = sval;
  1298. tex.FaceTextures[i].Bump = bump;;
  1299. }
  1300. tex.DefaultTexture.Shiny = sval;
  1301. tex.DefaultTexture.Bump = bump;
  1302. }
  1303. part.UpdateTexture(tex);
  1304. return;
  1305. }
  1306. }
  1307. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1308. {
  1309. Primitive.TextureEntry tex = part.Shape.Textures;
  1310. if (face >= 0 && face < GetNumberOfSides(part))
  1311. {
  1312. tex.CreateFace((uint) face);
  1313. tex.FaceTextures[face].Fullbright = bright;
  1314. part.UpdateTexture(tex);
  1315. return;
  1316. }
  1317. else if (face == ScriptBaseClass.ALL_SIDES)
  1318. {
  1319. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1320. {
  1321. if (tex.FaceTextures[i] != null)
  1322. {
  1323. tex.FaceTextures[i].Fullbright = bright;
  1324. }
  1325. }
  1326. tex.DefaultTexture.Fullbright = bright;
  1327. part.UpdateTexture(tex);
  1328. return;
  1329. }
  1330. }
  1331. public LSL_Float llGetAlpha(int face)
  1332. {
  1333. m_host.AddScriptLPS(1);
  1334. return GetAlpha(m_host, face);
  1335. }
  1336. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1337. {
  1338. Primitive.TextureEntry tex = part.Shape.Textures;
  1339. if (face == ScriptBaseClass.ALL_SIDES)
  1340. {
  1341. int i;
  1342. double sum = 0.0;
  1343. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1344. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1345. return sum;
  1346. }
  1347. if (face >= 0 && face < GetNumberOfSides(part))
  1348. {
  1349. return (double)tex.GetFace((uint)face).RGBA.A;
  1350. }
  1351. return 0.0;
  1352. }
  1353. public void llSetAlpha(double alpha, int face)
  1354. {
  1355. m_host.AddScriptLPS(1);
  1356. SetAlpha(m_host, alpha, face);
  1357. }
  1358. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1359. {
  1360. m_host.AddScriptLPS(1);
  1361. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1362. foreach (SceneObjectPart part in parts)
  1363. SetAlpha(part, alpha, face);
  1364. }
  1365. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1366. {
  1367. Primitive.TextureEntry tex = part.Shape.Textures;
  1368. Color4 texcolor;
  1369. if (face >= 0 && face < GetNumberOfSides(part))
  1370. {
  1371. texcolor = tex.CreateFace((uint)face).RGBA;
  1372. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1373. tex.FaceTextures[face].RGBA = texcolor;
  1374. part.UpdateTexture(tex);
  1375. return;
  1376. }
  1377. else if (face == ScriptBaseClass.ALL_SIDES)
  1378. {
  1379. for (int i = 0; i < GetNumberOfSides(part); i++)
  1380. {
  1381. if (tex.FaceTextures[i] != null)
  1382. {
  1383. texcolor = tex.FaceTextures[i].RGBA;
  1384. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1385. tex.FaceTextures[i].RGBA = texcolor;
  1386. }
  1387. }
  1388. texcolor = tex.DefaultTexture.RGBA;
  1389. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1390. tex.DefaultTexture.RGBA = texcolor;
  1391. part.UpdateTexture(tex);
  1392. return;
  1393. }
  1394. }
  1395. /// <summary>
  1396. /// Set flexi parameters of a part.
  1397. ///
  1398. /// FIXME: Much of this code should probably be within the part itself.
  1399. /// </summary>
  1400. /// <param name="part"></param>
  1401. /// <param name="flexi"></param>
  1402. /// <param name="softness"></param>
  1403. /// <param name="gravity"></param>
  1404. /// <param name="friction"></param>
  1405. /// <param name="wind"></param>
  1406. /// <param name="tension"></param>
  1407. /// <param name="Force"></param>
  1408. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1409. float wind, float tension, LSL_Vector Force)
  1410. {
  1411. if (part == null)
  1412. return;
  1413. if (flexi)
  1414. {
  1415. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1416. // work once the prim is already flexi
  1417. part.Shape.FlexiSoftness = softness;
  1418. part.Shape.FlexiGravity = gravity;
  1419. part.Shape.FlexiDrag = friction;
  1420. part.Shape.FlexiWind = wind;
  1421. part.Shape.FlexiTension = tension;
  1422. part.Shape.FlexiForceX = (float)Force.x;
  1423. part.Shape.FlexiForceY = (float)Force.y;
  1424. part.Shape.FlexiForceZ = (float)Force.z;
  1425. part.Shape.PathCurve = 0x80;
  1426. }
  1427. part.ParentGroup.HasGroupChanged = true;
  1428. part.ScheduleFullUpdate();
  1429. }
  1430. /// <summary>
  1431. /// Set a light point on a part
  1432. /// </summary>
  1433. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1434. ///
  1435. /// <param name="part"></param>
  1436. /// <param name="light"></param>
  1437. /// <param name="color"></param>
  1438. /// <param name="intensity"></param>
  1439. /// <param name="radius"></param>
  1440. /// <param name="falloff"></param>
  1441. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1442. {
  1443. if (part == null)
  1444. return;
  1445. if (light)
  1446. {
  1447. part.Shape.LightEntry = true;
  1448. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  1449. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  1450. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  1451. part.Shape.LightIntensity = intensity;
  1452. part.Shape.LightRadius = radius;
  1453. part.Shape.LightFalloff = falloff;
  1454. }
  1455. else
  1456. {
  1457. part.Shape.LightEntry = false;
  1458. }
  1459. part.ParentGroup.HasGroupChanged = true;
  1460. part.ScheduleFullUpdate();
  1461. }
  1462. public LSL_Vector llGetColor(int face)
  1463. {
  1464. m_host.AddScriptLPS(1);
  1465. return GetColor(m_host, face);
  1466. }
  1467. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  1468. {
  1469. Primitive.TextureEntry tex = part.Shape.Textures;
  1470. Color4 texcolor;
  1471. LSL_Vector rgb = new LSL_Vector();
  1472. if (face == ScriptBaseClass.ALL_SIDES)
  1473. {
  1474. int i;
  1475. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1476. {
  1477. texcolor = tex.GetFace((uint)i).RGBA;
  1478. rgb.x += texcolor.R;
  1479. rgb.y += texcolor.G;
  1480. rgb.z += texcolor.B;
  1481. }
  1482. rgb.x /= (float)GetNumberOfSides(part);
  1483. rgb.y /= (float)GetNumberOfSides(part);
  1484. rgb.z /= (float)GetNumberOfSides(part);
  1485. return rgb;
  1486. }
  1487. if (face >= 0 && face < GetNumberOfSides(part))
  1488. {
  1489. texcolor = tex.GetFace((uint)face).RGBA;
  1490. rgb.x = texcolor.R;
  1491. rgb.y = texcolor.G;
  1492. rgb.z = texcolor.B;
  1493. return rgb;
  1494. }
  1495. else
  1496. {
  1497. return new LSL_Vector();
  1498. }
  1499. }
  1500. public void llSetTexture(string texture, int face)
  1501. {
  1502. m_host.AddScriptLPS(1);
  1503. SetTexture(m_host, texture, face);
  1504. ScriptSleep(200);
  1505. }
  1506. public void llSetLinkTexture(int linknumber, string texture, int face)
  1507. {
  1508. m_host.AddScriptLPS(1);
  1509. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1510. foreach (SceneObjectPart part in parts)
  1511. SetTexture(part, texture, face);
  1512. ScriptSleep(200);
  1513. }
  1514. protected void SetTexture(SceneObjectPart part, string texture, int face)
  1515. {
  1516. UUID textureID=new UUID();
  1517. if (!UUID.TryParse(texture, out textureID))
  1518. {
  1519. textureID=InventoryKey(texture, (int)AssetType.Texture);
  1520. }
  1521. if (textureID == UUID.Zero)
  1522. return;
  1523. Primitive.TextureEntry tex = part.Shape.Textures;
  1524. if (face >= 0 && face < GetNumberOfSides(part))
  1525. {
  1526. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1527. texface.TextureID = textureID;
  1528. tex.FaceTextures[face] = texface;
  1529. part.UpdateTexture(tex);
  1530. return;
  1531. }
  1532. else if (face == ScriptBaseClass.ALL_SIDES)
  1533. {
  1534. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1535. {
  1536. if (tex.FaceTextures[i] != null)
  1537. {
  1538. tex.FaceTextures[i].TextureID = textureID;
  1539. }
  1540. }
  1541. tex.DefaultTexture.TextureID = textureID;
  1542. part.UpdateTexture(tex);
  1543. return;
  1544. }
  1545. }
  1546. public void llScaleTexture(double u, double v, int face)
  1547. {
  1548. m_host.AddScriptLPS(1);
  1549. ScaleTexture(m_host, u, v, face);
  1550. ScriptSleep(200);
  1551. }
  1552. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  1553. {
  1554. Primitive.TextureEntry tex = part.Shape.Textures;
  1555. if (face >= 0 && face < GetNumberOfSides(part))
  1556. {
  1557. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1558. texface.RepeatU = (float)u;
  1559. texface.RepeatV = (float)v;
  1560. tex.FaceTextures[face] = texface;
  1561. part.UpdateTexture(tex);
  1562. return;
  1563. }
  1564. if (face == ScriptBaseClass.ALL_SIDES)
  1565. {
  1566. for (int i = 0; i < GetNumberOfSides(part); i++)
  1567. {
  1568. if (tex.FaceTextures[i] != null)
  1569. {
  1570. tex.FaceTextures[i].RepeatU = (float)u;
  1571. tex.FaceTextures[i].RepeatV = (float)v;
  1572. }
  1573. }
  1574. tex.DefaultTexture.RepeatU = (float)u;
  1575. tex.DefaultTexture.RepeatV = (float)v;
  1576. part.UpdateTexture(tex);
  1577. return;
  1578. }
  1579. }
  1580. public void llOffsetTexture(double u, double v, int face)
  1581. {
  1582. m_host.AddScriptLPS(1);
  1583. OffsetTexture(m_host, u, v, face);
  1584. ScriptSleep(200);
  1585. }
  1586. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  1587. {
  1588. Primitive.TextureEntry tex = part.Shape.Textures;
  1589. if (face >= 0 && face < GetNumberOfSides(part))
  1590. {
  1591. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1592. texface.OffsetU = (float)u;
  1593. texface.OffsetV = (float)v;
  1594. tex.FaceTextures[face] = texface;
  1595. part.UpdateTexture(tex);
  1596. return;
  1597. }
  1598. if (face == ScriptBaseClass.ALL_SIDES)
  1599. {
  1600. for (int i = 0; i < GetNumberOfSides(part); i++)
  1601. {
  1602. if (tex.FaceTextures[i] != null)
  1603. {
  1604. tex.FaceTextures[i].OffsetU = (float)u;
  1605. tex.FaceTextures[i].OffsetV = (float)v;
  1606. }
  1607. }
  1608. tex.DefaultTexture.OffsetU = (float)u;
  1609. tex.DefaultTexture.OffsetV = (float)v;
  1610. part.UpdateTexture(tex);
  1611. return;
  1612. }
  1613. }
  1614. public void llRotateTexture(double rotation, int face)
  1615. {
  1616. m_host.AddScriptLPS(1);
  1617. RotateTexture(m_host, rotation, face);
  1618. ScriptSleep(200);
  1619. }
  1620. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  1621. {
  1622. Primitive.TextureEntry tex = part.Shape.Textures;
  1623. if (face >= 0 && face < GetNumberOfSides(part))
  1624. {
  1625. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1626. texface.Rotation = (float)rotation;
  1627. tex.FaceTextures[face] = texface;
  1628. part.UpdateTexture(tex);
  1629. return;
  1630. }
  1631. if (face == ScriptBaseClass.ALL_SIDES)
  1632. {
  1633. for (int i = 0; i < GetNumberOfSides(part); i++)
  1634. {
  1635. if (tex.FaceTextures[i] != null)
  1636. {
  1637. tex.FaceTextures[i].Rotation = (float)rotation;
  1638. }
  1639. }
  1640. tex.DefaultTexture.Rotation = (float)rotation;
  1641. part.UpdateTexture(tex);
  1642. return;
  1643. }
  1644. }
  1645. public LSL_String llGetTexture(int face)
  1646. {
  1647. m_host.AddScriptLPS(1);
  1648. return GetTexture(m_host, face);
  1649. }
  1650. protected LSL_String GetTexture(SceneObjectPart part, int face)
  1651. {
  1652. Primitive.TextureEntry tex = part.Shape.Textures;
  1653. if (face == ScriptBaseClass.ALL_SIDES)
  1654. {
  1655. face = 0;
  1656. }
  1657. if (face >= 0 && face < GetNumberOfSides(part))
  1658. {
  1659. Primitive.TextureEntryFace texface;
  1660. texface = tex.GetFace((uint)face);
  1661. return texface.TextureID.ToString();
  1662. }
  1663. else
  1664. {
  1665. return String.Empty;
  1666. }
  1667. }
  1668. public void llSetPos(LSL_Vector pos)
  1669. {
  1670. m_host.AddScriptLPS(1);
  1671. SetPos(m_host, pos);
  1672. ScriptSleep(200);
  1673. }
  1674. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  1675. // note linked setpos is capped "differently"
  1676. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  1677. {
  1678. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  1679. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  1680. else
  1681. return end;
  1682. }
  1683. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
  1684. {
  1685. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  1686. LSL_Vector currentPos = llGetLocalPos();
  1687. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  1688. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  1689. if (part.ParentGroup.RootPart == part)
  1690. {
  1691. if ((targetPos.z < ground) && disable_underground_movement)
  1692. targetPos.z = ground;
  1693. SceneObjectGroup parent = part.ParentGroup;
  1694. LSL_Vector real_vec = SetPosAdjust(currentPos, targetPos);
  1695. parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z));
  1696. }
  1697. else
  1698. {
  1699. LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos);
  1700. part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
  1701. SceneObjectGroup parent = part.ParentGroup;
  1702. parent.HasGroupChanged = true;
  1703. parent.ScheduleGroupForTerseUpdate();
  1704. }
  1705. }
  1706. public LSL_Vector llGetPos()
  1707. {
  1708. m_host.AddScriptLPS(1);
  1709. Vector3 pos = m_host.GetWorldPosition();
  1710. return new LSL_Vector(pos.X, pos.Y, pos.Z);
  1711. }
  1712. public LSL_Vector llGetLocalPos()
  1713. {
  1714. m_host.AddScriptLPS(1);
  1715. if (m_host.ParentID != 0)
  1716. {
  1717. return new LSL_Vector(m_host.OffsetPosition.X,
  1718. m_host.OffsetPosition.Y,
  1719. m_host.OffsetPosition.Z);
  1720. }
  1721. else
  1722. {
  1723. return new LSL_Vector(m_host.AbsolutePosition.X,
  1724. m_host.AbsolutePosition.Y,
  1725. m_host.AbsolutePosition.Z);
  1726. }
  1727. }
  1728. public void llSetRot(LSL_Rotation rot)
  1729. {
  1730. m_host.AddScriptLPS(1);
  1731. // try to let this work as in SL...
  1732. if (m_host.ParentID == 0)
  1733. {
  1734. // special case: If we are root, rotate complete SOG to new rotation
  1735. SetRot(m_host, Rot2Quaternion(rot));
  1736. }
  1737. else
  1738. {
  1739. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  1740. SceneObjectGroup group = m_host.ParentGroup;
  1741. if (group != null) // a bit paranoid, maybe
  1742. {
  1743. SceneObjectPart rootPart = group.RootPart;
  1744. if (rootPart != null) // again, better safe than sorry
  1745. {
  1746. SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot));
  1747. }
  1748. }
  1749. }
  1750. ScriptSleep(200);
  1751. }
  1752. public void llSetLocalRot(LSL_Rotation rot)
  1753. {
  1754. m_host.AddScriptLPS(1);
  1755. SetRot(m_host, Rot2Quaternion(rot));
  1756. ScriptSleep(200);
  1757. }
  1758. protected void SetRot(SceneObjectPart part, Quaternion rot)
  1759. {
  1760. part.UpdateRotation(rot);
  1761. // Update rotation does not move the object in the physics scene if it's a linkset.
  1762. //KF: Do NOT use this next line if using ODE physics engine. This need a switch based on .ini Phys Engine type
  1763. // part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition;
  1764. // So, after thinking about this for a bit, the issue with the part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition line
  1765. // is it isn't compatible with vehicles because it causes the vehicle body to have to be broken down and rebuilt
  1766. // It's perfectly okay when the object is not an active physical body though.
  1767. // So, part.ParentGroup.ResetChildPrimPhysicsPositions(); does the thing that Kitto is warning against
  1768. // but only if the object is not physial and active. This is important for rotating doors.
  1769. // without the absoluteposition = absoluteposition happening, the doors do not move in the physics
  1770. // scene
  1771. if (part.PhysActor != null && !part.PhysActor.IsPhysical)
  1772. {
  1773. part.ParentGroup.ResetChildPrimPhysicsPositions();
  1774. }
  1775. }
  1776. /// <summary>
  1777. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  1778. /// </summary>
  1779. public LSL_Rotation llGetRot()
  1780. {
  1781. // unlinked or root prim then use llRootRotation
  1782. // see llRootRotaion for references.
  1783. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  1784. {
  1785. return llGetRootRotation();
  1786. }
  1787. m_host.AddScriptLPS(1);
  1788. Quaternion q = m_host.GetWorldRotation();
  1789. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  1790. }
  1791. private LSL_Rotation GetPartRot(SceneObjectPart part)
  1792. {
  1793. Quaternion q;
  1794. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  1795. {
  1796. if (part.ParentGroup.RootPart.AttachmentPoint != 0)
  1797. {
  1798. ScenePresence avatar = World.GetScenePresence(part.AttachedAvatar);
  1799. if (avatar != null)
  1800. {
  1801. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  1802. q = avatar.CameraRotation; // Mouselook
  1803. else
  1804. q = avatar.Rotation; // Currently infrequently updated so may be inaccurate
  1805. }
  1806. else
  1807. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  1808. }
  1809. else
  1810. q = part.ParentGroup.GroupRotation; // just the group rotation
  1811. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  1812. }
  1813. q = part.GetWorldRotation();
  1814. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  1815. }
  1816. public LSL_Rotation llGetLocalRot()
  1817. {
  1818. m_host.AddScriptLPS(1);
  1819. return new LSL_Rotation(m_host.RotationOffset.X, m_host.RotationOffset.Y, m_host.RotationOffset.Z, m_host.RotationOffset.W);
  1820. }
  1821. public void llSetForce(LSL_Vector force, int local)
  1822. {
  1823. m_host.AddScriptLPS(1);
  1824. if (m_host.ParentGroup != null)
  1825. {
  1826. if (!m_host.ParentGroup.IsDeleted)
  1827. {
  1828. if (local != 0)
  1829. force *= llGetRot();
  1830. m_host.ParentGroup.RootPart.SetForce(new Vector3((float)force.x, (float)force.y, (float)force.z));
  1831. }
  1832. }
  1833. }
  1834. public LSL_Vector llGetForce()
  1835. {
  1836. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  1837. m_host.AddScriptLPS(1);
  1838. if (m_host.ParentGroup != null)
  1839. {
  1840. if (!m_host.ParentGroup.IsDeleted)
  1841. {
  1842. Vector3 tmpForce = m_host.ParentGroup.RootPart.GetForce();
  1843. force.x = tmpForce.X;
  1844. force.y = tmpForce.Y;
  1845. force.z = tmpForce.Z;
  1846. }
  1847. }
  1848. return force;
  1849. }
  1850. public LSL_Integer llTarget(LSL_Vector position, double range)
  1851. {
  1852. m_host.AddScriptLPS(1);
  1853. return m_host.registerTargetWaypoint(new Vector3((float)position.x, (float)position.y, (float)position.z), (float)range);
  1854. }
  1855. public void llTargetRemove(int number)
  1856. {
  1857. m_host.AddScriptLPS(1);
  1858. m_host.unregisterTargetWaypoint(number);
  1859. }
  1860. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  1861. {
  1862. m_host.AddScriptLPS(1);
  1863. return m_host.registerRotTargetWaypoint(new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), (float)error);
  1864. }
  1865. public void llRotTargetRemove(int number)
  1866. {
  1867. m_host.AddScriptLPS(1);
  1868. m_host.unregisterRotTargetWaypoint(number);
  1869. }
  1870. public void llMoveToTarget(LSL_Vector target, double tau)
  1871. {
  1872. m_host.AddScriptLPS(1);
  1873. m_host.MoveToTarget(new Vector3((float)target.x, (float)target.y, (float)target.z), (float)tau);
  1874. }
  1875. public void llStopMoveToTarget()
  1876. {
  1877. m_host.AddScriptLPS(1);
  1878. m_host.StopMoveToTarget();
  1879. }
  1880. public void llApplyImpulse(LSL_Vector force, int local)
  1881. {
  1882. m_host.AddScriptLPS(1);
  1883. //No energy force yet
  1884. Vector3 v = new Vector3((float)force.x, (float)force.y, (float)force.z);
  1885. if (v.Length() > 20000.0f)
  1886. {
  1887. v.Normalize();
  1888. v = v * 20000.0f;
  1889. }
  1890. m_host.ApplyImpulse(v, local != 0);
  1891. }
  1892. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  1893. {
  1894. m_host.AddScriptLPS(1);
  1895. m_host.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0);
  1896. }
  1897. public void llSetTorque(LSL_Vector torque, int local)
  1898. {
  1899. m_host.AddScriptLPS(1);
  1900. m_host.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0);
  1901. }
  1902. public LSL_Vector llGetTorque()
  1903. {
  1904. m_host.AddScriptLPS(1);
  1905. Vector3 torque = m_host.GetTorque();
  1906. return new LSL_Vector(torque.X,torque.Y,torque.Z);
  1907. }
  1908. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  1909. {
  1910. m_host.AddScriptLPS(1);
  1911. llSetForce(force, local);
  1912. llSetTorque(torque, local);
  1913. }
  1914. public LSL_Vector llGetVel()
  1915. {
  1916. m_host.AddScriptLPS(1);
  1917. return new LSL_Vector(m_host.Velocity.X, m_host.Velocity.Y, m_host.Velocity.Z);
  1918. }
  1919. public LSL_Vector llGetAccel()
  1920. {
  1921. m_host.AddScriptLPS(1);
  1922. return new LSL_Vector(m_host.Acceleration.X, m_host.Acceleration.Y, m_host.Acceleration.Z);
  1923. }
  1924. public LSL_Vector llGetOmega()
  1925. {
  1926. m_host.AddScriptLPS(1);
  1927. return new LSL_Vector(m_host.AngularVelocity.X, m_host.AngularVelocity.Y, m_host.AngularVelocity.Z);
  1928. }
  1929. public LSL_Float llGetTimeOfDay()
  1930. {
  1931. m_host.AddScriptLPS(1);
  1932. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  1933. }
  1934. public LSL_Float llGetWallclock()
  1935. {
  1936. m_host.AddScriptLPS(1);
  1937. return DateTime.Now.TimeOfDay.TotalSeconds;
  1938. }
  1939. public LSL_Float llGetTime()
  1940. {
  1941. m_host.AddScriptLPS(1);
  1942. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1943. return (double)(ScriptTime.TotalMilliseconds / 1000);
  1944. }
  1945. public void llResetTime()
  1946. {
  1947. m_host.AddScriptLPS(1);
  1948. m_timer = DateTime.Now;
  1949. }
  1950. public LSL_Float llGetAndResetTime()
  1951. {
  1952. m_host.AddScriptLPS(1);
  1953. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1954. m_timer = DateTime.Now;
  1955. return (double)(ScriptTime.TotalMilliseconds / 1000);
  1956. }
  1957. public void llSound(string sound, double volume, int queue, int loop)
  1958. {
  1959. m_host.AddScriptLPS(1);
  1960. // This function has been deprecated
  1961. // see http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSound
  1962. Deprecated("llSound");
  1963. }
  1964. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  1965. // 20080530 Updated to remove code duplication
  1966. public void llPlaySound(string sound, double volume)
  1967. {
  1968. m_host.AddScriptLPS(1);
  1969. // send the sound, once, to all clients in range
  1970. m_host.SendSound(KeyOrName(sound).ToString(), volume, false, 0, 0, false, false);
  1971. }
  1972. // Xantor 20080528 we should do this differently.
  1973. // 1) apply the sound to the object
  1974. // 2) schedule full update
  1975. // just sending the sound out once doesn't work so well when other avatars come in view later on
  1976. // or when the prim gets moved, changed, sat on, whatever
  1977. // see large number of mantises (mantes?)
  1978. // 20080530 Updated to remove code duplication
  1979. // 20080530 Stop sound if there is one, otherwise volume only changes don't work
  1980. public void llLoopSound(string sound, double volume)
  1981. {
  1982. m_host.AddScriptLPS(1);
  1983. if (m_host.Sound != UUID.Zero)
  1984. llStopSound();
  1985. m_host.Sound = KeyOrName(sound);
  1986. m_host.SoundGain = volume;
  1987. m_host.SoundFlags = 1; // looping
  1988. m_host.SoundRadius = 20; // Magic number, 20 seems reasonable. Make configurable?
  1989. m_host.ScheduleFullUpdate();
  1990. m_host.SendFullUpdateToAllClients();
  1991. }
  1992. public void llLoopSoundMaster(string sound, double volume)
  1993. {
  1994. m_host.AddScriptLPS(1);
  1995. m_host.ParentGroup.LoopSoundMasterPrim = m_host;
  1996. lock (m_host.ParentGroup.LoopSoundSlavePrims)
  1997. {
  1998. foreach (SceneObjectPart prim in m_host.ParentGroup.LoopSoundSlavePrims)
  1999. {
  2000. if (prim.Sound != UUID.Zero)
  2001. llStopSound();
  2002. prim.Sound = KeyOrName(sound);
  2003. prim.SoundGain = volume;
  2004. prim.SoundFlags = 1; // looping
  2005. prim.SoundRadius = 20; // Magic number, 20 seems reasonable. Make configurable?
  2006. prim.ScheduleFullUpdate();
  2007. prim.SendFullUpdateToAllClients();
  2008. }
  2009. }
  2010. if (m_host.Sound != UUID.Zero)
  2011. llStopSound();
  2012. m_host.Sound = KeyOrName(sound);
  2013. m_host.SoundGain = volume;
  2014. m_host.SoundFlags = 1; // looping
  2015. m_host.SoundRadius = 20; // Magic number, 20 seems reasonable. Make configurable?
  2016. m_host.ScheduleFullUpdate();
  2017. m_host.SendFullUpdateToAllClients();
  2018. }
  2019. public void llLoopSoundSlave(string sound, double volume)
  2020. {
  2021. m_host.AddScriptLPS(1);
  2022. lock (m_host.ParentGroup.LoopSoundSlavePrims)
  2023. {
  2024. m_host.ParentGroup.LoopSoundSlavePrims.Add(m_host);
  2025. }
  2026. }
  2027. public void llPlaySoundSlave(string sound, double volume)
  2028. {
  2029. m_host.AddScriptLPS(1);
  2030. // send the sound, once, to all clients in range
  2031. m_host.SendSound(KeyOrName(sound).ToString(), volume, false, 0, 0, true, false);
  2032. }
  2033. public void llTriggerSound(string sound, double volume)
  2034. {
  2035. m_host.AddScriptLPS(1);
  2036. // send the sound, once, to all clients in range
  2037. m_host.SendSound(KeyOrName(sound).ToString(), volume, true, 0, 0, false, false);
  2038. }
  2039. // Xantor 20080528: Clear prim data of sound instead
  2040. public void llStopSound()
  2041. {
  2042. m_host.AddScriptLPS(1);
  2043. if (m_host.ParentGroup.LoopSoundSlavePrims.Contains(m_host))
  2044. {
  2045. if (m_host.ParentGroup.LoopSoundMasterPrim == m_host)
  2046. {
  2047. foreach (SceneObjectPart part in m_host.ParentGroup.LoopSoundSlavePrims)
  2048. {
  2049. part.Sound = UUID.Zero;
  2050. part.SoundGain = 0;
  2051. part.SoundFlags = 0;
  2052. part.SoundRadius = 0;
  2053. part.ScheduleFullUpdate();
  2054. part.SendFullUpdateToAllClients();
  2055. }
  2056. m_host.ParentGroup.LoopSoundMasterPrim = null;
  2057. m_host.ParentGroup.LoopSoundSlavePrims.Clear();
  2058. }
  2059. else
  2060. {
  2061. m_host.Sound = UUID.Zero;
  2062. m_host.SoundGain = 0;
  2063. m_host.SoundFlags = 0;
  2064. m_host.SoundRadius = 0;
  2065. m_host.ScheduleFullUpdate();
  2066. m_host.SendFullUpdateToAllClients();
  2067. }
  2068. }
  2069. else
  2070. {
  2071. m_host.Sound = UUID.Zero;
  2072. m_host.SoundGain = 0;
  2073. m_host.SoundFlags = 0;
  2074. m_host.SoundRadius = 0;
  2075. m_host.ScheduleFullUpdate();
  2076. m_host.SendFullUpdateToAllClients();
  2077. }
  2078. }
  2079. public void llPreloadSound(string sound)
  2080. {
  2081. m_host.AddScriptLPS(1);
  2082. m_host.PreloadSound(sound);
  2083. ScriptSleep(1000);
  2084. }
  2085. /// <summary>
  2086. /// Return a portion of the designated string bounded by
  2087. /// inclusive indices (start and end). As usual, the negative
  2088. /// indices, and the tolerance for out-of-bound values, makes
  2089. /// this more complicated than it might otherwise seem.
  2090. /// </summary>
  2091. public LSL_String llGetSubString(string src, int start, int end)
  2092. {
  2093. m_host.AddScriptLPS(1);
  2094. // Normalize indices (if negative).
  2095. // After normlaization they may still be
  2096. // negative, but that is now relative to
  2097. // the start, rather than the end, of the
  2098. // sequence.
  2099. if (start < 0)
  2100. {
  2101. start = src.Length+start;
  2102. }
  2103. if (end < 0)
  2104. {
  2105. end = src.Length+end;
  2106. }
  2107. // Conventional substring
  2108. if (start <= end)
  2109. {
  2110. // Implies both bounds are out-of-range.
  2111. if (end < 0 || start >= src.Length)
  2112. {
  2113. return String.Empty;
  2114. }
  2115. // If end is positive, then it directly
  2116. // corresponds to the lengt of the substring
  2117. // needed (plus one of course). BUT, it
  2118. // must be within bounds.
  2119. if (end >= src.Length)
  2120. {
  2121. end = src.Length-1;
  2122. }
  2123. if (start < 0)
  2124. {
  2125. return src.Substring(0,end+1);
  2126. }
  2127. // Both indices are positive
  2128. return src.Substring(start, (end+1) - start);
  2129. }
  2130. // Inverted substring (end < start)
  2131. else
  2132. {
  2133. // Implies both indices are below the
  2134. // lower bound. In the inverted case, that
  2135. // means the entire string will be returned
  2136. // unchanged.
  2137. if (start < 0)
  2138. {
  2139. return src;
  2140. }
  2141. // If both indices are greater than the upper
  2142. // bound the result may seem initially counter
  2143. // intuitive.
  2144. if (end >= src.Length)
  2145. {
  2146. return src;
  2147. }
  2148. if (end < 0)
  2149. {
  2150. if (start < src.Length)
  2151. {
  2152. return src.Substring(start);
  2153. }
  2154. else
  2155. {
  2156. return String.Empty;
  2157. }
  2158. }
  2159. else
  2160. {
  2161. if (start < src.Length)
  2162. {
  2163. return src.Substring(0,end+1) + src.Substring(start);
  2164. }
  2165. else
  2166. {
  2167. return src.Substring(0,end+1);
  2168. }
  2169. }
  2170. }
  2171. }
  2172. /// <summary>
  2173. /// Delete substring removes the specified substring bounded
  2174. /// by the inclusive indices start and end. Indices may be
  2175. /// negative (indicating end-relative) and may be inverted,
  2176. /// i.e. end < start.
  2177. /// </summary>
  2178. public LSL_String llDeleteSubString(string src, int start, int end)
  2179. {
  2180. m_host.AddScriptLPS(1);
  2181. // Normalize indices (if negative).
  2182. // After normlaization they may still be
  2183. // negative, but that is now relative to
  2184. // the start, rather than the end, of the
  2185. // sequence.
  2186. if (start < 0)
  2187. {
  2188. start = src.Length+start;
  2189. }
  2190. if (end < 0)
  2191. {
  2192. end = src.Length+end;
  2193. }
  2194. // Conventionally delimited substring
  2195. if (start <= end)
  2196. {
  2197. // If both bounds are outside of the existing
  2198. // string, then return unchanges.
  2199. if (end < 0 || start >= src.Length)
  2200. {
  2201. return src;
  2202. }
  2203. // At least one bound is in-range, so we
  2204. // need to clip the out-of-bound argument.
  2205. if (start < 0)
  2206. {
  2207. start = 0;
  2208. }
  2209. if (end >= src.Length)
  2210. {
  2211. end = src.Length-1;
  2212. }
  2213. return src.Remove(start,end-start+1);
  2214. }
  2215. // Inverted substring
  2216. else
  2217. {
  2218. // In this case, out of bounds means that
  2219. // the existing string is part of the cut.
  2220. if (start < 0 || end >= src.Length)
  2221. {
  2222. return String.Empty;
  2223. }
  2224. if (end > 0)
  2225. {
  2226. if (start < src.Length)
  2227. {
  2228. return src.Remove(start).Remove(0,end+1);
  2229. }
  2230. else
  2231. {
  2232. return src.Remove(0,end+1);
  2233. }
  2234. }
  2235. else
  2236. {
  2237. if (start < src.Length)
  2238. {
  2239. return src.Remove(start);
  2240. }
  2241. else
  2242. {
  2243. return src;
  2244. }
  2245. }
  2246. }
  2247. }
  2248. /// <summary>
  2249. /// Insert string inserts the specified string identified by src
  2250. /// at the index indicated by index. Index may be negative, in
  2251. /// which case it is end-relative. The index may exceed either
  2252. /// string bound, with the result being a concatenation.
  2253. /// </summary>
  2254. public LSL_String llInsertString(string dest, int index, string src)
  2255. {
  2256. m_host.AddScriptLPS(1);
  2257. // Normalize indices (if negative).
  2258. // After normlaization they may still be
  2259. // negative, but that is now relative to
  2260. // the start, rather than the end, of the
  2261. // sequence.
  2262. if (index < 0)
  2263. {
  2264. index = dest.Length+index;
  2265. // Negative now means it is less than the lower
  2266. // bound of the string.
  2267. if (index < 0)
  2268. {
  2269. return src+dest;
  2270. }
  2271. }
  2272. if (index >= dest.Length)
  2273. {
  2274. return dest+src;
  2275. }
  2276. // The index is in bounds.
  2277. // In this case the index refers to the index that will
  2278. // be assigned to the first character of the inserted string.
  2279. // So unlike the other string operations, we do not add one
  2280. // to get the correct string length.
  2281. return dest.Substring(0,index)+src+dest.Substring(index);
  2282. }
  2283. public LSL_String llToUpper(string src)
  2284. {
  2285. m_host.AddScriptLPS(1);
  2286. return src.ToUpper();
  2287. }
  2288. public LSL_String llToLower(string src)
  2289. {
  2290. m_host.AddScriptLPS(1);
  2291. return src.ToLower();
  2292. }
  2293. public LSL_Integer llGiveMoney(string destination, int amount)
  2294. {
  2295. UUID invItemID=InventorySelf();
  2296. if (invItemID == UUID.Zero)
  2297. return 0;
  2298. m_host.AddScriptLPS(1);
  2299. TaskInventoryItem item = m_host.TaskInventory[invItemID];
  2300. lock (m_host.TaskInventory)
  2301. {
  2302. item = m_host.TaskInventory[invItemID];
  2303. }
  2304. if (item.PermsGranter == UUID.Zero)
  2305. return 0;
  2306. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  2307. {
  2308. LSLError("No permissions to give money");
  2309. return 0;
  2310. }
  2311. UUID toID = new UUID();
  2312. if (!UUID.TryParse(destination, out toID))
  2313. {
  2314. LSLError("Bad key in llGiveMoney");
  2315. return 0;
  2316. }
  2317. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  2318. if (money == null)
  2319. {
  2320. NotImplemented("llGiveMoney");
  2321. return 0;
  2322. }
  2323. bool result = money.ObjectGiveMoney(
  2324. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  2325. if (result)
  2326. return 1;
  2327. return 0;
  2328. }
  2329. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2330. {
  2331. m_host.AddScriptLPS(1);
  2332. Deprecated("llMakeExplosion");
  2333. ScriptSleep(100);
  2334. }
  2335. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  2336. {
  2337. m_host.AddScriptLPS(1);
  2338. Deprecated("llMakeFountain");
  2339. ScriptSleep(100);
  2340. }
  2341. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2342. {
  2343. m_host.AddScriptLPS(1);
  2344. Deprecated("llMakeSmoke");
  2345. ScriptSleep(100);
  2346. }
  2347. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2348. {
  2349. m_host.AddScriptLPS(1);
  2350. Deprecated("llMakeFire");
  2351. ScriptSleep(100);
  2352. }
  2353. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2354. {
  2355. m_host.AddScriptLPS(1);
  2356. if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  2357. return;
  2358. float dist = (float)llVecDist(llGetPos(), pos);
  2359. if (dist > m_ScriptDistanceFactor * 10.0f)
  2360. return;
  2361. TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  2362. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
  2363. {
  2364. if (inv.Value.Name == inventory)
  2365. {
  2366. // make sure we're an object.
  2367. if (inv.Value.InvType != (int)InventoryType.Object)
  2368. {
  2369. llSay(0, "Unable to create requested object. Object is missing from database.");
  2370. return;
  2371. }
  2372. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  2373. Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z);
  2374. // need the magnitude later
  2375. float velmag = (float)Util.GetMagnitude(llvel);
  2376. SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param);
  2377. // If either of these are null, then there was an unknown error.
  2378. if (new_group == null)
  2379. continue;
  2380. if (new_group.RootPart == null)
  2381. continue;
  2382. // objects rezzed with this method are die_at_edge by default.
  2383. new_group.RootPart.SetDieAtEdge(true);
  2384. new_group.ResumeScripts();
  2385. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  2386. "object_rez", new Object[] {
  2387. new LSL_String(
  2388. new_group.RootPart.UUID.ToString()) },
  2389. new DetectParams[0]));
  2390. float groupmass = new_group.GetMass();
  2391. if (new_group.RootPart.PhysActor != null && new_group.RootPart.PhysActor.IsPhysical && llvel != Vector3.Zero)
  2392. {
  2393. //Recoil.
  2394. llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0);
  2395. }
  2396. // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
  2397. ScriptSleep((int)((groupmass * velmag) / 10));
  2398. ScriptSleep(100);
  2399. return;
  2400. }
  2401. }
  2402. llSay(0, "Could not find object " + inventory);
  2403. }
  2404. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2405. {
  2406. llRezAtRoot(inventory, pos, vel, rot, param);
  2407. }
  2408. public void llLookAt(LSL_Vector target, double strength, double damping)
  2409. {
  2410. m_host.AddScriptLPS(1);
  2411. // Determine where we are looking from
  2412. LSL_Vector from = llGetPos();
  2413. // Work out the normalised vector from the source to the target
  2414. LSL_Vector delta = llVecNorm(target - from);
  2415. LSL_Vector angle = new LSL_Vector(0,0,0);
  2416. // Calculate the yaw
  2417. // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system
  2418. angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO;
  2419. // Calculate pitch
  2420. angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z)));
  2421. // we need to convert from a vector describing
  2422. // the angles of rotation in radians into rotation value
  2423. LSL_Types.Quaternion rot = llEuler2Rot(angle);
  2424. Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
  2425. m_host.startLookAt(rotation, (float)damping, (float)strength);
  2426. // Orient the object to the angle calculated
  2427. //llSetRot(rot);
  2428. }
  2429. public void llStopLookAt()
  2430. {
  2431. m_host.AddScriptLPS(1);
  2432. // NotImplemented("llStopLookAt");
  2433. m_host.StopLookAt();
  2434. }
  2435. public void llSetTimerEvent(double sec)
  2436. {
  2437. if (sec != 0.0 && sec < m_MinTimerInterval)
  2438. sec = m_MinTimerInterval;
  2439. m_host.AddScriptLPS(1);
  2440. // Setting timer repeat
  2441. AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec);
  2442. }
  2443. public virtual void llSleep(double sec)
  2444. {
  2445. m_host.AddScriptLPS(1);
  2446. Thread.Sleep((int)(sec * 1000));
  2447. }
  2448. public LSL_Float llGetMass()
  2449. {
  2450. m_host.AddScriptLPS(1);
  2451. return m_host.GetMass();
  2452. }
  2453. public void llCollisionFilter(string name, string id, int accept)
  2454. {
  2455. m_host.AddScriptLPS(1);
  2456. m_host.CollisionFilter.Clear();
  2457. if (id != null)
  2458. {
  2459. m_host.CollisionFilter.Add(accept,id);
  2460. }
  2461. else
  2462. {
  2463. m_host.CollisionFilter.Add(accept,name);
  2464. }
  2465. }
  2466. public void llTakeControls(int controls, int accept, int pass_on)
  2467. {
  2468. TaskInventoryItem item;
  2469. lock (m_host.TaskInventory)
  2470. {
  2471. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2472. return;
  2473. else
  2474. item = m_host.TaskInventory[InventorySelf()];
  2475. }
  2476. if (item.PermsGranter != UUID.Zero)
  2477. {
  2478. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2479. if (presence != null)
  2480. {
  2481. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2482. {
  2483. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID);
  2484. }
  2485. }
  2486. }
  2487. m_host.AddScriptLPS(1);
  2488. }
  2489. public void llReleaseControls()
  2490. {
  2491. TaskInventoryItem item;
  2492. lock (m_host.TaskInventory)
  2493. {
  2494. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2495. return;
  2496. else
  2497. item = m_host.TaskInventory[InventorySelf()];
  2498. }
  2499. m_host.AddScriptLPS(1);
  2500. if (item.PermsGranter != UUID.Zero)
  2501. {
  2502. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2503. if (presence != null)
  2504. {
  2505. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2506. {
  2507. // Unregister controls from Presence
  2508. presence.UnRegisterControlEventsToScript(m_localID, m_itemID);
  2509. // Remove Take Control permission.
  2510. item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  2511. }
  2512. }
  2513. }
  2514. }
  2515. public void llReleaseURL(string url)
  2516. {
  2517. m_host.AddScriptLPS(1);
  2518. if (m_UrlModule != null)
  2519. m_UrlModule.ReleaseURL(url);
  2520. }
  2521. public void llAttachToAvatar(int attachment)
  2522. {
  2523. m_host.AddScriptLPS(1);
  2524. if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
  2525. return;
  2526. TaskInventoryItem item;
  2527. lock (m_host.TaskInventory)
  2528. {
  2529. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2530. return;
  2531. else
  2532. item = m_host.TaskInventory[InventorySelf()];
  2533. }
  2534. if (item.PermsGranter != m_host.OwnerID)
  2535. return;
  2536. if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2537. {
  2538. SceneObjectGroup grp = m_host.ParentGroup;
  2539. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  2540. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2541. if (attachmentsModule != null)
  2542. attachmentsModule.AttachObject(
  2543. presence.ControllingClient, grp.LocalId,
  2544. (uint)attachment, Quaternion.Identity, Vector3.Zero, false);
  2545. }
  2546. }
  2547. public void llDetachFromAvatar()
  2548. {
  2549. m_host.AddScriptLPS(1);
  2550. if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
  2551. return;
  2552. TaskInventoryItem item;
  2553. lock (m_host.TaskInventory)
  2554. {
  2555. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2556. return;
  2557. else
  2558. item = m_host.TaskInventory[InventorySelf()];
  2559. }
  2560. if (item.PermsGranter != m_host.OwnerID)
  2561. return;
  2562. if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2563. {
  2564. SceneObjectGroup grp = m_host.ParentGroup;
  2565. UUID itemID = grp.GetFromItemID();
  2566. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  2567. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2568. if (attachmentsModule != null)
  2569. attachmentsModule.ShowDetachInUserInventory(itemID, presence.ControllingClient);
  2570. }
  2571. }
  2572. public void llTakeCamera(string avatar)
  2573. {
  2574. m_host.AddScriptLPS(1);
  2575. Deprecated("llTakeCamera");
  2576. }
  2577. public void llReleaseCamera(string avatar)
  2578. {
  2579. m_host.AddScriptLPS(1);
  2580. Deprecated("llReleaseCamera");
  2581. }
  2582. public LSL_String llGetOwner()
  2583. {
  2584. m_host.AddScriptLPS(1);
  2585. return m_host.OwnerID.ToString();
  2586. }
  2587. public void llInstantMessage(string user, string message)
  2588. {
  2589. m_host.AddScriptLPS(1);
  2590. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  2591. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  2592. // but I don't think we have a list of scenes available from here.
  2593. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  2594. // user is a UUID
  2595. // TODO: figure out values for client, fromSession, and imSessionID
  2596. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  2597. UUID friendTransactionID = UUID.Random();
  2598. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  2599. GridInstantMessage msg = new GridInstantMessage();
  2600. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
  2601. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  2602. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  2603. // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  2604. // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  2605. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  2606. //if (client != null)
  2607. //{
  2608. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  2609. //}
  2610. //else
  2611. //{
  2612. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  2613. //}
  2614. // Cap the message length at 1024.
  2615. if (message != null && message.Length > 1024)
  2616. msg.message = message.Substring(0, 1024);
  2617. else
  2618. msg.message = message;
  2619. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  2620. msg.fromGroup = false;// fromGroup;
  2621. msg.offline = (byte)0; //offline;
  2622. msg.ParentEstateID = 0; //ParentEstateID;
  2623. msg.Position = Vector3.Zero;// new Vector3(m_host.AbsolutePosition);
  2624. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  2625. msg.binaryBucket = new byte[0];// binaryBucket;
  2626. if (m_TransferModule != null)
  2627. {
  2628. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  2629. }
  2630. ScriptSleep(2000);
  2631. }
  2632. public void llEmail(string address, string subject, string message)
  2633. {
  2634. m_host.AddScriptLPS(1);
  2635. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2636. if (emailModule == null)
  2637. {
  2638. ShoutError("llEmail: email module not configured");
  2639. return;
  2640. }
  2641. emailModule.SendEmail(m_host.UUID, address, subject, message);
  2642. ScriptSleep(20000);
  2643. }
  2644. public void llGetNextEmail(string address, string subject)
  2645. {
  2646. m_host.AddScriptLPS(1);
  2647. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2648. if (emailModule == null)
  2649. {
  2650. ShoutError("llGetNextEmail: email module not configured");
  2651. return;
  2652. }
  2653. Email email;
  2654. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  2655. if (email == null)
  2656. return;
  2657. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  2658. new EventParams("email",
  2659. new Object[] {
  2660. new LSL_String(email.time),
  2661. new LSL_String(email.sender),
  2662. new LSL_String(email.subject),
  2663. new LSL_String(email.message),
  2664. new LSL_Integer(email.numLeft)},
  2665. new DetectParams[0]));
  2666. }
  2667. public LSL_String llGetKey()
  2668. {
  2669. m_host.AddScriptLPS(1);
  2670. return m_host.UUID.ToString();
  2671. }
  2672. public void llSetBuoyancy(double buoyancy)
  2673. {
  2674. m_host.AddScriptLPS(1);
  2675. if (m_host.ParentGroup != null)
  2676. {
  2677. if (!m_host.ParentGroup.IsDeleted)
  2678. {
  2679. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  2680. }
  2681. }
  2682. }
  2683. /// <summary>
  2684. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  2685. /// </summary>
  2686. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2687. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  2688. /// <param name="tau">Number of seconds over which to reach target</param>
  2689. public void llSetHoverHeight(double height, int water, double tau)
  2690. {
  2691. m_host.AddScriptLPS(1);
  2692. if (m_host.PhysActor != null)
  2693. {
  2694. PIDHoverType hoverType = PIDHoverType.Ground;
  2695. if (water != 0)
  2696. {
  2697. hoverType = PIDHoverType.GroundAndWater;
  2698. }
  2699. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  2700. }
  2701. }
  2702. public void llStopHover()
  2703. {
  2704. m_host.AddScriptLPS(1);
  2705. if (m_host.PhysActor != null)
  2706. {
  2707. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  2708. }
  2709. }
  2710. public void llMinEventDelay(double delay)
  2711. {
  2712. m_host.AddScriptLPS(1);
  2713. try
  2714. {
  2715. m_ScriptEngine.SetMinEventDelay(m_itemID, delay);
  2716. }
  2717. catch (NotImplementedException)
  2718. {
  2719. // Currently not implemented in DotNetEngine only XEngine
  2720. NotImplemented("llMinEventDelay in DotNetEngine");
  2721. }
  2722. }
  2723. /// <summary>
  2724. /// llSoundPreload is deprecated. In SL this appears to do absolutely nothing
  2725. /// and is documented to have no delay.
  2726. /// </summary>
  2727. public void llSoundPreload(string sound)
  2728. {
  2729. m_host.AddScriptLPS(1);
  2730. }
  2731. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  2732. {
  2733. m_host.AddScriptLPS(1);
  2734. Quaternion rot = new Quaternion((float)target.x, (float)target.y, (float)target.z, (float)target.s);
  2735. m_host.RotLookAt(rot, (float)strength, (float)damping);
  2736. }
  2737. public LSL_Integer llStringLength(string str)
  2738. {
  2739. m_host.AddScriptLPS(1);
  2740. if (str.Length > 0)
  2741. {
  2742. return str.Length;
  2743. }
  2744. else
  2745. {
  2746. return 0;
  2747. }
  2748. }
  2749. public void llStartAnimation(string anim)
  2750. {
  2751. m_host.AddScriptLPS(1);
  2752. UUID invItemID = InventorySelf();
  2753. if (invItemID == UUID.Zero)
  2754. return;
  2755. TaskInventoryItem item;
  2756. lock (m_host.TaskInventory)
  2757. {
  2758. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2759. return;
  2760. else
  2761. item = m_host.TaskInventory[InventorySelf()];
  2762. }
  2763. if (item.PermsGranter == UUID.Zero)
  2764. return;
  2765. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  2766. {
  2767. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2768. if (presence != null)
  2769. {
  2770. // Do NOT try to parse UUID, animations cannot be triggered by ID
  2771. UUID animID = InventoryKey(anim, (int)AssetType.Animation);
  2772. if (animID == UUID.Zero)
  2773. presence.Animator.AddAnimation(anim, m_host.UUID);
  2774. else
  2775. presence.Animator.AddAnimation(animID, m_host.UUID);
  2776. }
  2777. }
  2778. }
  2779. public void llStopAnimation(string anim)
  2780. {
  2781. m_host.AddScriptLPS(1);
  2782. UUID invItemID=InventorySelf();
  2783. if (invItemID == UUID.Zero)
  2784. return;
  2785. TaskInventoryItem item;
  2786. lock (m_host.TaskInventory)
  2787. {
  2788. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2789. return;
  2790. else
  2791. item = m_host.TaskInventory[InventorySelf()];
  2792. }
  2793. if (item.PermsGranter == UUID.Zero)
  2794. return;
  2795. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  2796. {
  2797. UUID animID = new UUID();
  2798. if (!UUID.TryParse(anim, out animID))
  2799. {
  2800. animID=InventoryKey(anim);
  2801. }
  2802. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2803. if (presence != null)
  2804. {
  2805. if (animID == UUID.Zero)
  2806. presence.Animator.RemoveAnimation(anim);
  2807. else
  2808. presence.Animator.RemoveAnimation(animID);
  2809. }
  2810. }
  2811. }
  2812. public void llPointAt(LSL_Vector pos)
  2813. {
  2814. m_host.AddScriptLPS(1);
  2815. ScenePresence Owner = World.GetScenePresence(m_host.UUID);
  2816. LSL_Rotation rot = llEuler2Rot(pos);
  2817. Owner.PreviousRotation = Owner.Rotation;
  2818. Owner.Rotation = (new Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s));
  2819. }
  2820. public void llStopPointAt()
  2821. {
  2822. m_host.AddScriptLPS(1);
  2823. ScenePresence Owner = m_host.ParentGroup.Scene.GetScenePresence(m_host.OwnerID);
  2824. Owner.Rotation = Owner.PreviousRotation;
  2825. }
  2826. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  2827. {
  2828. m_host.AddScriptLPS(1);
  2829. m_host.AngularVelocity = new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  2830. m_host.ScheduleTerseUpdate();
  2831. m_host.SendTerseUpdateToAllClients();
  2832. m_host.ParentGroup.HasGroupChanged = true;
  2833. }
  2834. public LSL_Integer llGetStartParameter()
  2835. {
  2836. m_host.AddScriptLPS(1);
  2837. return m_ScriptEngine.GetStartParameter(m_itemID);
  2838. }
  2839. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  2840. {
  2841. m_host.AddScriptLPS(1);
  2842. NotImplemented("llGodLikeRezObject");
  2843. }
  2844. public void llRequestPermissions(string agent, int perm)
  2845. {
  2846. UUID agentID = new UUID();
  2847. if (!UUID.TryParse(agent, out agentID))
  2848. return;
  2849. UUID invItemID = InventorySelf();
  2850. if (invItemID == UUID.Zero)
  2851. return; // Not in a prim? How??
  2852. TaskInventoryItem item;
  2853. lock (m_host.TaskInventory)
  2854. {
  2855. item = m_host.TaskInventory[invItemID];
  2856. }
  2857. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  2858. {
  2859. llReleaseControls();
  2860. item.PermsGranter = UUID.Zero;
  2861. item.PermsMask = 0;
  2862. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2863. "run_time_permissions", new Object[] {
  2864. new LSL_Integer(0) },
  2865. new DetectParams[0]));
  2866. return;
  2867. }
  2868. if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  2869. llReleaseControls();
  2870. m_host.AddScriptLPS(1);
  2871. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.RootPart.AttachedAvatar)
  2872. {
  2873. // When attached, certain permissions are implicit if requested from owner
  2874. int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  2875. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  2876. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  2877. ScriptBaseClass.PERMISSION_ATTACH;
  2878. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  2879. {
  2880. lock (m_host.TaskInventory)
  2881. {
  2882. m_host.TaskInventory[invItemID].PermsGranter = agentID;
  2883. m_host.TaskInventory[invItemID].PermsMask = perm;
  2884. }
  2885. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2886. "run_time_permissions", new Object[] {
  2887. new LSL_Integer(perm) },
  2888. new DetectParams[0]));
  2889. return;
  2890. }
  2891. }
  2892. else if (m_host.SitTargetAvatar == agentID) // Sitting avatar
  2893. {
  2894. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  2895. int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  2896. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  2897. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  2898. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  2899. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  2900. {
  2901. lock (m_host.TaskInventory)
  2902. {
  2903. m_host.TaskInventory[invItemID].PermsGranter = agentID;
  2904. m_host.TaskInventory[invItemID].PermsMask = perm;
  2905. }
  2906. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2907. "run_time_permissions", new Object[] {
  2908. new LSL_Integer(perm) },
  2909. new DetectParams[0]));
  2910. return;
  2911. }
  2912. }
  2913. ScenePresence presence = World.GetScenePresence(agentID);
  2914. if (presence != null)
  2915. {
  2916. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  2917. if (ownerName == String.Empty)
  2918. ownerName = "(hippos)";
  2919. if (!m_waitingForScriptAnswer)
  2920. {
  2921. lock (m_host.TaskInventory)
  2922. {
  2923. m_host.TaskInventory[invItemID].PermsGranter = agentID;
  2924. m_host.TaskInventory[invItemID].PermsMask = 0;
  2925. }
  2926. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  2927. m_waitingForScriptAnswer=true;
  2928. }
  2929. presence.ControllingClient.SendScriptQuestion(
  2930. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
  2931. return;
  2932. }
  2933. // Requested agent is not in range, refuse perms
  2934. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2935. "run_time_permissions", new Object[] {
  2936. new LSL_Integer(0) },
  2937. new DetectParams[0]));
  2938. }
  2939. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  2940. {
  2941. if (taskID != m_host.UUID)
  2942. return;
  2943. UUID invItemID = InventorySelf();
  2944. if (invItemID == UUID.Zero)
  2945. return;
  2946. client.OnScriptAnswer-=handleScriptAnswer;
  2947. m_waitingForScriptAnswer=false;
  2948. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  2949. llReleaseControls();
  2950. lock (m_host.TaskInventory)
  2951. {
  2952. m_host.TaskInventory[invItemID].PermsMask = answer;
  2953. }
  2954. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2955. "run_time_permissions", new Object[] {
  2956. new LSL_Integer(answer) },
  2957. new DetectParams[0]));
  2958. }
  2959. public LSL_String llGetPermissionsKey()
  2960. {
  2961. m_host.AddScriptLPS(1);
  2962. lock (m_host.TaskInventory)
  2963. {
  2964. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2965. {
  2966. if (item.Type == 10 && item.ItemID == m_itemID)
  2967. {
  2968. return item.PermsGranter.ToString();
  2969. }
  2970. }
  2971. }
  2972. return UUID.Zero.ToString();
  2973. }
  2974. public LSL_Integer llGetPermissions()
  2975. {
  2976. m_host.AddScriptLPS(1);
  2977. lock (m_host.TaskInventory)
  2978. {
  2979. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2980. {
  2981. if (item.Type == 10 && item.ItemID == m_itemID)
  2982. {
  2983. int perms = item.PermsMask;
  2984. if (m_automaticLinkPermission)
  2985. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  2986. return perms;
  2987. }
  2988. }
  2989. }
  2990. return 0;
  2991. }
  2992. public LSL_Integer llGetLinkNumber()
  2993. {
  2994. m_host.AddScriptLPS(1);
  2995. if (m_host.ParentGroup.Children.Count > 1)
  2996. {
  2997. return m_host.LinkNum;
  2998. }
  2999. else
  3000. {
  3001. return 0;
  3002. }
  3003. }
  3004. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3005. {
  3006. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3007. foreach (SceneObjectPart part in parts)
  3008. part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
  3009. }
  3010. public void llCreateLink(string target, int parent)
  3011. {
  3012. m_host.AddScriptLPS(1);
  3013. UUID invItemID = InventorySelf();
  3014. TaskInventoryItem item;
  3015. lock (m_host.TaskInventory)
  3016. {
  3017. item = m_host.TaskInventory[invItemID];
  3018. }
  3019. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3020. && !m_automaticLinkPermission)
  3021. {
  3022. ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3023. return;
  3024. }
  3025. IClientAPI client = null;
  3026. ScenePresence sp = World.GetScenePresence(item.PermsGranter);
  3027. if (sp != null)
  3028. client = sp.ControllingClient;
  3029. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)target);
  3030. if (targetPart.ParentGroup.RootPart.AttachmentPoint != 0)
  3031. return; // Fail silently if attached
  3032. SceneObjectGroup parentPrim = null, childPrim = null;
  3033. if (targetPart != null)
  3034. {
  3035. if (parent != 0) {
  3036. parentPrim = m_host.ParentGroup;
  3037. childPrim = targetPart.ParentGroup;
  3038. }
  3039. else
  3040. {
  3041. parentPrim = targetPart.ParentGroup;
  3042. childPrim = m_host.ParentGroup;
  3043. }
  3044. // byte uf = childPrim.RootPart.UpdateFlag;
  3045. childPrim.RootPart.UpdateFlag = 0;
  3046. parentPrim.LinkToGroup(childPrim);
  3047. // if (uf != (Byte)0)
  3048. // parent.RootPart.UpdateFlag = uf;
  3049. }
  3050. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3051. parentPrim.RootPart.CreateSelected = true;
  3052. parentPrim.HasGroupChanged = true;
  3053. parentPrim.ScheduleGroupForFullUpdate();
  3054. if (client != null)
  3055. parentPrim.GetProperties(client);
  3056. ScriptSleep(1000);
  3057. }
  3058. public void llBreakLink(int linknum)
  3059. {
  3060. m_host.AddScriptLPS(1);
  3061. UUID invItemID = InventorySelf();
  3062. lock (m_host.TaskInventory)
  3063. {
  3064. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3065. && !m_automaticLinkPermission)
  3066. {
  3067. ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3068. return;
  3069. }
  3070. }
  3071. if (linknum < ScriptBaseClass.LINK_THIS)
  3072. return;
  3073. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3074. if (parentPrim.RootPart.AttachmentPoint != 0)
  3075. return; // Fail silently if attached
  3076. SceneObjectPart childPrim = null;
  3077. switch (linknum)
  3078. {
  3079. case ScriptBaseClass.LINK_ROOT:
  3080. break;
  3081. case ScriptBaseClass.LINK_SET:
  3082. case ScriptBaseClass.LINK_ALL_OTHERS:
  3083. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3084. case ScriptBaseClass.LINK_THIS:
  3085. foreach (SceneObjectPart part in parentPrim.Children.Values)
  3086. {
  3087. if (part.UUID != m_host.UUID)
  3088. {
  3089. childPrim = part;
  3090. break;
  3091. }
  3092. }
  3093. break;
  3094. default:
  3095. childPrim = parentPrim.GetLinkNumPart(linknum);
  3096. if (childPrim.UUID == m_host.UUID)
  3097. childPrim = null;
  3098. break;
  3099. }
  3100. if (linknum == ScriptBaseClass.LINK_ROOT)
  3101. {
  3102. // Restructuring Multiple Prims.
  3103. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
  3104. parts.Remove(parentPrim.RootPart);
  3105. foreach (SceneObjectPart part in parts)
  3106. {
  3107. parentPrim.DelinkFromGroup(part.LocalId, true);
  3108. }
  3109. parentPrim.HasGroupChanged = true;
  3110. parentPrim.ScheduleGroupForFullUpdate();
  3111. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3112. if (parts.Count > 0)
  3113. {
  3114. SceneObjectPart newRoot = parts[0];
  3115. parts.Remove(newRoot);
  3116. foreach (SceneObjectPart part in parts)
  3117. {
  3118. part.UpdateFlag = 0;
  3119. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3120. }
  3121. newRoot.ParentGroup.HasGroupChanged = true;
  3122. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3123. }
  3124. }
  3125. else
  3126. {
  3127. if (childPrim == null)
  3128. return;
  3129. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3130. parentPrim.HasGroupChanged = true;
  3131. parentPrim.ScheduleGroupForFullUpdate();
  3132. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3133. }
  3134. }
  3135. public void llBreakAllLinks()
  3136. {
  3137. m_host.AddScriptLPS(1);
  3138. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3139. if (parentPrim.RootPart.AttachmentPoint != 0)
  3140. return; // Fail silently if attached
  3141. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
  3142. parts.Remove(parentPrim.RootPart);
  3143. foreach (SceneObjectPart part in parts)
  3144. {
  3145. parentPrim.DelinkFromGroup(part.LocalId, true);
  3146. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3147. }
  3148. parentPrim.HasGroupChanged = true;
  3149. parentPrim.ScheduleGroupForFullUpdate();
  3150. }
  3151. public LSL_String llGetLinkKey(int linknum)
  3152. {
  3153. m_host.AddScriptLPS(1);
  3154. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3155. if (part != null)
  3156. {
  3157. return part.UUID.ToString();
  3158. }
  3159. else
  3160. {
  3161. return UUID.Zero.ToString();
  3162. }
  3163. }
  3164. /// <summary>
  3165. /// The rules governing the returned name are not simple. The only
  3166. /// time a blank name is returned is if the target prim has a blank
  3167. /// name. If no prim with the given link number can be found then
  3168. /// usually NULL_KEY is returned but there are exceptions.
  3169. ///
  3170. /// In a single unlinked prim, A call with 0 returns the name, all
  3171. /// other values for link number return NULL_KEY
  3172. ///
  3173. /// In link sets it is more complicated.
  3174. ///
  3175. /// If the script is in the root prim:-
  3176. /// A zero link number returns NULL_KEY.
  3177. /// Positive link numbers return the name of the prim, or NULL_KEY
  3178. /// if a prim does not exist at that position.
  3179. /// Negative link numbers return the name of the first child prim.
  3180. ///
  3181. /// If the script is in a child prim:-
  3182. /// Link numbers 0 or 1 return the name of the root prim.
  3183. /// Positive link numbers return the name of the prim or NULL_KEY
  3184. /// if a prim does not exist at that position.
  3185. /// Negative numbers return the name of the root prim.
  3186. ///
  3187. /// References
  3188. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  3189. /// Mentions NULL_KEY being returned
  3190. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  3191. /// Mentions using the LINK_* constants, some of which are negative
  3192. /// </summary>
  3193. public LSL_String llGetLinkName(int linknum)
  3194. {
  3195. m_host.AddScriptLPS(1);
  3196. // simplest case, this prims link number
  3197. if (m_host.LinkNum == linknum)
  3198. return m_host.Name;
  3199. // Single prim
  3200. if (m_host.LinkNum == 0)
  3201. {
  3202. if (linknum == 0)
  3203. return m_host.Name;
  3204. else
  3205. return UUID.Zero.ToString();
  3206. }
  3207. // Link set
  3208. SceneObjectPart part = null;
  3209. if (m_host.LinkNum == 1) // this is the Root prim
  3210. {
  3211. if (linknum < 0)
  3212. part = m_host.ParentGroup.GetLinkNumPart(2);
  3213. else
  3214. part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3215. }
  3216. else // this is a child prim
  3217. {
  3218. if (linknum < 2)
  3219. part = m_host.ParentGroup.GetLinkNumPart(1);
  3220. else
  3221. part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3222. }
  3223. if (part != null)
  3224. return part.Name;
  3225. else
  3226. return UUID.Zero.ToString();
  3227. }
  3228. public LSL_Integer llGetInventoryNumber(int type)
  3229. {
  3230. m_host.AddScriptLPS(1);
  3231. int count = 0;
  3232. lock (m_host.TaskInventory)
  3233. {
  3234. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3235. {
  3236. if (inv.Value.Type == type || type == -1)
  3237. {
  3238. count = count + 1;
  3239. }
  3240. }
  3241. }
  3242. return count;
  3243. }
  3244. public LSL_String llGetInventoryName(int type, int number)
  3245. {
  3246. m_host.AddScriptLPS(1);
  3247. ArrayList keys = new ArrayList();
  3248. lock (m_host.TaskInventory)
  3249. {
  3250. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3251. {
  3252. if (inv.Value.Type == type || type == -1)
  3253. {
  3254. keys.Add(inv.Value.Name);
  3255. }
  3256. }
  3257. }
  3258. if (keys.Count == 0)
  3259. {
  3260. return String.Empty;
  3261. }
  3262. keys.Sort();
  3263. if (keys.Count > number)
  3264. {
  3265. return (string)keys[number];
  3266. }
  3267. return String.Empty;
  3268. }
  3269. public LSL_Float llGetEnergy()
  3270. {
  3271. m_host.AddScriptLPS(1);
  3272. // TODO: figure out real energy value
  3273. return 1.0f;
  3274. }
  3275. public void llGiveInventory(string destination, string inventory)
  3276. {
  3277. m_host.AddScriptLPS(1);
  3278. bool found = false;
  3279. UUID destId = UUID.Zero;
  3280. UUID objId = UUID.Zero;
  3281. int assetType = 0;
  3282. string objName = String.Empty;
  3283. if (!UUID.TryParse(destination, out destId))
  3284. {
  3285. llSay(0, "Could not parse key " + destination);
  3286. return;
  3287. }
  3288. // move the first object found with this inventory name
  3289. lock (m_host.TaskInventory)
  3290. {
  3291. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3292. {
  3293. if (inv.Value.Name == inventory)
  3294. {
  3295. found = true;
  3296. objId = inv.Key;
  3297. assetType = inv.Value.Type;
  3298. objName = inv.Value.Name;
  3299. break;
  3300. }
  3301. }
  3302. }
  3303. if (!found)
  3304. {
  3305. llSay(0, String.Format("Could not find object '{0}'", inventory));
  3306. throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
  3307. }
  3308. // check if destination is an avatar
  3309. if (World.GetScenePresence(destId) != null)
  3310. {
  3311. // destination is an avatar
  3312. InventoryItemBase agentItem =
  3313. World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
  3314. if (agentItem == null)
  3315. return;
  3316. byte[] bucket = new byte[17];
  3317. bucket[0] = (byte)assetType;
  3318. byte[] objBytes = objId.GetBytes();
  3319. Array.Copy(objBytes, 0, bucket, 1, 16);
  3320. Console.WriteLine("Giving inventory");
  3321. GridInstantMessage msg = new GridInstantMessage(World,
  3322. m_host.UUID, m_host.Name+", an object owned by "+
  3323. resolveName(m_host.OwnerID)+",", destId,
  3324. (byte)InstantMessageDialog.InventoryOffered,
  3325. false, objName+"\n"+m_host.Name+" is located at "+
  3326. World.RegionInfo.RegionName+" "+
  3327. m_host.AbsolutePosition.ToString(),
  3328. agentItem.ID, true, m_host.AbsolutePosition,
  3329. bucket);
  3330. if (m_TransferModule != null)
  3331. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3332. }
  3333. else
  3334. {
  3335. // destination is an object
  3336. World.MoveTaskInventoryItem(destId, m_host, objId);
  3337. }
  3338. ScriptSleep(3000);
  3339. }
  3340. public void llRemoveInventory(string name)
  3341. {
  3342. m_host.AddScriptLPS(1);
  3343. lock (m_host.TaskInventory)
  3344. {
  3345. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  3346. {
  3347. if (item.Name == name)
  3348. {
  3349. if (item.ItemID == m_itemID)
  3350. throw new ScriptDeleteException();
  3351. else
  3352. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  3353. return;
  3354. }
  3355. }
  3356. }
  3357. }
  3358. public void llSetText(string text, LSL_Vector color, double alpha)
  3359. {
  3360. m_host.AddScriptLPS(1);
  3361. Vector3 av3 = new Vector3(Util.Clip((float)color.x, 0.0f, 1.0f),
  3362. Util.Clip((float)color.y, 0.0f, 1.0f),
  3363. Util.Clip((float)color.z, 0.0f, 1.0f));
  3364. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  3365. m_host.ParentGroup.HasGroupChanged = true;
  3366. m_host.ParentGroup.ScheduleGroupForFullUpdate();
  3367. }
  3368. public LSL_Float llWater(LSL_Vector offset)
  3369. {
  3370. m_host.AddScriptLPS(1);
  3371. return World.RegionInfo.RegionSettings.WaterHeight;
  3372. }
  3373. public void llPassTouches(int pass)
  3374. {
  3375. m_host.AddScriptLPS(1);
  3376. if (pass != 0)
  3377. m_host.PassTouches = true;
  3378. else
  3379. m_host.PassTouches = false;
  3380. }
  3381. public LSL_String llRequestAgentData(string id, int data)
  3382. {
  3383. m_host.AddScriptLPS(1);
  3384. UUID uuid = (UUID)id;
  3385. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  3386. PresenceInfo pinfo = null;
  3387. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3388. if (pinfos != null && pinfos.Length > 0)
  3389. pinfo = pinfos[0];
  3390. if (pinfo == null)
  3391. return UUID.Zero.ToString();
  3392. string reply = String.Empty;
  3393. switch (data)
  3394. {
  3395. case 1: // DATA_ONLINE (0|1)
  3396. // TODO: implement fetching of this information
  3397. if (pinfo != null)
  3398. reply = "1";
  3399. else
  3400. reply = "0";
  3401. break;
  3402. case 2: // DATA_NAME (First Last)
  3403. reply = account.FirstName + " " + account.LastName;
  3404. break;
  3405. case 3: // DATA_BORN (YYYY-MM-DD)
  3406. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3407. born = born.AddSeconds(account.Created);
  3408. reply = born.ToString("yyyy-MM-dd");
  3409. break;
  3410. case 4: // DATA_RATING (0,0,0,0,0,0)
  3411. reply = "0,0,0,0,0,0";
  3412. break;
  3413. case 8: // DATA_PAYINFO (0|1|2|3)
  3414. reply = "0";
  3415. break;
  3416. default:
  3417. return UUID.Zero.ToString(); // Raise no event
  3418. }
  3419. UUID rq = UUID.Random();
  3420. UUID tid = AsyncCommands.
  3421. DataserverPlugin.RegisterRequest(m_localID,
  3422. m_itemID, rq.ToString());
  3423. AsyncCommands.
  3424. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  3425. ScriptSleep(100);
  3426. return tid.ToString();
  3427. }
  3428. public LSL_String llRequestInventoryData(string name)
  3429. {
  3430. m_host.AddScriptLPS(1);
  3431. TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  3432. foreach (TaskInventoryItem item in itemDictionary.Values)
  3433. {
  3434. if (item.Type == 3 && item.Name == name)
  3435. {
  3436. UUID tid = AsyncCommands.
  3437. DataserverPlugin.RegisterRequest(m_localID,
  3438. m_itemID, item.AssetID.ToString());
  3439. Vector3 region = new Vector3(
  3440. World.RegionInfo.RegionLocX * Constants.RegionSize,
  3441. World.RegionInfo.RegionLocY * Constants.RegionSize,
  3442. 0);
  3443. World.AssetService.Get(item.AssetID.ToString(), this,
  3444. delegate(string i, object sender, AssetBase a)
  3445. {
  3446. AssetLandmark lm = new AssetLandmark(a);
  3447. float rx = (uint)(lm.RegionHandle >> 32);
  3448. float ry = (uint)lm.RegionHandle;
  3449. region = lm.Position + new Vector3(rx, ry, 0) - region;
  3450. string reply = region.ToString();
  3451. AsyncCommands.
  3452. DataserverPlugin.DataserverReply(i.ToString(),
  3453. reply);
  3454. });
  3455. ScriptSleep(1000);
  3456. return tid.ToString();
  3457. }
  3458. }
  3459. ScriptSleep(1000);
  3460. return String.Empty;
  3461. }
  3462. public void llSetDamage(double damage)
  3463. {
  3464. m_host.AddScriptLPS(1);
  3465. m_host.ParentGroup.Damage = (float)damage;
  3466. }
  3467. public void llTeleportAgentHome(string agent)
  3468. {
  3469. m_host.AddScriptLPS(1);
  3470. UUID agentId = new UUID();
  3471. if (UUID.TryParse(agent, out agentId))
  3472. {
  3473. ScenePresence presence = World.GetScenePresence(agentId);
  3474. if (presence != null)
  3475. {
  3476. // agent must be over the owners land
  3477. if (m_host.OwnerID == World.LandChannel.GetLandObject(
  3478. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  3479. {
  3480. presence.ControllingClient.SendTeleportLocationStart();
  3481. World.TeleportClientHome(agentId, presence.ControllingClient);
  3482. }
  3483. }
  3484. }
  3485. ScriptSleep(5000);
  3486. }
  3487. public void llTextBox(string agent, string message, int chatChannel)
  3488. {
  3489. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  3490. if (dm == null)
  3491. return;
  3492. m_host.AddScriptLPS(1);
  3493. UUID av = new UUID();
  3494. if (!UUID.TryParse(agent,out av))
  3495. {
  3496. LSLError("First parameter to llDialog needs to be a key");
  3497. return;
  3498. }
  3499. if (message == string.Empty)
  3500. {
  3501. ShoutError("Trying to use llTextBox with empty message.");
  3502. }
  3503. else if (message.Length > 512)
  3504. {
  3505. ShoutError("Trying to use llTextBox with message over 512 characters.");
  3506. }
  3507. else
  3508. {
  3509. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  3510. ScriptSleep(1000);
  3511. }
  3512. }
  3513. public void llModifyLand(int action, int brush)
  3514. {
  3515. m_host.AddScriptLPS(1);
  3516. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  3517. if (tm != null)
  3518. {
  3519. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action, m_host.OwnerID);
  3520. }
  3521. }
  3522. public void llCollisionSound(string impact_sound, double impact_volume)
  3523. {
  3524. m_host.AddScriptLPS(1);
  3525. // TODO: Parameter check logic required.
  3526. UUID soundId = UUID.Zero;
  3527. if (!UUID.TryParse(impact_sound, out soundId))
  3528. {
  3529. lock (m_host.TaskInventory)
  3530. {
  3531. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  3532. {
  3533. if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
  3534. {
  3535. soundId = item.AssetID;
  3536. break;
  3537. }
  3538. }
  3539. }
  3540. }
  3541. m_host.CollisionSound = soundId;
  3542. m_host.CollisionSoundVolume = (float)impact_volume;
  3543. }
  3544. public void llCollisionSprite(string impact_sprite)
  3545. {
  3546. m_host.AddScriptLPS(1);
  3547. NotImplemented("llCollisionSprite");
  3548. }
  3549. public LSL_String llGetAnimation(string id)
  3550. {
  3551. // This should only return a value if the avatar is in the same region
  3552. m_host.AddScriptLPS(1);
  3553. UUID avatar = (UUID)id;
  3554. ScenePresence presence = World.GetScenePresence(avatar);
  3555. if (presence == null)
  3556. return "";
  3557. if (m_host.RegionHandle == presence.RegionHandle)
  3558. {
  3559. Dictionary<UUID, string> animationstateNames = AnimationSet.Animations.AnimStateNames;
  3560. if (presence != null)
  3561. {
  3562. AnimationSet currentAnims = presence.Animator.Animations;
  3563. string currentAnimationState = String.Empty;
  3564. if (animationstateNames.TryGetValue(currentAnims.DefaultAnimation.AnimID, out currentAnimationState))
  3565. return currentAnimationState;
  3566. }
  3567. }
  3568. return String.Empty;
  3569. }
  3570. public void llMessageLinked(int linknumber, int num, string msg, string id)
  3571. {
  3572. m_host.AddScriptLPS(1);
  3573. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3574. UUID partItemID;
  3575. foreach (SceneObjectPart part in parts)
  3576. {
  3577. TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
  3578. foreach (TaskInventoryItem item in itemsDictionary.Values)
  3579. {
  3580. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  3581. {
  3582. partItemID = item.ItemID;
  3583. int linkNumber = m_host.LinkNum;
  3584. if (m_host.ParentGroup.Children.Count == 1)
  3585. linkNumber = 0;
  3586. object[] resobj = new object[]
  3587. {
  3588. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  3589. };
  3590. m_ScriptEngine.PostScriptEvent(partItemID,
  3591. new EventParams("link_message",
  3592. resobj, new DetectParams[0]));
  3593. }
  3594. }
  3595. }
  3596. }
  3597. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  3598. {
  3599. m_host.AddScriptLPS(1);
  3600. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  3601. bool pushAllowed = false;
  3602. bool pusheeIsAvatar = false;
  3603. UUID targetID = UUID.Zero;
  3604. if (!UUID.TryParse(target,out targetID))
  3605. return;
  3606. ScenePresence pusheeav = null;
  3607. Vector3 PusheePos = Vector3.Zero;
  3608. SceneObjectPart pusheeob = null;
  3609. ScenePresence avatar = World.GetScenePresence(targetID);
  3610. if (avatar != null)
  3611. {
  3612. pusheeIsAvatar = true;
  3613. // Pushee doesn't have a physics actor
  3614. if (avatar.PhysicsActor == null)
  3615. return;
  3616. // Pushee is in GodMode this pushing object isn't owned by them
  3617. if (avatar.GodLevel > 0 && m_host.OwnerID != targetID)
  3618. return;
  3619. pusheeav = avatar;
  3620. // Find pushee position
  3621. // Pushee Linked?
  3622. if (pusheeav.ParentID != 0)
  3623. {
  3624. SceneObjectPart parentobj = World.GetSceneObjectPart(pusheeav.ParentID);
  3625. if (parentobj != null)
  3626. {
  3627. PusheePos = parentobj.AbsolutePosition;
  3628. }
  3629. else
  3630. {
  3631. PusheePos = pusheeav.AbsolutePosition;
  3632. }
  3633. }
  3634. else
  3635. {
  3636. PusheePos = pusheeav.AbsolutePosition;
  3637. }
  3638. }
  3639. if (!pusheeIsAvatar)
  3640. {
  3641. // not an avatar so push is not affected by parcel flags
  3642. pusheeob = World.GetSceneObjectPart((UUID)target);
  3643. // We can't find object
  3644. if (pusheeob == null)
  3645. return;
  3646. // Object not pushable. Not an attachment and has no physics component
  3647. if (!pusheeob.IsAttachment && pusheeob.PhysActor == null)
  3648. return;
  3649. PusheePos = pusheeob.AbsolutePosition;
  3650. pushAllowed = true;
  3651. }
  3652. else
  3653. {
  3654. if (pushrestricted)
  3655. {
  3656. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos.X, PusheePos.Y);
  3657. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  3658. if (targetlandObj == null)
  3659. return;
  3660. // Need provisions for Group Owned here
  3661. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  3662. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  3663. {
  3664. pushAllowed = true;
  3665. }
  3666. }
  3667. else
  3668. {
  3669. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos.X, PusheePos.Y);
  3670. if (targetlandObj == null)
  3671. {
  3672. // We didn't find the parcel but region isn't push restricted so assume it's ok
  3673. pushAllowed = true;
  3674. }
  3675. else
  3676. {
  3677. // Parcel push restriction
  3678. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  3679. {
  3680. // Need provisions for Group Owned here
  3681. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  3682. targetlandObj.LandData.IsGroupOwned ||
  3683. m_host.OwnerID == targetID)
  3684. {
  3685. pushAllowed = true;
  3686. }
  3687. //ParcelFlags.RestrictPushObject
  3688. //pushAllowed = true;
  3689. }
  3690. else
  3691. {
  3692. // Parcel isn't push restricted
  3693. pushAllowed = true;
  3694. }
  3695. }
  3696. }
  3697. }
  3698. if (pushAllowed)
  3699. {
  3700. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  3701. float distance_term = distance * distance * distance; // Script Energy
  3702. float pusher_mass = m_host.GetMass();
  3703. float PUSH_ATTENUATION_DISTANCE = 17f;
  3704. float PUSH_ATTENUATION_SCALE = 5f;
  3705. float distance_attenuation = 1f;
  3706. if (distance > PUSH_ATTENUATION_DISTANCE)
  3707. {
  3708. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  3709. distance_attenuation = 1f / normalized_units;
  3710. }
  3711. Vector3 applied_linear_impulse = new Vector3((float)impulse.x, (float)impulse.y, (float)impulse.z);
  3712. {
  3713. float impulse_length = applied_linear_impulse.Length();
  3714. float desired_energy = impulse_length * pusher_mass;
  3715. if (desired_energy > 0f)
  3716. desired_energy += distance_term;
  3717. float scaling_factor = 1f;
  3718. scaling_factor *= distance_attenuation;
  3719. applied_linear_impulse *= scaling_factor;
  3720. }
  3721. if (pusheeIsAvatar)
  3722. {
  3723. if (pusheeav != null)
  3724. {
  3725. if (pusheeav.PhysicsActor != null)
  3726. {
  3727. if (local != 0)
  3728. {
  3729. applied_linear_impulse *= m_host.GetWorldRotation();
  3730. }
  3731. pusheeav.PhysicsActor.AddForce(applied_linear_impulse, true);
  3732. }
  3733. }
  3734. }
  3735. else
  3736. {
  3737. if (pusheeob != null)
  3738. {
  3739. if (pusheeob.PhysActor != null)
  3740. {
  3741. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  3742. }
  3743. }
  3744. }
  3745. }
  3746. }
  3747. public void llPassCollisions(int pass)
  3748. {
  3749. m_host.AddScriptLPS(1);
  3750. if (pass == 0)
  3751. {
  3752. m_host.ParentGroup.PassCollision = false;
  3753. }
  3754. else
  3755. {
  3756. m_host.ParentGroup.PassCollision = true;
  3757. }
  3758. }
  3759. public LSL_String llGetScriptName()
  3760. {
  3761. string result = String.Empty;
  3762. m_host.AddScriptLPS(1);
  3763. lock (m_host.TaskInventory)
  3764. {
  3765. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  3766. {
  3767. if (item.Type == 10 && item.ItemID == m_itemID)
  3768. {
  3769. result = item.Name != null ? item.Name : String.Empty;
  3770. break;
  3771. }
  3772. }
  3773. }
  3774. return result;
  3775. }
  3776. public LSL_Integer llGetNumberOfSides()
  3777. {
  3778. m_host.AddScriptLPS(1);
  3779. return GetNumberOfSides(m_host);
  3780. }
  3781. protected int GetNumberOfSides(SceneObjectPart part)
  3782. {
  3783. int sides = part.GetNumberOfSides();
  3784. if (part.GetPrimType() == PrimType.SPHERE && part.Shape.ProfileHollow > 0)
  3785. {
  3786. // Make up for a bug where LSL shows 4 sides rather than 2
  3787. sides += 2;
  3788. }
  3789. return sides;
  3790. }
  3791. /* The new / changed functions were tested with the following LSL script:
  3792. default
  3793. {
  3794. state_entry()
  3795. {
  3796. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  3797. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  3798. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  3799. // convert back and forth between quaternion <-> vector and angle
  3800. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  3801. llOwnerSay("Old rotation was: "+(string) rot);
  3802. llOwnerSay("re-converted rotation is: "+(string) newrot);
  3803. llSetRot(rot); // to check the parameters in the prim
  3804. }
  3805. }
  3806. */
  3807. // Xantor 29/apr/2008
  3808. // Returns rotation described by rotating angle radians about axis.
  3809. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  3810. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  3811. {
  3812. m_host.AddScriptLPS(1);
  3813. double x, y, z, s, t;
  3814. s = Math.Cos(angle * 0.5);
  3815. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  3816. x = axis.x * t;
  3817. y = axis.y * t;
  3818. z = axis.z * t;
  3819. return new LSL_Rotation(x,y,z,s);
  3820. }
  3821. // Xantor 29/apr/2008
  3822. // converts a Quaternion to X,Y,Z axis rotations
  3823. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  3824. {
  3825. m_host.AddScriptLPS(1);
  3826. double x,y,z;
  3827. if (rot.s > 1) // normalization needed
  3828. {
  3829. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  3830. rot.z * rot.z + rot.s * rot.s);
  3831. rot.x /= length;
  3832. rot.y /= length;
  3833. rot.z /= length;
  3834. rot.s /= length;
  3835. }
  3836. // double angle = 2 * Math.Acos(rot.s);
  3837. double s = Math.Sqrt(1 - rot.s * rot.s);
  3838. if (s < 0.001)
  3839. {
  3840. x = 1;
  3841. y = z = 0;
  3842. }
  3843. else
  3844. {
  3845. x = rot.x / s; // normalise axis
  3846. y = rot.y / s;
  3847. z = rot.z / s;
  3848. }
  3849. return new LSL_Vector(x,y,z);
  3850. }
  3851. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  3852. public LSL_Float llRot2Angle(LSL_Rotation rot)
  3853. {
  3854. m_host.AddScriptLPS(1);
  3855. if (rot.s > 1) // normalization needed
  3856. {
  3857. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  3858. rot.z * rot.z + rot.s * rot.s);
  3859. rot.x /= length;
  3860. rot.y /= length;
  3861. rot.z /= length;
  3862. rot.s /= length;
  3863. }
  3864. double angle = 2 * Math.Acos(rot.s);
  3865. return angle;
  3866. }
  3867. public LSL_Float llAcos(double val)
  3868. {
  3869. m_host.AddScriptLPS(1);
  3870. return (double)Math.Acos(val);
  3871. }
  3872. public LSL_Float llAsin(double val)
  3873. {
  3874. m_host.AddScriptLPS(1);
  3875. return (double)Math.Asin(val);
  3876. }
  3877. // Xantor 30/apr/2008
  3878. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  3879. {
  3880. m_host.AddScriptLPS(1);
  3881. double angle = Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2;
  3882. if (angle < 0) angle = -angle;
  3883. if (angle > Math.PI) return (Math.PI * 2 - angle);
  3884. return angle;
  3885. }
  3886. public LSL_String llGetInventoryKey(string name)
  3887. {
  3888. m_host.AddScriptLPS(1);
  3889. lock (m_host.TaskInventory)
  3890. {
  3891. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3892. {
  3893. if (inv.Value.Name == name)
  3894. {
  3895. if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  3896. {
  3897. return inv.Value.AssetID.ToString();
  3898. }
  3899. else
  3900. {
  3901. return UUID.Zero.ToString();
  3902. }
  3903. }
  3904. }
  3905. }
  3906. return UUID.Zero.ToString();
  3907. }
  3908. public void llAllowInventoryDrop(int add)
  3909. {
  3910. m_host.AddScriptLPS(1);
  3911. if (add != 0)
  3912. m_host.ParentGroup.RootPart.AllowedDrop = true;
  3913. else
  3914. m_host.ParentGroup.RootPart.AllowedDrop = false;
  3915. // Update the object flags
  3916. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  3917. }
  3918. public LSL_Vector llGetSunDirection()
  3919. {
  3920. m_host.AddScriptLPS(1);
  3921. LSL_Vector SunDoubleVector3;
  3922. Vector3 SunFloatVector3;
  3923. // sunPosition estate setting is set in OpenSim.Region.CoreModules.SunModule
  3924. // have to convert from Vector3 (float) to LSL_Vector (double)
  3925. SunFloatVector3 = World.RegionInfo.RegionSettings.SunVector;
  3926. SunDoubleVector3.x = (double)SunFloatVector3.X;
  3927. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  3928. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  3929. return SunDoubleVector3;
  3930. }
  3931. public LSL_Vector llGetTextureOffset(int face)
  3932. {
  3933. m_host.AddScriptLPS(1);
  3934. return GetTextureOffset(m_host, face);
  3935. }
  3936. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  3937. {
  3938. Primitive.TextureEntry tex = part.Shape.Textures;
  3939. LSL_Vector offset = new LSL_Vector();
  3940. if (face == ScriptBaseClass.ALL_SIDES)
  3941. {
  3942. face = 0;
  3943. }
  3944. if (face >= 0 && face < GetNumberOfSides(part))
  3945. {
  3946. offset.x = tex.GetFace((uint)face).OffsetU;
  3947. offset.y = tex.GetFace((uint)face).OffsetV;
  3948. offset.z = 0.0;
  3949. return offset;
  3950. }
  3951. else
  3952. {
  3953. return offset;
  3954. }
  3955. }
  3956. public LSL_Vector llGetTextureScale(int side)
  3957. {
  3958. m_host.AddScriptLPS(1);
  3959. Primitive.TextureEntry tex = m_host.Shape.Textures;
  3960. LSL_Vector scale;
  3961. if (side == -1)
  3962. {
  3963. side = 0;
  3964. }
  3965. scale.x = tex.GetFace((uint)side).RepeatU;
  3966. scale.y = tex.GetFace((uint)side).RepeatV;
  3967. scale.z = 0.0;
  3968. return scale;
  3969. }
  3970. public LSL_Float llGetTextureRot(int face)
  3971. {
  3972. m_host.AddScriptLPS(1);
  3973. return GetTextureRot(m_host, face);
  3974. }
  3975. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  3976. {
  3977. Primitive.TextureEntry tex = part.Shape.Textures;
  3978. if (face == -1)
  3979. {
  3980. face = 0;
  3981. }
  3982. if (face >= 0 && face < GetNumberOfSides(part))
  3983. {
  3984. return tex.GetFace((uint)face).Rotation;
  3985. }
  3986. else
  3987. {
  3988. return 0.0;
  3989. }
  3990. }
  3991. public LSL_Integer llSubStringIndex(string source, string pattern)
  3992. {
  3993. m_host.AddScriptLPS(1);
  3994. return source.IndexOf(pattern);
  3995. }
  3996. public LSL_String llGetOwnerKey(string id)
  3997. {
  3998. m_host.AddScriptLPS(1);
  3999. UUID key = new UUID();
  4000. if (UUID.TryParse(id, out key))
  4001. {
  4002. try
  4003. {
  4004. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4005. if (obj == null)
  4006. return id; // the key is for an agent so just return the key
  4007. else
  4008. return obj.OwnerID.ToString();
  4009. }
  4010. catch (KeyNotFoundException)
  4011. {
  4012. return id; // The Object/Agent not in the region so just return the key
  4013. }
  4014. }
  4015. else
  4016. {
  4017. return UUID.Zero.ToString();
  4018. }
  4019. }
  4020. public LSL_Vector llGetCenterOfMass()
  4021. {
  4022. m_host.AddScriptLPS(1);
  4023. Vector3 center = m_host.GetGeometricCenter();
  4024. return new LSL_Vector(center.X,center.Y,center.Z);
  4025. }
  4026. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4027. {
  4028. m_host.AddScriptLPS(1);
  4029. if (stride <= 0)
  4030. {
  4031. stride = 1;
  4032. }
  4033. return src.Sort(stride, ascending);
  4034. }
  4035. public LSL_Integer llGetListLength(LSL_List src)
  4036. {
  4037. m_host.AddScriptLPS(1);
  4038. if (src == null)
  4039. {
  4040. return 0;
  4041. }
  4042. else
  4043. {
  4044. return src.Length;
  4045. }
  4046. }
  4047. public LSL_Integer llList2Integer(LSL_List src, int index)
  4048. {
  4049. m_host.AddScriptLPS(1);
  4050. if (index < 0)
  4051. {
  4052. index = src.Length + index;
  4053. }
  4054. if (index >= src.Length || index < 0)
  4055. {
  4056. return 0;
  4057. }
  4058. try
  4059. {
  4060. if (src.Data[index] is LSL_Integer)
  4061. return (LSL_Integer) src.Data[index];
  4062. else if (src.Data[index] is LSL_Float)
  4063. return Convert.ToInt32(((LSL_Float) src.Data[index]).value);
  4064. return new LSL_Integer(src.Data[index].ToString());
  4065. }
  4066. catch (FormatException)
  4067. {
  4068. return 0;
  4069. }
  4070. }
  4071. public LSL_Float llList2Float(LSL_List src, int index)
  4072. {
  4073. m_host.AddScriptLPS(1);
  4074. if (index < 0)
  4075. {
  4076. index = src.Length + index;
  4077. }
  4078. if (index >= src.Length || index < 0)
  4079. {
  4080. return 0.0;
  4081. }
  4082. try
  4083. {
  4084. if (src.Data[index] is LSL_Integer)
  4085. return Convert.ToDouble(((LSL_Integer) src.Data[index]).value);
  4086. else if (src.Data[index] is LSL_Float)
  4087. return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
  4088. else if (src.Data[index] is LSL_String)
  4089. return Convert.ToDouble(((LSL_String) src.Data[index]).m_string);
  4090. return Convert.ToDouble(src.Data[index]);
  4091. }
  4092. catch (FormatException)
  4093. {
  4094. return 0.0;
  4095. }
  4096. }
  4097. public LSL_String llList2String(LSL_List src, int index)
  4098. {
  4099. m_host.AddScriptLPS(1);
  4100. if (index < 0)
  4101. {
  4102. index = src.Length + index;
  4103. }
  4104. if (index >= src.Length || index < 0)
  4105. {
  4106. return String.Empty;
  4107. }
  4108. return src.Data[index].ToString();
  4109. }
  4110. public LSL_String llList2Key(LSL_List src, int index)
  4111. {
  4112. m_host.AddScriptLPS(1);
  4113. if (index < 0)
  4114. {
  4115. index = src.Length + index;
  4116. }
  4117. if (index >= src.Length || index < 0)
  4118. {
  4119. return "";
  4120. }
  4121. return src.Data[index].ToString();
  4122. }
  4123. public LSL_Vector llList2Vector(LSL_List src, int index)
  4124. {
  4125. m_host.AddScriptLPS(1);
  4126. if (index < 0)
  4127. {
  4128. index = src.Length + index;
  4129. }
  4130. if (index >= src.Length || index < 0)
  4131. {
  4132. return new LSL_Vector(0, 0, 0);
  4133. }
  4134. if (src.Data[index].GetType() == typeof(LSL_Vector))
  4135. {
  4136. return (LSL_Vector)src.Data[index];
  4137. }
  4138. else
  4139. {
  4140. return new LSL_Vector(src.Data[index].ToString());
  4141. }
  4142. }
  4143. public LSL_Rotation llList2Rot(LSL_List src, int index)
  4144. {
  4145. m_host.AddScriptLPS(1);
  4146. if (index < 0)
  4147. {
  4148. index = src.Length + index;
  4149. }
  4150. if (index >= src.Length || index < 0)
  4151. {
  4152. return new LSL_Rotation(0, 0, 0, 1);
  4153. }
  4154. if (src.Data[index].GetType() == typeof(LSL_Rotation))
  4155. {
  4156. return (LSL_Rotation)src.Data[index];
  4157. }
  4158. else
  4159. {
  4160. return new LSL_Rotation(src.Data[index].ToString());
  4161. }
  4162. }
  4163. public LSL_List llList2List(LSL_List src, int start, int end)
  4164. {
  4165. m_host.AddScriptLPS(1);
  4166. return src.GetSublist(start, end);
  4167. }
  4168. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  4169. {
  4170. return src.DeleteSublist(start, end);
  4171. }
  4172. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  4173. {
  4174. m_host.AddScriptLPS(1);
  4175. if (index < 0)
  4176. {
  4177. index = src.Length + index;
  4178. }
  4179. if (index >= src.Length)
  4180. {
  4181. return 0;
  4182. }
  4183. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  4184. return 1;
  4185. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  4186. return 2;
  4187. if (src.Data[index] is LSL_String || src.Data[index] is String)
  4188. {
  4189. UUID tuuid;
  4190. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  4191. {
  4192. return 4;
  4193. }
  4194. else
  4195. {
  4196. return 3;
  4197. }
  4198. }
  4199. if (src.Data[index] is LSL_Vector)
  4200. return 5;
  4201. if (src.Data[index] is LSL_Rotation)
  4202. return 6;
  4203. if (src.Data[index] is LSL_List)
  4204. return 7;
  4205. return 0;
  4206. }
  4207. /// <summary>
  4208. /// Process the supplied list and return the
  4209. /// content of the list formatted as a comma
  4210. /// separated list. There is a space after
  4211. /// each comma.
  4212. /// </summary>
  4213. public LSL_String llList2CSV(LSL_List src)
  4214. {
  4215. string ret = String.Empty;
  4216. int x = 0;
  4217. m_host.AddScriptLPS(1);
  4218. if (src.Data.Length > 0)
  4219. {
  4220. ret = src.Data[x++].ToString();
  4221. for (; x < src.Data.Length; x++)
  4222. {
  4223. ret += ", "+src.Data[x].ToString();
  4224. }
  4225. }
  4226. return ret;
  4227. }
  4228. /// <summary>
  4229. /// The supplied string is scanned for commas
  4230. /// and converted into a list. Commas are only
  4231. /// effective if they are encountered outside
  4232. /// of '<' '>' delimiters. Any whitespace
  4233. /// before or after an element is trimmed.
  4234. /// </summary>
  4235. public LSL_List llCSV2List(string src)
  4236. {
  4237. LSL_List result = new LSL_List();
  4238. int parens = 0;
  4239. int start = 0;
  4240. int length = 0;
  4241. m_host.AddScriptLPS(1);
  4242. for (int i = 0; i < src.Length; i++)
  4243. {
  4244. switch (src[i])
  4245. {
  4246. case '<':
  4247. parens++;
  4248. length++;
  4249. break;
  4250. case '>':
  4251. if (parens > 0)
  4252. parens--;
  4253. length++;
  4254. break;
  4255. case ',':
  4256. if (parens == 0)
  4257. {
  4258. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4259. start += length+1;
  4260. length = 0;
  4261. }
  4262. else
  4263. {
  4264. length++;
  4265. }
  4266. break;
  4267. default:
  4268. length++;
  4269. break;
  4270. }
  4271. }
  4272. result.Add(src.Substring(start,length).Trim());
  4273. return result;
  4274. }
  4275. /// <summary>
  4276. /// Randomizes the list, be arbitrarily reordering
  4277. /// sublists of stride elements. As the stride approaches
  4278. /// the size of the list, the options become very
  4279. /// limited.
  4280. /// </summary>
  4281. /// <remarks>
  4282. /// This could take a while for very large list
  4283. /// sizes.
  4284. /// </remarks>
  4285. public LSL_List llListRandomize(LSL_List src, int stride)
  4286. {
  4287. LSL_List result;
  4288. Random rand = new Random();
  4289. int chunkk;
  4290. int[] chunks;
  4291. m_host.AddScriptLPS(1);
  4292. if (stride <= 0)
  4293. {
  4294. stride = 1;
  4295. }
  4296. // Stride MUST be a factor of the list length
  4297. // If not, then return the src list. This also
  4298. // traps those cases where stride > length.
  4299. if (src.Length != stride && src.Length%stride == 0)
  4300. {
  4301. chunkk = src.Length/stride;
  4302. chunks = new int[chunkk];
  4303. for (int i = 0; i < chunkk; i++)
  4304. chunks[i] = i;
  4305. // Knuth shuffle the chunkk index
  4306. for (int i = chunkk - 1; i >= 1; i--)
  4307. {
  4308. // Elect an unrandomized chunk to swap
  4309. int index = rand.Next(i + 1);
  4310. int tmp;
  4311. // and swap position with first unrandomized chunk
  4312. tmp = chunks[i];
  4313. chunks[i] = chunks[index];
  4314. chunks[index] = tmp;
  4315. }
  4316. // Construct the randomized list
  4317. result = new LSL_List();
  4318. for (int i = 0; i < chunkk; i++)
  4319. {
  4320. for (int j = 0; j < stride; j++)
  4321. {
  4322. result.Add(src.Data[chunks[i]*stride+j]);
  4323. }
  4324. }
  4325. }
  4326. else {
  4327. object[] array = new object[src.Length];
  4328. Array.Copy(src.Data, 0, array, 0, src.Length);
  4329. result = new LSL_List(array);
  4330. }
  4331. return result;
  4332. }
  4333. /// <summary>
  4334. /// Elements in the source list starting with 0 and then
  4335. /// every i+stride. If the stride is negative then the scan
  4336. /// is backwards producing an inverted result.
  4337. /// Only those elements that are also in the specified
  4338. /// range are included in the result.
  4339. /// </summary>
  4340. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  4341. {
  4342. LSL_List result = new LSL_List();
  4343. int[] si = new int[2];
  4344. int[] ei = new int[2];
  4345. bool twopass = false;
  4346. m_host.AddScriptLPS(1);
  4347. // First step is always to deal with negative indices
  4348. if (start < 0)
  4349. start = src.Length+start;
  4350. if (end < 0)
  4351. end = src.Length+end;
  4352. // Out of bounds indices are OK, just trim them
  4353. // accordingly
  4354. if (start > src.Length)
  4355. start = src.Length;
  4356. if (end > src.Length)
  4357. end = src.Length;
  4358. if (stride == 0)
  4359. stride = 1;
  4360. // There may be one or two ranges to be considered
  4361. if (start != end)
  4362. {
  4363. if (start <= end)
  4364. {
  4365. si[0] = start;
  4366. ei[0] = end;
  4367. }
  4368. else
  4369. {
  4370. si[1] = start;
  4371. ei[1] = src.Length;
  4372. si[0] = 0;
  4373. ei[0] = end;
  4374. twopass = true;
  4375. }
  4376. // The scan always starts from the beginning of the
  4377. // source list, but members are only selected if they
  4378. // fall within the specified sub-range. The specified
  4379. // range values are inclusive.
  4380. // A negative stride reverses the direction of the
  4381. // scan producing an inverted list as a result.
  4382. if (stride > 0)
  4383. {
  4384. for (int i = 0; i < src.Length; i += stride)
  4385. {
  4386. if (i<=ei[0] && i>=si[0])
  4387. result.Add(src.Data[i]);
  4388. if (twopass && i>=si[1] && i<=ei[1])
  4389. result.Add(src.Data[i]);
  4390. }
  4391. }
  4392. else if (stride < 0)
  4393. {
  4394. for (int i = src.Length - 1; i >= 0; i += stride)
  4395. {
  4396. if (i <= ei[0] && i >= si[0])
  4397. result.Add(src.Data[i]);
  4398. if (twopass && i >= si[1] && i <= ei[1])
  4399. result.Add(src.Data[i]);
  4400. }
  4401. }
  4402. }
  4403. else
  4404. {
  4405. if (start%stride == 0)
  4406. {
  4407. result.Add(src.Data[start]);
  4408. }
  4409. }
  4410. return result;
  4411. }
  4412. public LSL_Integer llGetRegionAgentCount()
  4413. {
  4414. m_host.AddScriptLPS(1);
  4415. return new LSL_Integer(World.GetRootAgentCount());
  4416. }
  4417. public LSL_Vector llGetRegionCorner()
  4418. {
  4419. m_host.AddScriptLPS(1);
  4420. return new LSL_Vector(World.RegionInfo.RegionLocX * Constants.RegionSize, World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
  4421. }
  4422. /// <summary>
  4423. /// Insert the list identified by <src> into the
  4424. /// list designated by <dest> such that the first
  4425. /// new element has the index specified by <index>
  4426. /// </summary>
  4427. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  4428. {
  4429. LSL_List pref = null;
  4430. LSL_List suff = null;
  4431. m_host.AddScriptLPS(1);
  4432. if (index < 0)
  4433. {
  4434. index = index+dest.Length;
  4435. if (index < 0)
  4436. {
  4437. index = 0;
  4438. }
  4439. }
  4440. if (index != 0)
  4441. {
  4442. pref = dest.GetSublist(0,index-1);
  4443. if (index < dest.Length)
  4444. {
  4445. suff = dest.GetSublist(index,-1);
  4446. return pref + src + suff;
  4447. }
  4448. else
  4449. {
  4450. return pref + src;
  4451. }
  4452. }
  4453. else
  4454. {
  4455. if (index < dest.Length)
  4456. {
  4457. suff = dest.GetSublist(index,-1);
  4458. return src + suff;
  4459. }
  4460. else
  4461. {
  4462. return src;
  4463. }
  4464. }
  4465. }
  4466. /// <summary>
  4467. /// Returns the index of the first occurrence of test
  4468. /// in src.
  4469. /// </summary>
  4470. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  4471. {
  4472. int index = -1;
  4473. int length = src.Length - test.Length + 1;
  4474. m_host.AddScriptLPS(1);
  4475. // If either list is empty, do not match
  4476. if (src.Length != 0 && test.Length != 0)
  4477. {
  4478. for (int i = 0; i < length; i++)
  4479. {
  4480. if (src.Data[i].Equals(test.Data[0]))
  4481. {
  4482. int j;
  4483. for (j = 1; j < test.Length; j++)
  4484. if (!src.Data[i+j].Equals(test.Data[j]))
  4485. break;
  4486. if (j == test.Length)
  4487. {
  4488. index = i;
  4489. break;
  4490. }
  4491. }
  4492. }
  4493. }
  4494. return index;
  4495. }
  4496. public LSL_String llGetObjectName()
  4497. {
  4498. m_host.AddScriptLPS(1);
  4499. return m_host.Name!=null?m_host.Name:String.Empty;
  4500. }
  4501. public void llSetObjectName(string name)
  4502. {
  4503. m_host.AddScriptLPS(1);
  4504. m_host.Name = name!=null?name:String.Empty;
  4505. }
  4506. public LSL_String llGetDate()
  4507. {
  4508. m_host.AddScriptLPS(1);
  4509. DateTime date = DateTime.Now.ToUniversalTime();
  4510. string result = date.ToString("yyyy-MM-dd");
  4511. return result;
  4512. }
  4513. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  4514. {
  4515. m_host.AddScriptLPS(1);
  4516. // edge will be used to pass the Region Coordinates offset
  4517. // we want to check for a neighboring sim
  4518. LSL_Vector edge = new LSL_Vector(0, 0, 0);
  4519. if (dir.x == 0)
  4520. {
  4521. if (dir.y == 0)
  4522. {
  4523. // Direction vector is 0,0 so return
  4524. // false since we're staying in the sim
  4525. return 0;
  4526. }
  4527. else
  4528. {
  4529. // Y is the only valid direction
  4530. edge.y = dir.y / Math.Abs(dir.y);
  4531. }
  4532. }
  4533. else
  4534. {
  4535. LSL_Float mag;
  4536. if (dir.x > 0)
  4537. {
  4538. mag = (Constants.RegionSize - pos.x) / dir.x;
  4539. }
  4540. else
  4541. {
  4542. mag = (pos.x/dir.x);
  4543. }
  4544. mag = Math.Abs(mag);
  4545. edge.y = pos.y + (dir.y * mag);
  4546. if (edge.y > Constants.RegionSize || edge.y < 0)
  4547. {
  4548. // Y goes out of bounds first
  4549. edge.y = dir.y / Math.Abs(dir.y);
  4550. }
  4551. else
  4552. {
  4553. // X goes out of bounds first or its a corner exit
  4554. edge.y = 0;
  4555. edge.x = dir.x / Math.Abs(dir.x);
  4556. }
  4557. }
  4558. List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID);
  4559. uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x;
  4560. uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y;
  4561. foreach (GridRegion sri in neighbors)
  4562. {
  4563. if (sri.RegionLocX == neighborX && sri.RegionLocY == neighborY)
  4564. return 0;
  4565. }
  4566. return 1;
  4567. }
  4568. /// <summary>
  4569. /// Not fully implemented yet. Still to do:-
  4570. /// AGENT_BUSY
  4571. /// Remove as they are done
  4572. /// </summary>
  4573. public LSL_Integer llGetAgentInfo(string id)
  4574. {
  4575. m_host.AddScriptLPS(1);
  4576. UUID key = new UUID();
  4577. if (!UUID.TryParse(id, out key))
  4578. {
  4579. return 0;
  4580. }
  4581. int flags = 0;
  4582. ScenePresence agent = World.GetScenePresence(key);
  4583. if (agent == null)
  4584. {
  4585. return 0;
  4586. }
  4587. if (agent.IsChildAgent)
  4588. return 0; // Fail if they are not in the same region
  4589. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  4590. if (agent.SetAlwaysRun)
  4591. {
  4592. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  4593. }
  4594. if (agent.HasAttachments())
  4595. {
  4596. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  4597. if (agent.HasScriptedAttachments())
  4598. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  4599. }
  4600. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  4601. {
  4602. flags |= ScriptBaseClass.AGENT_FLYING;
  4603. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  4604. }
  4605. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  4606. {
  4607. flags |= ScriptBaseClass.AGENT_AWAY;
  4608. }
  4609. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  4610. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  4611. {
  4612. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  4613. }
  4614. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  4615. {
  4616. flags |= ScriptBaseClass.AGENT_TYPING;
  4617. }
  4618. string agentMovementAnimation = agent.Animator.GetMovementAnimation();
  4619. if (agentMovementAnimation == "CROUCH")
  4620. {
  4621. flags |= ScriptBaseClass.AGENT_CROUCHING;
  4622. }
  4623. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  4624. {
  4625. flags |= ScriptBaseClass.AGENT_WALKING;
  4626. }
  4627. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  4628. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  4629. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  4630. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  4631. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  4632. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 &&
  4633. agent.PhysicsActor != null &&
  4634. !agent.PhysicsActor.IsColliding)
  4635. {
  4636. flags |= ScriptBaseClass.AGENT_IN_AIR;
  4637. }
  4638. if (agent.ParentID != 0)
  4639. {
  4640. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  4641. flags |= ScriptBaseClass.AGENT_SITTING;
  4642. }
  4643. if (agent.Animator.Animations.DefaultAnimation.AnimID
  4644. == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  4645. {
  4646. flags |= ScriptBaseClass.AGENT_SITTING;
  4647. }
  4648. return flags;
  4649. }
  4650. public LSL_String llGetAgentLanguage(string id)
  4651. {
  4652. // This should only return a value if the avatar is in the same region
  4653. //ckrinke 1-30-09 : This needs to parse the XMLRPC language field supplied
  4654. //by the client at login. Currently returning only en-us until our I18N
  4655. //effort gains momentum
  4656. m_host.AddScriptLPS(1);
  4657. return "en-us";
  4658. }
  4659. public void llAdjustSoundVolume(double volume)
  4660. {
  4661. m_host.AddScriptLPS(1);
  4662. m_host.AdjustSoundGain(volume);
  4663. ScriptSleep(100);
  4664. }
  4665. public void llSetSoundQueueing(int queue)
  4666. {
  4667. m_host.AddScriptLPS(1);
  4668. NotImplemented("llSetSoundQueueing");
  4669. }
  4670. public void llSetSoundRadius(double radius)
  4671. {
  4672. m_host.AddScriptLPS(1);
  4673. m_host.SoundRadius = radius;
  4674. }
  4675. public LSL_String llKey2Name(string id)
  4676. {
  4677. m_host.AddScriptLPS(1);
  4678. UUID key = new UUID();
  4679. if (UUID.TryParse(id,out key))
  4680. {
  4681. ScenePresence presence = World.GetScenePresence(key);
  4682. if (presence != null)
  4683. {
  4684. return presence.ControllingClient.Name;
  4685. //return presence.Name;
  4686. }
  4687. if (World.GetSceneObjectPart(key) != null)
  4688. {
  4689. return World.GetSceneObjectPart(key).Name;
  4690. }
  4691. }
  4692. return String.Empty;
  4693. }
  4694. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  4695. {
  4696. m_host.AddScriptLPS(1);
  4697. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  4698. }
  4699. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  4700. {
  4701. m_host.AddScriptLPS(1);
  4702. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4703. foreach (var part in parts)
  4704. {
  4705. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  4706. }
  4707. }
  4708. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  4709. {
  4710. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  4711. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  4712. //ALL_SIDES
  4713. if (face == ScriptBaseClass.ALL_SIDES)
  4714. face = 255;
  4715. pTexAnim.Face = (uint)face;
  4716. pTexAnim.Length = (float)length;
  4717. pTexAnim.Rate = (float)rate;
  4718. pTexAnim.SizeX = (uint)sizex;
  4719. pTexAnim.SizeY = (uint)sizey;
  4720. pTexAnim.Start = (float)start;
  4721. part.AddTextureAnimation(pTexAnim);
  4722. part.SendFullUpdateToAllClients();
  4723. part.ParentGroup.HasGroupChanged = true;
  4724. }
  4725. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  4726. LSL_Vector bottom_south_west)
  4727. {
  4728. m_host.AddScriptLPS(1);
  4729. float radius1 = (float)llVecDist(llGetPos(), top_north_east);
  4730. float radius2 = (float)llVecDist(llGetPos(), bottom_south_west);
  4731. float radius = Math.Abs(radius1 - radius2);
  4732. m_host.SendSound(KeyOrName(sound).ToString(), volume, true, 0, radius, false, false);
  4733. }
  4734. public void llEjectFromLand(string pest)
  4735. {
  4736. m_host.AddScriptLPS(1);
  4737. UUID agentId = new UUID();
  4738. if (UUID.TryParse(pest, out agentId))
  4739. {
  4740. ScenePresence presence = World.GetScenePresence(agentId);
  4741. if (presence != null)
  4742. {
  4743. // agent must be over the owners land
  4744. if (m_host.OwnerID == World.LandChannel.GetLandObject(
  4745. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  4746. World.TeleportClientHome(agentId, presence.ControllingClient);
  4747. }
  4748. }
  4749. ScriptSleep(5000);
  4750. }
  4751. public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
  4752. {
  4753. m_host.AddScriptLPS(1);
  4754. LSL_List ret = new LSL_List();
  4755. LSL_List spacers = new LSL_List();
  4756. if (in_spacers.Length > 0 && separators.Length > 0)
  4757. {
  4758. for (int i = 0; i < in_spacers.Length; i++)
  4759. {
  4760. object s = in_spacers.Data[i];
  4761. for (int j = 0; j < separators.Length; j++)
  4762. {
  4763. if (separators.Data[j].ToString() == s.ToString())
  4764. {
  4765. s = null;
  4766. break;
  4767. }
  4768. }
  4769. if (s != null)
  4770. {
  4771. spacers.Add(s);
  4772. }
  4773. }
  4774. }
  4775. object[] delimiters = new object[separators.Length + spacers.Length];
  4776. separators.Data.CopyTo(delimiters, 0);
  4777. spacers.Data.CopyTo(delimiters, separators.Length);
  4778. bool dfound = false;
  4779. do
  4780. {
  4781. dfound = false;
  4782. int cindex = -1;
  4783. string cdeli = "";
  4784. for (int i = 0; i < delimiters.Length; i++)
  4785. {
  4786. int index = str.IndexOf(delimiters[i].ToString());
  4787. bool found = index != -1;
  4788. if (found && String.Empty != delimiters[i].ToString())
  4789. {
  4790. if ((cindex > index) || (cindex == -1))
  4791. {
  4792. cindex = index;
  4793. cdeli = delimiters[i].ToString();
  4794. }
  4795. dfound = dfound || found;
  4796. }
  4797. }
  4798. if (cindex != -1)
  4799. {
  4800. if (cindex > 0)
  4801. {
  4802. ret.Add(new LSL_String(str.Substring(0, cindex)));
  4803. }
  4804. // Cannot use spacers.Contains() because spacers may be either type String or LSLString
  4805. for (int j = 0; j < spacers.Length; j++)
  4806. {
  4807. if (spacers.Data[j].ToString() == cdeli)
  4808. {
  4809. ret.Add(new LSL_String(cdeli));
  4810. break;
  4811. }
  4812. }
  4813. str = str.Substring(cindex + cdeli.Length);
  4814. }
  4815. } while (dfound);
  4816. if (str != "")
  4817. {
  4818. ret.Add(new LSL_String(str));
  4819. }
  4820. return ret;
  4821. }
  4822. public LSL_Integer llOverMyLand(string id)
  4823. {
  4824. m_host.AddScriptLPS(1);
  4825. UUID key = new UUID();
  4826. if (UUID.TryParse(id, out key))
  4827. {
  4828. ScenePresence presence = World.GetScenePresence(key);
  4829. if (presence != null) // object is an avatar
  4830. {
  4831. if (m_host.OwnerID
  4832. == World.LandChannel.GetLandObject(
  4833. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  4834. return 1;
  4835. }
  4836. else // object is not an avatar
  4837. {
  4838. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4839. if (obj != null)
  4840. if (m_host.OwnerID
  4841. == World.LandChannel.GetLandObject(
  4842. obj.AbsolutePosition.X, obj.AbsolutePosition.Y).LandData.OwnerID)
  4843. return 1;
  4844. }
  4845. }
  4846. return 0;
  4847. }
  4848. public LSL_String llGetLandOwnerAt(LSL_Vector pos)
  4849. {
  4850. m_host.AddScriptLPS(1);
  4851. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  4852. if (land == null)
  4853. return UUID.Zero.ToString();
  4854. return land.LandData.OwnerID.ToString();
  4855. }
  4856. /// <summary>
  4857. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  4858. /// only the height of avatars vary and that says:
  4859. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  4860. /// </summary>
  4861. public LSL_Vector llGetAgentSize(string id)
  4862. {
  4863. m_host.AddScriptLPS(1);
  4864. ScenePresence avatar = World.GetScenePresence((UUID)id);
  4865. LSL_Vector agentSize;
  4866. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  4867. {
  4868. agentSize = ScriptBaseClass.ZERO_VECTOR;
  4869. }
  4870. else
  4871. {
  4872. agentSize = new LSL_Vector(0.45, 0.6, avatar.Appearance.AvatarHeight);
  4873. }
  4874. return agentSize;
  4875. }
  4876. public LSL_Integer llSameGroup(string agent)
  4877. {
  4878. m_host.AddScriptLPS(1);
  4879. UUID agentId = new UUID();
  4880. if (!UUID.TryParse(agent, out agentId))
  4881. return new LSL_Integer(0);
  4882. ScenePresence presence = World.GetScenePresence(agentId);
  4883. if (presence == null || presence.IsChildAgent) // Return flase for child agents
  4884. return new LSL_Integer(0);
  4885. IClientAPI client = presence.ControllingClient;
  4886. if (m_host.GroupID == client.ActiveGroupId)
  4887. return new LSL_Integer(1);
  4888. else
  4889. return new LSL_Integer(0);
  4890. }
  4891. public void llUnSit(string id)
  4892. {
  4893. m_host.AddScriptLPS(1);
  4894. UUID key = new UUID();
  4895. if (UUID.TryParse(id, out key))
  4896. {
  4897. ScenePresence av = World.GetScenePresence(key);
  4898. if (av != null)
  4899. {
  4900. if (llAvatarOnSitTarget() == id)
  4901. {
  4902. // if the avatar is sitting on this object, then
  4903. // we can unsit them. We don't want random scripts unsitting random people
  4904. // Lets avoid the popcorn avatar scenario.
  4905. av.StandUp();
  4906. }
  4907. else
  4908. {
  4909. // If the object owner also owns the parcel
  4910. // or
  4911. // if the land is group owned and the object is group owned by the same group
  4912. // or
  4913. // if the object is owned by a person with estate access.
  4914. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition.X, av.AbsolutePosition.Y);
  4915. if (parcel != null)
  4916. {
  4917. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  4918. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  4919. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  4920. {
  4921. av.StandUp();
  4922. }
  4923. }
  4924. }
  4925. }
  4926. }
  4927. }
  4928. public LSL_Vector llGroundSlope(LSL_Vector offset)
  4929. {
  4930. m_host.AddScriptLPS(1);
  4931. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  4932. LSL_Vector vsn = llGroundNormal(offset);
  4933. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  4934. //the height of that point on the plane. The resulting vector gives the slope.
  4935. Vector3 vsl = new Vector3();
  4936. vsl.X = (float)vsn.x;
  4937. vsl.Y = (float)vsn.y;
  4938. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  4939. vsl.Normalize();
  4940. //Normalization might be overkill here
  4941. return new LSL_Vector(vsl.X, vsl.Y, vsl.Z);
  4942. }
  4943. public LSL_Vector llGroundNormal(LSL_Vector offset)
  4944. {
  4945. m_host.AddScriptLPS(1);
  4946. Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x,
  4947. (float)offset.y,
  4948. (float)offset.z);
  4949. // Clamp to valid position
  4950. if (pos.X < 0)
  4951. pos.X = 0;
  4952. else if (pos.X >= World.Heightmap.Width)
  4953. pos.X = World.Heightmap.Width - 1;
  4954. if (pos.Y < 0)
  4955. pos.Y = 0;
  4956. else if (pos.Y >= World.Heightmap.Height)
  4957. pos.Y = World.Heightmap.Height - 1;
  4958. //Find two points in addition to the position to define a plane
  4959. Vector3 p0 = new Vector3(pos.X, pos.Y,
  4960. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  4961. Vector3 p1 = new Vector3();
  4962. Vector3 p2 = new Vector3();
  4963. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  4964. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  4965. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  4966. else
  4967. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  4968. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  4969. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  4970. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  4971. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  4972. else
  4973. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  4974. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  4975. //Find normalized vectors from p0 to p1 and p0 to p2
  4976. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  4977. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  4978. v0.Normalize();
  4979. v1.Normalize();
  4980. //Find the cross product of the vectors (the slope normal).
  4981. Vector3 vsn = new Vector3();
  4982. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  4983. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  4984. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  4985. vsn.Normalize();
  4986. //I believe the crossproduct of two normalized vectors is a normalized vector so
  4987. //this normalization may be overkill
  4988. return new LSL_Vector(vsn.X, vsn.Y, vsn.Z);
  4989. }
  4990. public LSL_Vector llGroundContour(LSL_Vector offset)
  4991. {
  4992. m_host.AddScriptLPS(1);
  4993. LSL_Vector x = llGroundSlope(offset);
  4994. return new LSL_Vector(-x.y, x.x, 0.0);
  4995. }
  4996. public LSL_Integer llGetAttached()
  4997. {
  4998. m_host.AddScriptLPS(1);
  4999. return m_host.ParentGroup.RootPart.AttachmentPoint;
  5000. }
  5001. public LSL_Integer llGetFreeMemory()
  5002. {
  5003. m_host.AddScriptLPS(1);
  5004. // Make scripts designed for LSO happy
  5005. return 16384;
  5006. }
  5007. public LSL_Integer llGetFreeURLs()
  5008. {
  5009. m_host.AddScriptLPS(1);
  5010. if (m_UrlModule != null)
  5011. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  5012. return new LSL_Integer(0);
  5013. }
  5014. public LSL_String llGetRegionName()
  5015. {
  5016. m_host.AddScriptLPS(1);
  5017. return World.RegionInfo.RegionName;
  5018. }
  5019. public LSL_Float llGetRegionTimeDilation()
  5020. {
  5021. m_host.AddScriptLPS(1);
  5022. return (double)World.TimeDilation;
  5023. }
  5024. /// <summary>
  5025. /// Returns the value reported in the client Statistics window
  5026. /// </summary>
  5027. public LSL_Float llGetRegionFPS()
  5028. {
  5029. m_host.AddScriptLPS(1);
  5030. return World.SimulatorFPS;
  5031. }
  5032. /* particle system rules should be coming into this routine as doubles, that is
  5033. rule[0] should be an integer from this list and rule[1] should be the arg
  5034. for the same integer. wiki.secondlife.com has most of this mapping, but some
  5035. came from http://www.caligari-designs.com/p4u2
  5036. We iterate through the list for 'Count' elements, incrementing by two for each
  5037. iteration and set the members of Primitive.ParticleSystem, one at a time.
  5038. */
  5039. public enum PrimitiveRule : int
  5040. {
  5041. PSYS_PART_FLAGS = 0,
  5042. PSYS_PART_START_COLOR = 1,
  5043. PSYS_PART_START_ALPHA = 2,
  5044. PSYS_PART_END_COLOR = 3,
  5045. PSYS_PART_END_ALPHA = 4,
  5046. PSYS_PART_START_SCALE = 5,
  5047. PSYS_PART_END_SCALE = 6,
  5048. PSYS_PART_MAX_AGE = 7,
  5049. PSYS_SRC_ACCEL = 8,
  5050. PSYS_SRC_PATTERN = 9,
  5051. PSYS_SRC_INNERANGLE = 10,
  5052. PSYS_SRC_OUTERANGLE = 11,
  5053. PSYS_SRC_TEXTURE = 12,
  5054. PSYS_SRC_BURST_RATE = 13,
  5055. PSYS_SRC_BURST_PART_COUNT = 15,
  5056. PSYS_SRC_BURST_RADIUS = 16,
  5057. PSYS_SRC_BURST_SPEED_MIN = 17,
  5058. PSYS_SRC_BURST_SPEED_MAX = 18,
  5059. PSYS_SRC_MAX_AGE = 19,
  5060. PSYS_SRC_TARGET_KEY = 20,
  5061. PSYS_SRC_OMEGA = 21,
  5062. PSYS_SRC_ANGLE_BEGIN = 22,
  5063. PSYS_SRC_ANGLE_END = 23
  5064. }
  5065. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  5066. {
  5067. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  5068. return returnval;
  5069. }
  5070. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  5071. {
  5072. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  5073. // TODO find out about the other defaults and add them here
  5074. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5075. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5076. ps.PartStartScaleX = 1.0f;
  5077. ps.PartStartScaleY = 1.0f;
  5078. ps.PartEndScaleX = 1.0f;
  5079. ps.PartEndScaleY = 1.0f;
  5080. ps.BurstSpeedMin = 1.0f;
  5081. ps.BurstSpeedMax = 1.0f;
  5082. ps.BurstRate = 0.1f;
  5083. ps.PartMaxAge = 10.0f;
  5084. return ps;
  5085. }
  5086. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  5087. {
  5088. m_host.AddScriptLPS(1);
  5089. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5090. foreach (var part in parts)
  5091. {
  5092. SetParticleSystem(part, rules);
  5093. }
  5094. }
  5095. public void llParticleSystem(LSL_List rules)
  5096. {
  5097. m_host.AddScriptLPS(1);
  5098. SetParticleSystem(m_host, rules);
  5099. }
  5100. private void SetParticleSystem(SceneObjectPart part, LSL_List rules) {
  5101. if (rules.Length == 0)
  5102. {
  5103. part.RemoveParticleSystem();
  5104. part.ParentGroup.HasGroupChanged = true;
  5105. }
  5106. else
  5107. {
  5108. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  5109. LSL_Vector tempv = new LSL_Vector();
  5110. float tempf = 0;
  5111. for (int i = 0; i < rules.Length; i += 2)
  5112. {
  5113. switch (rules.GetLSLIntegerItem(i))
  5114. {
  5115. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  5116. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  5117. break;
  5118. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  5119. tempv = rules.GetVector3Item(i + 1);
  5120. prules.PartStartColor.R = (float)tempv.x;
  5121. prules.PartStartColor.G = (float)tempv.y;
  5122. prules.PartStartColor.B = (float)tempv.z;
  5123. break;
  5124. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  5125. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5126. prules.PartStartColor.A = tempf;
  5127. break;
  5128. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  5129. tempv = rules.GetVector3Item(i + 1);
  5130. prules.PartEndColor.R = (float)tempv.x;
  5131. prules.PartEndColor.G = (float)tempv.y;
  5132. prules.PartEndColor.B = (float)tempv.z;
  5133. break;
  5134. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  5135. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5136. prules.PartEndColor.A = tempf;
  5137. break;
  5138. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  5139. tempv = rules.GetVector3Item(i + 1);
  5140. prules.PartStartScaleX = (float)tempv.x;
  5141. prules.PartStartScaleY = (float)tempv.y;
  5142. break;
  5143. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  5144. tempv = rules.GetVector3Item(i + 1);
  5145. prules.PartEndScaleX = (float)tempv.x;
  5146. prules.PartEndScaleY = (float)tempv.y;
  5147. break;
  5148. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  5149. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5150. prules.PartMaxAge = tempf;
  5151. break;
  5152. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  5153. tempv = rules.GetVector3Item(i + 1);
  5154. prules.PartAcceleration.X = (float)tempv.x;
  5155. prules.PartAcceleration.Y = (float)tempv.y;
  5156. prules.PartAcceleration.Z = (float)tempv.z;
  5157. break;
  5158. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  5159. int tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5160. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  5161. break;
  5162. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  5163. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  5164. // client tells the difference between the two by looking at the 0x02 bit in
  5165. // the PartFlags variable.
  5166. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  5167. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5168. prules.InnerAngle = (float)tempf;
  5169. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5170. break;
  5171. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  5172. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5173. prules.OuterAngle = (float)tempf;
  5174. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5175. break;
  5176. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  5177. prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1));
  5178. break;
  5179. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  5180. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5181. prules.BurstRate = (float)tempf;
  5182. break;
  5183. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  5184. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  5185. break;
  5186. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  5187. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5188. prules.BurstRadius = (float)tempf;
  5189. break;
  5190. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  5191. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5192. prules.BurstSpeedMin = (float)tempf;
  5193. break;
  5194. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  5195. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5196. prules.BurstSpeedMax = (float)tempf;
  5197. break;
  5198. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  5199. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5200. prules.MaxAge = (float)tempf;
  5201. break;
  5202. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  5203. UUID key = UUID.Zero;
  5204. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  5205. {
  5206. prules.Target = key;
  5207. }
  5208. else
  5209. {
  5210. prules.Target = part.UUID;
  5211. }
  5212. break;
  5213. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  5214. // AL: This is an assumption, since it is the only thing that would match.
  5215. tempv = rules.GetVector3Item(i + 1);
  5216. prules.AngularVelocity.X = (float)tempv.x;
  5217. prules.AngularVelocity.Y = (float)tempv.y;
  5218. prules.AngularVelocity.Z = (float)tempv.z;
  5219. break;
  5220. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  5221. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5222. prules.InnerAngle = (float)tempf;
  5223. prules.PartFlags |= 0x02; // Set new angle format.
  5224. break;
  5225. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  5226. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5227. prules.OuterAngle = (float)tempf;
  5228. prules.PartFlags |= 0x02; // Set new angle format.
  5229. break;
  5230. }
  5231. }
  5232. prules.CRC = 1;
  5233. part.AddNewParticleSystem(prules);
  5234. part.ParentGroup.HasGroupChanged = true;
  5235. }
  5236. part.SendFullUpdateToAllClients();
  5237. }
  5238. public void llGroundRepel(double height, int water, double tau)
  5239. {
  5240. m_host.AddScriptLPS(1);
  5241. if (m_host.PhysActor != null)
  5242. {
  5243. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  5244. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  5245. PIDHoverType hoverType = PIDHoverType.Ground;
  5246. if (water != 0)
  5247. {
  5248. hoverType = PIDHoverType.GroundAndWater;
  5249. if (ground < waterLevel)
  5250. height += waterLevel;
  5251. else
  5252. height += ground;
  5253. }
  5254. else
  5255. {
  5256. height += ground;
  5257. }
  5258. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  5259. }
  5260. }
  5261. protected UUID GetTaskInventoryItem(string name)
  5262. {
  5263. lock (m_host.TaskInventory)
  5264. {
  5265. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  5266. {
  5267. if (inv.Value.Name == name)
  5268. return inv.Key;
  5269. }
  5270. }
  5271. return UUID.Zero;
  5272. }
  5273. public void llGiveInventoryList(string destination, string category, LSL_List inventory)
  5274. {
  5275. m_host.AddScriptLPS(1);
  5276. UUID destID;
  5277. if (!UUID.TryParse(destination, out destID))
  5278. return;
  5279. List<UUID> itemList = new List<UUID>();
  5280. foreach (Object item in inventory.Data)
  5281. {
  5282. UUID itemID;
  5283. if (UUID.TryParse(item.ToString(), out itemID))
  5284. {
  5285. itemList.Add(itemID);
  5286. }
  5287. else
  5288. {
  5289. itemID = GetTaskInventoryItem(item.ToString());
  5290. if (itemID != UUID.Zero)
  5291. itemList.Add(itemID);
  5292. }
  5293. }
  5294. if (itemList.Count == 0)
  5295. return;
  5296. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  5297. if (folderID == UUID.Zero)
  5298. return;
  5299. byte[] bucket = new byte[17];
  5300. bucket[0] = (byte)AssetType.Folder;
  5301. byte[] objBytes = folderID.GetBytes();
  5302. Array.Copy(objBytes, 0, bucket, 1, 16);
  5303. GridInstantMessage msg = new GridInstantMessage(World,
  5304. m_host.UUID, m_host.Name+", an object owned by "+
  5305. resolveName(m_host.OwnerID)+",", destID,
  5306. (byte)InstantMessageDialog.InventoryOffered,
  5307. false, category+"\n"+m_host.Name+" is located at "+
  5308. World.RegionInfo.RegionName+" "+
  5309. m_host.AbsolutePosition.ToString(),
  5310. folderID, true, m_host.AbsolutePosition,
  5311. bucket);
  5312. if (m_TransferModule != null)
  5313. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  5314. }
  5315. public void llSetVehicleType(int type)
  5316. {
  5317. m_host.AddScriptLPS(1);
  5318. if (m_host.ParentGroup != null)
  5319. {
  5320. if (!m_host.ParentGroup.IsDeleted)
  5321. {
  5322. m_host.ParentGroup.RootPart.SetVehicleType(type);
  5323. }
  5324. }
  5325. }
  5326. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5327. //CFK 9/28: so these are not complete yet.
  5328. public void llSetVehicleFloatParam(int param, LSL_Float value)
  5329. {
  5330. m_host.AddScriptLPS(1);
  5331. if (m_host.ParentGroup != null)
  5332. {
  5333. if (!m_host.ParentGroup.IsDeleted)
  5334. {
  5335. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  5336. }
  5337. }
  5338. }
  5339. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5340. //CFK 9/28: so these are not complete yet.
  5341. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  5342. {
  5343. m_host.AddScriptLPS(1);
  5344. if (m_host.ParentGroup != null)
  5345. {
  5346. if (!m_host.ParentGroup.IsDeleted)
  5347. {
  5348. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param,
  5349. new Vector3((float)vec.x, (float)vec.y, (float)vec.z));
  5350. }
  5351. }
  5352. }
  5353. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5354. //CFK 9/28: so these are not complete yet.
  5355. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  5356. {
  5357. m_host.AddScriptLPS(1);
  5358. if (m_host.ParentGroup != null)
  5359. {
  5360. if (!m_host.ParentGroup.IsDeleted)
  5361. {
  5362. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param,
  5363. Rot2Quaternion(rot));
  5364. }
  5365. }
  5366. }
  5367. public void llSetVehicleFlags(int flags)
  5368. {
  5369. m_host.AddScriptLPS(1);
  5370. if (m_host.ParentGroup != null)
  5371. {
  5372. if (!m_host.ParentGroup.IsDeleted)
  5373. {
  5374. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  5375. }
  5376. }
  5377. }
  5378. public void llRemoveVehicleFlags(int flags)
  5379. {
  5380. m_host.AddScriptLPS(1);
  5381. if (m_host.ParentGroup != null)
  5382. {
  5383. if (!m_host.ParentGroup.IsDeleted)
  5384. {
  5385. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  5386. }
  5387. }
  5388. }
  5389. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  5390. {
  5391. m_host.AddScriptLPS(1);
  5392. // LSL quaternions can normalize to 0, normal Quaternions can't.
  5393. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  5394. rot.z = 1; // ZERO_ROTATION = 0,0,0,1
  5395. m_host.SitTargetPosition = new Vector3((float)offset.x, (float)offset.y, (float)offset.z);
  5396. m_host.SitTargetOrientation = Rot2Quaternion(rot);
  5397. m_host.ParentGroup.HasGroupChanged = true;
  5398. }
  5399. public LSL_String llAvatarOnSitTarget()
  5400. {
  5401. m_host.AddScriptLPS(1);
  5402. return m_host.GetAvatarOnSitTarget().ToString();
  5403. }
  5404. public void llAddToLandPassList(string avatar, double hours)
  5405. {
  5406. m_host.AddScriptLPS(1);
  5407. UUID key;
  5408. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  5409. if (land.OwnerID == m_host.OwnerID)
  5410. {
  5411. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  5412. if (UUID.TryParse(avatar, out key))
  5413. {
  5414. entry.AgentID = key;
  5415. entry.Flags = AccessList.Access;
  5416. entry.Time = DateTime.Now.AddHours(hours);
  5417. land.ParcelAccessList.Add(entry);
  5418. }
  5419. }
  5420. ScriptSleep(100);
  5421. }
  5422. public void llSetTouchText(string text)
  5423. {
  5424. m_host.AddScriptLPS(1);
  5425. m_host.TouchName = text;
  5426. }
  5427. public void llSetSitText(string text)
  5428. {
  5429. m_host.AddScriptLPS(1);
  5430. m_host.SitName = text;
  5431. }
  5432. public void llSetCameraEyeOffset(LSL_Vector offset)
  5433. {
  5434. m_host.AddScriptLPS(1);
  5435. m_host.SetCameraEyeOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z));
  5436. }
  5437. public void llSetCameraAtOffset(LSL_Vector offset)
  5438. {
  5439. m_host.AddScriptLPS(1);
  5440. m_host.SetCameraAtOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z));
  5441. }
  5442. public LSL_String llDumpList2String(LSL_List src, string seperator)
  5443. {
  5444. m_host.AddScriptLPS(1);
  5445. if (src.Length == 0)
  5446. {
  5447. return String.Empty;
  5448. }
  5449. string ret = String.Empty;
  5450. foreach (object o in src.Data)
  5451. {
  5452. ret = ret + o.ToString() + seperator;
  5453. }
  5454. ret = ret.Substring(0, ret.Length - seperator.Length);
  5455. return ret;
  5456. }
  5457. public LSL_Integer llScriptDanger(LSL_Vector pos)
  5458. {
  5459. m_host.AddScriptLPS(1);
  5460. bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
  5461. if (result)
  5462. {
  5463. return 1;
  5464. }
  5465. else
  5466. {
  5467. return 0;
  5468. }
  5469. }
  5470. public void llDialog(string avatar, string message, LSL_List buttons, int chat_channel)
  5471. {
  5472. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  5473. if (dm == null)
  5474. return;
  5475. m_host.AddScriptLPS(1);
  5476. UUID av = new UUID();
  5477. if (!UUID.TryParse(avatar,out av))
  5478. {
  5479. LSLError("First parameter to llDialog needs to be a key");
  5480. return;
  5481. }
  5482. if (buttons.Length < 1)
  5483. {
  5484. LSLError("No less than 1 button can be shown");
  5485. return;
  5486. }
  5487. if (buttons.Length > 12)
  5488. {
  5489. LSLError("No more than 12 buttons can be shown");
  5490. return;
  5491. }
  5492. string[] buts = new string[buttons.Length];
  5493. for (int i = 0; i < buttons.Length; i++)
  5494. {
  5495. if (buttons.Data[i].ToString() == String.Empty)
  5496. {
  5497. LSLError("button label cannot be blank");
  5498. return;
  5499. }
  5500. if (buttons.Data[i].ToString().Length > 24)
  5501. {
  5502. LSLError("button label cannot be longer than 24 characters");
  5503. return;
  5504. }
  5505. buts[i] = buttons.Data[i].ToString();
  5506. }
  5507. dm.SendDialogToUser(
  5508. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  5509. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  5510. ScriptSleep(1000);
  5511. }
  5512. public void llVolumeDetect(int detect)
  5513. {
  5514. m_host.AddScriptLPS(1);
  5515. if (m_host.ParentGroup != null)
  5516. {
  5517. if (!m_host.ParentGroup.IsDeleted)
  5518. {
  5519. m_host.ParentGroup.RootPart.ScriptSetVolumeDetect(detect!=0);
  5520. }
  5521. }
  5522. }
  5523. /// <summary>
  5524. /// This is a depecated function so this just replicates the result of
  5525. /// invoking it in SL
  5526. /// </summary>
  5527. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  5528. {
  5529. m_host.AddScriptLPS(1);
  5530. // Report an error as it does in SL
  5531. ShoutError("Deprecated. Please use llRemoteLoadScriptPin instead.");
  5532. ScriptSleep(3000);
  5533. }
  5534. public void llSetRemoteScriptAccessPin(int pin)
  5535. {
  5536. m_host.AddScriptLPS(1);
  5537. m_host.ScriptAccessPin = pin;
  5538. }
  5539. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  5540. {
  5541. m_host.AddScriptLPS(1);
  5542. bool found = false;
  5543. UUID destId = UUID.Zero;
  5544. UUID srcId = UUID.Zero;
  5545. if (!UUID.TryParse(target, out destId))
  5546. {
  5547. llSay(0, "Could not parse key " + target);
  5548. return;
  5549. }
  5550. // target must be a different prim than the one containing the script
  5551. if (m_host.UUID == destId)
  5552. {
  5553. return;
  5554. }
  5555. // copy the first script found with this inventory name
  5556. lock (m_host.TaskInventory)
  5557. {
  5558. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  5559. {
  5560. if (inv.Value.Name == name)
  5561. {
  5562. // make sure the object is a script
  5563. if (10 == inv.Value.Type)
  5564. {
  5565. found = true;
  5566. srcId = inv.Key;
  5567. break;
  5568. }
  5569. }
  5570. }
  5571. }
  5572. if (!found)
  5573. {
  5574. llSay(0, "Could not find script " + name);
  5575. return;
  5576. }
  5577. // the rest of the permission checks are done in RezScript, so check the pin there as well
  5578. World.RezScript(srcId, m_host, destId, pin, running, start_param);
  5579. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  5580. ScriptSleep(3000);
  5581. }
  5582. public void llOpenRemoteDataChannel()
  5583. {
  5584. m_host.AddScriptLPS(1);
  5585. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5586. if (xmlrpcMod.IsEnabled())
  5587. {
  5588. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero);
  5589. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  5590. if (xmlRpcRouter != null)
  5591. {
  5592. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  5593. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  5594. m_itemID, String.Format("http://{0}:{1}/", ExternalHostName,
  5595. xmlrpcMod.Port.ToString()));
  5596. }
  5597. object[] resobj = new object[]
  5598. {
  5599. new LSL_Integer(1),
  5600. new LSL_String(channelID.ToString()),
  5601. new LSL_String(UUID.Zero.ToString()),
  5602. new LSL_String(String.Empty),
  5603. new LSL_Integer(0),
  5604. new LSL_String(String.Empty)
  5605. };
  5606. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj,
  5607. new DetectParams[0]));
  5608. }
  5609. ScriptSleep(1000);
  5610. }
  5611. public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata)
  5612. {
  5613. m_host.AddScriptLPS(1);
  5614. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5615. ScriptSleep(3000);
  5616. return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString();
  5617. }
  5618. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  5619. {
  5620. m_host.AddScriptLPS(1);
  5621. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5622. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  5623. ScriptSleep(3000);
  5624. }
  5625. public void llCloseRemoteDataChannel(string channel)
  5626. {
  5627. m_host.AddScriptLPS(1);
  5628. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5629. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  5630. ScriptSleep(1000);
  5631. }
  5632. public LSL_String llMD5String(string src, int nonce)
  5633. {
  5634. m_host.AddScriptLPS(1);
  5635. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()));
  5636. }
  5637. public LSL_String llSHA1String(string src)
  5638. {
  5639. m_host.AddScriptLPS(1);
  5640. return Util.SHA1Hash(src).ToLower();
  5641. }
  5642. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
  5643. {
  5644. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  5645. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  5646. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  5647. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  5648. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  5649. {
  5650. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  5651. }
  5652. shapeBlock.ProfileCurve = (byte)holeshape;
  5653. if (cut.x < 0f)
  5654. {
  5655. cut.x = 0f;
  5656. }
  5657. if (cut.x > 1f)
  5658. {
  5659. cut.x = 1f;
  5660. }
  5661. if (cut.y < 0f)
  5662. {
  5663. cut.y = 0f;
  5664. }
  5665. if (cut.y > 1f)
  5666. {
  5667. cut.y = 1f;
  5668. }
  5669. if (cut.y - cut.x < 0.05f)
  5670. {
  5671. cut.x = cut.y - 0.05f;
  5672. if (cut.x < 0.0f)
  5673. {
  5674. cut.x = 0.0f;
  5675. cut.y = 0.05f;
  5676. }
  5677. }
  5678. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  5679. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  5680. if (hollow < 0f)
  5681. {
  5682. hollow = 0f;
  5683. }
  5684. if (hollow > 0.95)
  5685. {
  5686. hollow = 0.95f;
  5687. }
  5688. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  5689. if (twist.x < -1.0f)
  5690. {
  5691. twist.x = -1.0f;
  5692. }
  5693. if (twist.x > 1.0f)
  5694. {
  5695. twist.x = 1.0f;
  5696. }
  5697. if (twist.y < -1.0f)
  5698. {
  5699. twist.y = -1.0f;
  5700. }
  5701. if (twist.y > 1.0f)
  5702. {
  5703. twist.y = 1.0f;
  5704. }
  5705. shapeBlock.PathTwistBegin = (sbyte)(100 * twist.x);
  5706. shapeBlock.PathTwist = (sbyte)(100 * twist.y);
  5707. shapeBlock.ObjectLocalID = part.LocalId;
  5708. // retain pathcurve
  5709. shapeBlock.PathCurve = part.Shape.PathCurve;
  5710. part.Shape.SculptEntry = false;
  5711. return shapeBlock;
  5712. }
  5713. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge)
  5714. {
  5715. ObjectShapePacket.ObjectDataBlock shapeBlock;
  5716. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
  5717. shapeBlock.ProfileCurve += fudge;
  5718. if (taper_b.x < 0f)
  5719. {
  5720. taper_b.x = 0f;
  5721. }
  5722. if (taper_b.x > 2f)
  5723. {
  5724. taper_b.x = 2f;
  5725. }
  5726. if (taper_b.y < 0f)
  5727. {
  5728. taper_b.y = 0f;
  5729. }
  5730. if (taper_b.y > 2f)
  5731. {
  5732. taper_b.y = 2f;
  5733. }
  5734. shapeBlock.PathScaleX = (byte)(100 * (2.0 - taper_b.x));
  5735. shapeBlock.PathScaleY = (byte)(100 * (2.0 - taper_b.y));
  5736. if (topshear.x < -0.5f)
  5737. {
  5738. topshear.x = -0.5f;
  5739. }
  5740. if (topshear.x > 0.5f)
  5741. {
  5742. topshear.x = 0.5f;
  5743. }
  5744. if (topshear.y < -0.5f)
  5745. {
  5746. topshear.y = -0.5f;
  5747. }
  5748. if (topshear.y > 0.5f)
  5749. {
  5750. topshear.y = 0.5f;
  5751. }
  5752. shapeBlock.PathShearX = (byte)(100 * topshear.x);
  5753. shapeBlock.PathShearY = (byte)(100 * topshear.y);
  5754. part.Shape.SculptEntry = false;
  5755. part.UpdateShape(shapeBlock);
  5756. }
  5757. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
  5758. {
  5759. ObjectShapePacket.ObjectDataBlock shapeBlock;
  5760. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
  5761. // profile/path swapped for a sphere
  5762. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  5763. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  5764. shapeBlock.ProfileCurve += fudge;
  5765. shapeBlock.PathScaleX = 100;
  5766. shapeBlock.PathScaleY = 100;
  5767. if (dimple.x < 0f)
  5768. {
  5769. dimple.x = 0f;
  5770. }
  5771. if (dimple.x > 1f)
  5772. {
  5773. dimple.x = 1f;
  5774. }
  5775. if (dimple.y < 0f)
  5776. {
  5777. dimple.y = 0f;
  5778. }
  5779. if (dimple.y > 1f)
  5780. {
  5781. dimple.y = 1f;
  5782. }
  5783. if (dimple.y - cut.x < 0.05f)
  5784. {
  5785. dimple.x = cut.y - 0.05f;
  5786. }
  5787. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  5788. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  5789. part.Shape.SculptEntry = false;
  5790. part.UpdateShape(shapeBlock);
  5791. }
  5792. 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 fudge)
  5793. {
  5794. ObjectShapePacket.ObjectDataBlock shapeBlock;
  5795. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
  5796. shapeBlock.ProfileCurve += fudge;
  5797. // profile/path swapped for a torrus, tube, ring
  5798. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  5799. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  5800. if (holesize.x < 0.05f)
  5801. {
  5802. holesize.x = 0.05f;
  5803. }
  5804. if (holesize.x > 1f)
  5805. {
  5806. holesize.x = 1f;
  5807. }
  5808. if (holesize.y < 0.05f)
  5809. {
  5810. holesize.y = 0.05f;
  5811. }
  5812. if (holesize.y > 0.5f)
  5813. {
  5814. holesize.y = 0.5f;
  5815. }
  5816. shapeBlock.PathScaleX = (byte)(100 * (2 - holesize.x));
  5817. shapeBlock.PathScaleY = (byte)(100 * (2 - holesize.y));
  5818. if (topshear.x < -0.5f)
  5819. {
  5820. topshear.x = -0.5f;
  5821. }
  5822. if (topshear.x > 0.5f)
  5823. {
  5824. topshear.x = 0.5f;
  5825. }
  5826. if (topshear.y < -0.5f)
  5827. {
  5828. topshear.y = -0.5f;
  5829. }
  5830. if (topshear.y > 0.5f)
  5831. {
  5832. topshear.y = 0.5f;
  5833. }
  5834. shapeBlock.PathShearX = (byte)(100 * topshear.x);
  5835. shapeBlock.PathShearY = (byte)(100 * topshear.y);
  5836. if (profilecut.x < 0f)
  5837. {
  5838. profilecut.x = 0f;
  5839. }
  5840. if (profilecut.x > 1f)
  5841. {
  5842. profilecut.x = 1f;
  5843. }
  5844. if (profilecut.y < 0f)
  5845. {
  5846. profilecut.y = 0f;
  5847. }
  5848. if (profilecut.y > 1f)
  5849. {
  5850. profilecut.y = 1f;
  5851. }
  5852. if (profilecut.y - profilecut.x < 0.05f)
  5853. {
  5854. profilecut.x = profilecut.y - 0.05f;
  5855. if (profilecut.x < 0.0f)
  5856. {
  5857. profilecut.x = 0.0f;
  5858. profilecut.y = 0.05f;
  5859. }
  5860. }
  5861. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  5862. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  5863. if (taper_a.x < -1f)
  5864. {
  5865. taper_a.x = -1f;
  5866. }
  5867. if (taper_a.x > 1f)
  5868. {
  5869. taper_a.x = 1f;
  5870. }
  5871. if (taper_a.y < -1f)
  5872. {
  5873. taper_a.y = -1f;
  5874. }
  5875. if (taper_a.y > 1f)
  5876. {
  5877. taper_a.y = 1f;
  5878. }
  5879. shapeBlock.PathTaperX = (sbyte)(100 * taper_a.x);
  5880. shapeBlock.PathTaperY = (sbyte)(100 * taper_a.y);
  5881. if (revolutions < 1f)
  5882. {
  5883. revolutions = 1f;
  5884. }
  5885. if (revolutions > 4f)
  5886. {
  5887. revolutions = 4f;
  5888. }
  5889. shapeBlock.PathRevolutions = (byte)(66.666667 * (revolutions - 1.0));
  5890. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  5891. if (radiusoffset < 0f)
  5892. {
  5893. radiusoffset = 0f;
  5894. }
  5895. if (radiusoffset > 1f)
  5896. {
  5897. radiusoffset = 1f;
  5898. }
  5899. shapeBlock.PathRadiusOffset = (sbyte)(100 * radiusoffset);
  5900. if (skew < -0.95f)
  5901. {
  5902. skew = -0.95f;
  5903. }
  5904. if (skew > 0.95f)
  5905. {
  5906. skew = 0.95f;
  5907. }
  5908. shapeBlock.PathSkew = (sbyte)(100 * skew);
  5909. part.Shape.SculptEntry = false;
  5910. part.UpdateShape(shapeBlock);
  5911. }
  5912. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type)
  5913. {
  5914. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  5915. UUID sculptId;
  5916. if (!UUID.TryParse(map, out sculptId))
  5917. {
  5918. sculptId = InventoryKey(map, (int)AssetType.Texture);
  5919. }
  5920. if (sculptId == UUID.Zero)
  5921. return;
  5922. shapeBlock.ObjectLocalID = part.LocalId;
  5923. shapeBlock.PathScaleX = 100;
  5924. shapeBlock.PathScaleY = 150;
  5925. if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER &&
  5926. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE &&
  5927. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE &&
  5928. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS)
  5929. {
  5930. // default
  5931. type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  5932. }
  5933. // retain pathcurve
  5934. shapeBlock.PathCurve = part.Shape.PathCurve;
  5935. part.Shape.SetSculptData((byte)type, sculptId);
  5936. part.Shape.SculptEntry = true;
  5937. part.UpdateShape(shapeBlock);
  5938. }
  5939. public void llSetPrimitiveParams(LSL_List rules)
  5940. {
  5941. m_host.AddScriptLPS(1);
  5942. SetPrimParams(m_host, rules);
  5943. }
  5944. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  5945. {
  5946. m_host.AddScriptLPS(1);
  5947. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5948. foreach (SceneObjectPart part in parts)
  5949. SetPrimParams(part, rules);
  5950. }
  5951. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  5952. {
  5953. llSetLinkPrimitiveParams(linknumber, rules);
  5954. }
  5955. protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
  5956. {
  5957. int idx = 0;
  5958. while (idx < rules.Length)
  5959. {
  5960. int code = rules.GetLSLIntegerItem(idx++);
  5961. int remain = rules.Length - idx;
  5962. int face;
  5963. LSL_Vector v;
  5964. switch (code)
  5965. {
  5966. case (int)ScriptBaseClass.PRIM_POSITION:
  5967. if (remain < 1)
  5968. return;
  5969. v=rules.GetVector3Item(idx++);
  5970. SetPos(part, v);
  5971. break;
  5972. case (int)ScriptBaseClass.PRIM_SIZE:
  5973. if (remain < 1)
  5974. return;
  5975. v=rules.GetVector3Item(idx++);
  5976. SetScale(part, v);
  5977. break;
  5978. case (int)ScriptBaseClass.PRIM_ROTATION:
  5979. if (remain < 1)
  5980. return;
  5981. LSL_Rotation q = rules.GetQuaternionItem(idx++);
  5982. // try to let this work as in SL...
  5983. if (part.ParentID == 0)
  5984. {
  5985. // special case: If we are root, rotate complete SOG to new rotation
  5986. SetRot(part, Rot2Quaternion(q));
  5987. }
  5988. else
  5989. {
  5990. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  5991. SceneObjectGroup group = part.ParentGroup;
  5992. if (group != null) // a bit paranoid, maybe
  5993. {
  5994. SceneObjectPart rootPart = group.RootPart;
  5995. if (rootPart != null) // again, better safe than sorry
  5996. {
  5997. SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
  5998. }
  5999. }
  6000. }
  6001. break;
  6002. case (int)ScriptBaseClass.PRIM_TYPE:
  6003. if (remain < 3)
  6004. return;
  6005. code = (int)rules.GetLSLIntegerItem(idx++);
  6006. remain = rules.Length - idx;
  6007. float hollow;
  6008. LSL_Vector twist;
  6009. LSL_Vector taper_b;
  6010. LSL_Vector topshear;
  6011. float revolutions;
  6012. float radiusoffset;
  6013. float skew;
  6014. LSL_Vector holesize;
  6015. LSL_Vector profilecut;
  6016. switch (code)
  6017. {
  6018. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  6019. if (remain < 6)
  6020. return;
  6021. face = (int)rules.GetLSLIntegerItem(idx++);
  6022. v = rules.GetVector3Item(idx++); // cut
  6023. hollow = (float)rules.GetLSLFloatItem(idx++);
  6024. twist = rules.GetVector3Item(idx++);
  6025. taper_b = rules.GetVector3Item(idx++);
  6026. topshear = rules.GetVector3Item(idx++);
  6027. part.Shape.PathCurve = (byte)Extrusion.Straight;
  6028. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 1);
  6029. break;
  6030. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  6031. if (remain < 6)
  6032. return;
  6033. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6034. v = rules.GetVector3Item(idx++); // cut
  6035. hollow = (float)rules.GetLSLFloatItem(idx++);
  6036. twist = rules.GetVector3Item(idx++);
  6037. taper_b = rules.GetVector3Item(idx++);
  6038. topshear = rules.GetVector3Item(idx++);
  6039. part.Shape.ProfileShape = ProfileShape.Circle;
  6040. part.Shape.PathCurve = (byte)Extrusion.Straight;
  6041. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 0);
  6042. break;
  6043. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  6044. if (remain < 6)
  6045. return;
  6046. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6047. v = rules.GetVector3Item(idx++); //cut
  6048. hollow = (float)rules.GetLSLFloatItem(idx++);
  6049. twist = rules.GetVector3Item(idx++);
  6050. taper_b = rules.GetVector3Item(idx++);
  6051. topshear = rules.GetVector3Item(idx++);
  6052. part.Shape.PathCurve = (byte)Extrusion.Straight;
  6053. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 3);
  6054. break;
  6055. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  6056. if (remain < 5)
  6057. return;
  6058. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6059. v = rules.GetVector3Item(idx++); // cut
  6060. hollow = (float)rules.GetLSLFloatItem(idx++);
  6061. twist = rules.GetVector3Item(idx++);
  6062. taper_b = rules.GetVector3Item(idx++); // dimple
  6063. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6064. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, 5);
  6065. break;
  6066. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  6067. if (remain < 11)
  6068. return;
  6069. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6070. v = rules.GetVector3Item(idx++); //cut
  6071. hollow = (float)rules.GetLSLFloatItem(idx++);
  6072. twist = rules.GetVector3Item(idx++);
  6073. holesize = rules.GetVector3Item(idx++);
  6074. topshear = rules.GetVector3Item(idx++);
  6075. profilecut = rules.GetVector3Item(idx++);
  6076. taper_b = rules.GetVector3Item(idx++); // taper_a
  6077. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6078. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6079. skew = (float)rules.GetLSLFloatItem(idx++);
  6080. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6081. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6082. revolutions, radiusoffset, skew, 0);
  6083. break;
  6084. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  6085. if (remain < 11)
  6086. return;
  6087. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6088. v = rules.GetVector3Item(idx++); //cut
  6089. hollow = (float)rules.GetLSLFloatItem(idx++);
  6090. twist = rules.GetVector3Item(idx++);
  6091. holesize = rules.GetVector3Item(idx++);
  6092. topshear = rules.GetVector3Item(idx++);
  6093. profilecut = rules.GetVector3Item(idx++);
  6094. taper_b = rules.GetVector3Item(idx++); // taper_a
  6095. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6096. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6097. skew = (float)rules.GetLSLFloatItem(idx++);
  6098. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6099. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6100. revolutions, radiusoffset, skew, 1);
  6101. break;
  6102. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  6103. if (remain < 11)
  6104. return;
  6105. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6106. v = rules.GetVector3Item(idx++); //cut
  6107. hollow = (float)rules.GetLSLFloatItem(idx++);
  6108. twist = rules.GetVector3Item(idx++);
  6109. holesize = rules.GetVector3Item(idx++);
  6110. topshear = rules.GetVector3Item(idx++);
  6111. profilecut = rules.GetVector3Item(idx++);
  6112. taper_b = rules.GetVector3Item(idx++); // taper_a
  6113. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6114. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6115. skew = (float)rules.GetLSLFloatItem(idx++);
  6116. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6117. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6118. revolutions, radiusoffset, skew, 3);
  6119. break;
  6120. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  6121. if (remain < 2)
  6122. return;
  6123. string map = rules.Data[idx++].ToString();
  6124. face = (int)rules.GetLSLIntegerItem(idx++); // type
  6125. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6126. SetPrimitiveShapeParams(part, map, face);
  6127. break;
  6128. }
  6129. break;
  6130. case (int)ScriptBaseClass.PRIM_TEXTURE:
  6131. if (remain < 5)
  6132. return;
  6133. face=(int)rules.GetLSLIntegerItem(idx++);
  6134. string tex=rules.Data[idx++].ToString();
  6135. LSL_Vector repeats=rules.GetVector3Item(idx++);
  6136. LSL_Vector offsets=rules.GetVector3Item(idx++);
  6137. double rotation=(double)rules.GetLSLFloatItem(idx++);
  6138. SetTexture(part, tex, face);
  6139. ScaleTexture(part, repeats.x, repeats.y, face);
  6140. OffsetTexture(part, offsets.x, offsets.y, face);
  6141. RotateTexture(part, rotation, face);
  6142. break;
  6143. case (int)ScriptBaseClass.PRIM_COLOR:
  6144. if (remain < 3)
  6145. return;
  6146. face=(int)rules.GetLSLIntegerItem(idx++);
  6147. LSL_Vector color=rules.GetVector3Item(idx++);
  6148. double alpha=(double)rules.GetLSLFloatItem(idx++);
  6149. part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
  6150. SetAlpha(part, alpha, face);
  6151. break;
  6152. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  6153. if (remain < 7)
  6154. return;
  6155. bool flexi = rules.GetLSLIntegerItem(idx++);
  6156. int softness = rules.GetLSLIntegerItem(idx++);
  6157. float gravity = (float)rules.GetLSLFloatItem(idx++);
  6158. float friction = (float)rules.GetLSLFloatItem(idx++);
  6159. float wind = (float)rules.GetLSLFloatItem(idx++);
  6160. float tension = (float)rules.GetLSLFloatItem(idx++);
  6161. LSL_Vector force = rules.GetVector3Item(idx++);
  6162. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  6163. break;
  6164. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  6165. if (remain < 5)
  6166. return;
  6167. bool light = rules.GetLSLIntegerItem(idx++);
  6168. LSL_Vector lightcolor = rules.GetVector3Item(idx++);
  6169. float intensity = (float)rules.GetLSLFloatItem(idx++);
  6170. float radius = (float)rules.GetLSLFloatItem(idx++);
  6171. float falloff = (float)rules.GetLSLFloatItem(idx++);
  6172. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  6173. break;
  6174. case (int)ScriptBaseClass.PRIM_GLOW:
  6175. if (remain < 2)
  6176. return;
  6177. face = rules.GetLSLIntegerItem(idx++);
  6178. float glow = (float)rules.GetLSLFloatItem(idx++);
  6179. SetGlow(part, face, glow);
  6180. break;
  6181. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  6182. if (remain < 3)
  6183. return;
  6184. face = (int)rules.GetLSLIntegerItem(idx++);
  6185. int shiny = (int)rules.GetLSLIntegerItem(idx++);
  6186. Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++));
  6187. SetShiny(part, face, shiny, bump);
  6188. break;
  6189. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  6190. if (remain < 2)
  6191. return;
  6192. face = rules.GetLSLIntegerItem(idx++);
  6193. bool st = rules.GetLSLIntegerItem(idx++);
  6194. SetFullBright(part, face , st);
  6195. break;
  6196. case (int)ScriptBaseClass.PRIM_MATERIAL:
  6197. if (remain < 1)
  6198. return;
  6199. int mat = rules.GetLSLIntegerItem(idx++);
  6200. if (mat < 0 || mat > 7)
  6201. return;
  6202. part.Material = Convert.ToByte(mat);
  6203. break;
  6204. case (int)ScriptBaseClass.PRIM_PHANTOM:
  6205. if (remain < 1)
  6206. return;
  6207. string ph = rules.Data[idx++].ToString();
  6208. bool phantom;
  6209. if (ph.Equals("1"))
  6210. phantom = true;
  6211. else
  6212. phantom = false;
  6213. part.ScriptSetPhantomStatus(phantom);
  6214. break;
  6215. case (int)ScriptBaseClass.PRIM_PHYSICS:
  6216. if (remain < 1)
  6217. return;
  6218. string phy = rules.Data[idx++].ToString();
  6219. bool physics;
  6220. if (phy.Equals("1"))
  6221. physics = true;
  6222. else
  6223. physics = false;
  6224. part.ScriptSetPhysicsStatus(physics);
  6225. break;
  6226. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  6227. if (remain < 1)
  6228. return;
  6229. string temp = rules.Data[idx++].ToString();
  6230. bool tempOnRez;
  6231. if (temp.Equals("1"))
  6232. tempOnRez = true;
  6233. else
  6234. tempOnRez = false;
  6235. part.ScriptSetTemporaryStatus(tempOnRez);
  6236. break;
  6237. case (int)ScriptBaseClass.PRIM_TEXGEN:
  6238. if (remain < 2)
  6239. return;
  6240. //face,type
  6241. face = rules.GetLSLIntegerItem(idx++);
  6242. int style = rules.GetLSLIntegerItem(idx++);
  6243. SetTexGen(part, face, style);
  6244. break;
  6245. case (int)ScriptBaseClass.PRIM_TEXT:
  6246. if (remain < 3)
  6247. return;
  6248. string primText = rules.GetLSLStringItem(idx++);
  6249. LSL_Vector primTextColor = rules.GetVector3Item(idx++);
  6250. LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++);
  6251. Vector3 av3 = new Vector3(Util.Clip((float)primTextColor.x, 0.0f, 1.0f),
  6252. Util.Clip((float)primTextColor.y, 0.0f, 1.0f),
  6253. Util.Clip((float)primTextColor.z, 0.0f, 1.0f));
  6254. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  6255. break;
  6256. }
  6257. }
  6258. }
  6259. public LSL_String llStringToBase64(string str)
  6260. {
  6261. m_host.AddScriptLPS(1);
  6262. try
  6263. {
  6264. byte[] encData_byte = new byte[str.Length];
  6265. encData_byte = Util.UTF8.GetBytes(str);
  6266. string encodedData = Convert.ToBase64String(encData_byte);
  6267. return encodedData;
  6268. }
  6269. catch (Exception e)
  6270. {
  6271. throw new Exception("Error in base64Encode" + e.Message);
  6272. }
  6273. }
  6274. public LSL_String llBase64ToString(string str)
  6275. {
  6276. m_host.AddScriptLPS(1);
  6277. try
  6278. {
  6279. return Util.Base64ToString(str);
  6280. }
  6281. catch (Exception e)
  6282. {
  6283. throw new Exception("Error in base64Decode" + e.Message);
  6284. }
  6285. }
  6286. public LSL_String llXorBase64Strings(string str1, string str2)
  6287. {
  6288. m_host.AddScriptLPS(1);
  6289. Deprecated("llXorBase64Strings");
  6290. ScriptSleep(300);
  6291. return String.Empty;
  6292. }
  6293. public void llRemoteDataSetRegion()
  6294. {
  6295. m_host.AddScriptLPS(1);
  6296. Deprecated("llRemoteDataSetRegion");
  6297. }
  6298. public LSL_Float llLog10(double val)
  6299. {
  6300. m_host.AddScriptLPS(1);
  6301. return (double)Math.Log10(val);
  6302. }
  6303. public LSL_Float llLog(double val)
  6304. {
  6305. m_host.AddScriptLPS(1);
  6306. return (double)Math.Log(val);
  6307. }
  6308. public LSL_List llGetAnimationList(string id)
  6309. {
  6310. m_host.AddScriptLPS(1);
  6311. LSL_List l = new LSL_List();
  6312. ScenePresence av = World.GetScenePresence((UUID)id);
  6313. if (av == null || av.IsChildAgent) // only if in the region
  6314. return l;
  6315. UUID[] anims;
  6316. anims = av.Animator.GetAnimationArray();
  6317. foreach (UUID foo in anims)
  6318. l.Add(foo.ToString());
  6319. return l;
  6320. }
  6321. public void llSetParcelMusicURL(string url)
  6322. {
  6323. m_host.AddScriptLPS(1);
  6324. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  6325. if (land.LandData.OwnerID != m_host.OwnerID)
  6326. return;
  6327. land.SetMusicUrl(url);
  6328. ScriptSleep(2000);
  6329. }
  6330. public LSL_Vector llGetRootPosition()
  6331. {
  6332. m_host.AddScriptLPS(1);
  6333. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition.X, m_host.ParentGroup.AbsolutePosition.Y,
  6334. m_host.ParentGroup.AbsolutePosition.Z);
  6335. }
  6336. /// <summary>
  6337. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  6338. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  6339. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  6340. /// In the root prim:-
  6341. /// Returns the object rotation if not attached
  6342. /// Returns the avatars rotation if attached
  6343. /// Returns the camera rotation if attached and the avatar is in mouselook
  6344. /// </summary>
  6345. public LSL_Rotation llGetRootRotation()
  6346. {
  6347. m_host.AddScriptLPS(1);
  6348. Quaternion q;
  6349. if (m_host.ParentGroup.RootPart.AttachmentPoint != 0)
  6350. {
  6351. ScenePresence avatar = World.GetScenePresence(m_host.AttachedAvatar);
  6352. if (avatar != null)
  6353. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  6354. q = avatar.CameraRotation; // Mouselook
  6355. else
  6356. q = avatar.Rotation; // Currently infrequently updated so may be inaccurate
  6357. else
  6358. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  6359. }
  6360. else
  6361. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  6362. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  6363. }
  6364. public LSL_String llGetObjectDesc()
  6365. {
  6366. return m_host.Description!=null?m_host.Description:String.Empty;
  6367. }
  6368. public void llSetObjectDesc(string desc)
  6369. {
  6370. m_host.AddScriptLPS(1);
  6371. m_host.Description = desc!=null?desc:String.Empty;
  6372. }
  6373. public LSL_String llGetCreator()
  6374. {
  6375. m_host.AddScriptLPS(1);
  6376. return m_host.CreatorID.ToString();
  6377. }
  6378. public LSL_String llGetTimestamp()
  6379. {
  6380. m_host.AddScriptLPS(1);
  6381. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  6382. }
  6383. public LSL_Integer llGetNumberOfPrims()
  6384. {
  6385. m_host.AddScriptLPS(1);
  6386. int avatarCount = 0;
  6387. World.ForEachScenePresence(delegate(ScenePresence presence)
  6388. {
  6389. if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID))
  6390. avatarCount++;
  6391. });
  6392. return m_host.ParentGroup.PrimCount + avatarCount;
  6393. }
  6394. /// <summary>
  6395. /// A partial implementation.
  6396. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  6397. /// So far only valid for standing/flying/ground sitting avatars and single prim objects.
  6398. /// If the object has multiple prims and/or a sitting avatar then the bounding
  6399. /// box is for the root prim only.
  6400. /// </summary>
  6401. public LSL_List llGetBoundingBox(string obj)
  6402. {
  6403. m_host.AddScriptLPS(1);
  6404. UUID objID = UUID.Zero;
  6405. LSL_List result = new LSL_List();
  6406. if (!UUID.TryParse(obj, out objID))
  6407. {
  6408. result.Add(new LSL_Vector());
  6409. result.Add(new LSL_Vector());
  6410. return result;
  6411. }
  6412. ScenePresence presence = World.GetScenePresence(objID);
  6413. if (presence != null)
  6414. {
  6415. if (presence.ParentID == 0) // not sat on an object
  6416. {
  6417. LSL_Vector lower;
  6418. LSL_Vector upper;
  6419. if (presence.Animator.Animations.DefaultAnimation.AnimID
  6420. == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  6421. {
  6422. // This is for ground sitting avatars
  6423. float height = presence.Appearance.AvatarHeight / 2.66666667f;
  6424. lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
  6425. upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
  6426. }
  6427. else
  6428. {
  6429. // This is for standing/flying avatars
  6430. float height = presence.Appearance.AvatarHeight / 2.0f;
  6431. lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
  6432. upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
  6433. }
  6434. result.Add(lower);
  6435. result.Add(upper);
  6436. return result;
  6437. }
  6438. else
  6439. {
  6440. // sitting on an object so we need the bounding box of that
  6441. // which should include the avatar so set the UUID to the
  6442. // UUID of the object the avatar is sat on and allow it to fall through
  6443. // to processing an object
  6444. SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
  6445. objID = p.UUID;
  6446. }
  6447. }
  6448. SceneObjectPart part = World.GetSceneObjectPart(objID);
  6449. // Currently only works for single prims without a sitting avatar
  6450. if (part != null)
  6451. {
  6452. Vector3 halfSize = part.Scale / 2.0f;
  6453. LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f);
  6454. LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z);
  6455. result.Add(lower);
  6456. result.Add(upper);
  6457. return result;
  6458. }
  6459. // Not found so return empty values
  6460. result.Add(new LSL_Vector());
  6461. result.Add(new LSL_Vector());
  6462. return result;
  6463. }
  6464. public LSL_Vector llGetGeometricCenter()
  6465. {
  6466. return new LSL_Vector(m_host.GetGeometricCenter().X, m_host.GetGeometricCenter().Y, m_host.GetGeometricCenter().Z);
  6467. }
  6468. public LSL_List llGetPrimitiveParams(LSL_List rules)
  6469. {
  6470. m_host.AddScriptLPS(1);
  6471. return GetLinkPrimitiveParams(m_host, rules);
  6472. }
  6473. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  6474. {
  6475. m_host.AddScriptLPS(1);
  6476. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6477. LSL_List res = new LSL_List();
  6478. foreach (var part in parts)
  6479. {
  6480. LSL_List partRes = GetLinkPrimitiveParams(part, rules);
  6481. res += partRes;
  6482. }
  6483. return res;
  6484. }
  6485. public LSL_List GetLinkPrimitiveParams(SceneObjectPart part, LSL_List rules)
  6486. {
  6487. LSL_List res = new LSL_List();
  6488. int idx=0;
  6489. while (idx < rules.Length)
  6490. {
  6491. int code=(int)rules.GetLSLIntegerItem(idx++);
  6492. int remain=rules.Length-idx;
  6493. switch (code)
  6494. {
  6495. case (int)ScriptBaseClass.PRIM_MATERIAL:
  6496. res.Add(new LSL_Integer(part.Material));
  6497. break;
  6498. case (int)ScriptBaseClass.PRIM_PHYSICS:
  6499. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  6500. res.Add(new LSL_Integer(1));
  6501. else
  6502. res.Add(new LSL_Integer(0));
  6503. break;
  6504. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  6505. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  6506. res.Add(new LSL_Integer(1));
  6507. else
  6508. res.Add(new LSL_Integer(0));
  6509. break;
  6510. case (int)ScriptBaseClass.PRIM_PHANTOM:
  6511. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  6512. res.Add(new LSL_Integer(1));
  6513. else
  6514. res.Add(new LSL_Integer(0));
  6515. break;
  6516. case (int)ScriptBaseClass.PRIM_POSITION:
  6517. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  6518. part.AbsolutePosition.Y,
  6519. part.AbsolutePosition.Z);
  6520. // For some reason, the part.AbsolutePosition.* values do not change if the
  6521. // linkset is rotated; they always reflect the child prim's world position
  6522. // as though the linkset is unrotated. This is incompatible behavior with SL's
  6523. // implementation, so will break scripts imported from there (not to mention it
  6524. // makes it more difficult to determine a child prim's actual inworld position).
  6525. if (part.ParentID != 0)
  6526. v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
  6527. res.Add(v);
  6528. break;
  6529. case (int)ScriptBaseClass.PRIM_SIZE:
  6530. res.Add(new LSL_Vector(part.Scale.X,
  6531. part.Scale.Y,
  6532. part.Scale.Z));
  6533. break;
  6534. case (int)ScriptBaseClass.PRIM_ROTATION:
  6535. res.Add(GetPartRot(part));
  6536. break;
  6537. case (int)ScriptBaseClass.PRIM_TYPE:
  6538. // implementing box
  6539. PrimitiveBaseShape Shape = part.Shape;
  6540. int primType = (int)part.GetPrimType();
  6541. res.Add(new LSL_Integer(primType));
  6542. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  6543. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  6544. switch (primType)
  6545. {
  6546. case ScriptBaseClass.PRIM_TYPE_BOX:
  6547. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  6548. case ScriptBaseClass.PRIM_TYPE_PRISM:
  6549. res.Add(new LSL_Integer(Shape.ProfileCurve));
  6550. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  6551. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  6552. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  6553. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  6554. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  6555. break;
  6556. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  6557. res.Add(new LSL_Integer(Shape.ProfileCurve));
  6558. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  6559. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  6560. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  6561. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  6562. break;
  6563. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  6564. res.Add(Shape.SculptTexture.ToString());
  6565. res.Add(new LSL_Integer(Shape.SculptType));
  6566. break;
  6567. case ScriptBaseClass.PRIM_TYPE_RING:
  6568. case ScriptBaseClass.PRIM_TYPE_TUBE:
  6569. case ScriptBaseClass.PRIM_TYPE_TORUS:
  6570. // holeshape
  6571. res.Add(new LSL_Integer(Shape.ProfileCurve));
  6572. // cut
  6573. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  6574. // hollow
  6575. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  6576. // twist
  6577. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  6578. // vector holesize
  6579. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  6580. // vector topshear
  6581. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  6582. // vector profilecut
  6583. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  6584. // vector tapera
  6585. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  6586. // float revolutions
  6587. res.Add(new LSL_Float((Shape.PathRevolutions * 0.015) + 1.0)); // Slightly inaccurate, because an unsigned
  6588. // byte is being used to represent the entire
  6589. // range of floating-point values from 1.0
  6590. // through 4.0 (which is how SL does it).
  6591. // float radiusoffset
  6592. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  6593. // float skew
  6594. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  6595. break;
  6596. }
  6597. break;
  6598. case (int)ScriptBaseClass.PRIM_TEXTURE:
  6599. if (remain < 1)
  6600. return res;
  6601. int face = (int)rules.GetLSLIntegerItem(idx++);
  6602. Primitive.TextureEntry tex = part.Shape.Textures;
  6603. if (face == ScriptBaseClass.ALL_SIDES)
  6604. {
  6605. for (face = 0 ; face < GetNumberOfSides(part); face++)
  6606. {
  6607. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6608. res.Add(new LSL_String(texface.TextureID.ToString()));
  6609. res.Add(new LSL_Vector(texface.RepeatU,
  6610. texface.RepeatV,
  6611. 0));
  6612. res.Add(new LSL_Vector(texface.OffsetU,
  6613. texface.OffsetV,
  6614. 0));
  6615. res.Add(new LSL_Float(texface.Rotation));
  6616. }
  6617. }
  6618. else
  6619. {
  6620. if (face >= 0 && face < GetNumberOfSides(part))
  6621. {
  6622. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6623. res.Add(new LSL_String(texface.TextureID.ToString()));
  6624. res.Add(new LSL_Vector(texface.RepeatU,
  6625. texface.RepeatV,
  6626. 0));
  6627. res.Add(new LSL_Vector(texface.OffsetU,
  6628. texface.OffsetV,
  6629. 0));
  6630. res.Add(new LSL_Float(texface.Rotation));
  6631. }
  6632. }
  6633. break;
  6634. case (int)ScriptBaseClass.PRIM_COLOR:
  6635. if (remain < 1)
  6636. return res;
  6637. face=(int)rules.GetLSLIntegerItem(idx++);
  6638. tex = part.Shape.Textures;
  6639. Color4 texcolor;
  6640. if (face == ScriptBaseClass.ALL_SIDES)
  6641. {
  6642. for (face = 0 ; face < GetNumberOfSides(part); face++)
  6643. {
  6644. texcolor = tex.GetFace((uint)face).RGBA;
  6645. res.Add(new LSL_Vector(texcolor.R,
  6646. texcolor.G,
  6647. texcolor.B));
  6648. res.Add(new LSL_Float(texcolor.A));
  6649. }
  6650. }
  6651. else
  6652. {
  6653. texcolor = tex.GetFace((uint)face).RGBA;
  6654. res.Add(new LSL_Vector(texcolor.R,
  6655. texcolor.G,
  6656. texcolor.B));
  6657. res.Add(new LSL_Float(texcolor.A));
  6658. }
  6659. break;
  6660. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  6661. // TODO--------------
  6662. if (remain < 1)
  6663. return res;
  6664. face=(int)rules.GetLSLIntegerItem(idx++);
  6665. res.Add(new LSL_Integer(0));
  6666. res.Add(new LSL_Integer(0));
  6667. break;
  6668. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  6669. // TODO--------------
  6670. if (remain < 1)
  6671. return res;
  6672. face=(int)rules.GetLSLIntegerItem(idx++);
  6673. res.Add(new LSL_Integer(0));
  6674. break;
  6675. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  6676. PrimitiveBaseShape shape = part.Shape;
  6677. if (shape.FlexiEntry)
  6678. res.Add(new LSL_Integer(1)); // active
  6679. else
  6680. res.Add(new LSL_Integer(0));
  6681. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  6682. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  6683. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  6684. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  6685. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  6686. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  6687. shape.FlexiForceY,
  6688. shape.FlexiForceZ));
  6689. break;
  6690. case (int)ScriptBaseClass.PRIM_TEXGEN:
  6691. // TODO--------------
  6692. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  6693. if (remain < 1)
  6694. return res;
  6695. face=(int)rules.GetLSLIntegerItem(idx++);
  6696. res.Add(new LSL_Integer(0));
  6697. break;
  6698. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  6699. shape = part.Shape;
  6700. if (shape.LightEntry)
  6701. res.Add(new LSL_Integer(1)); // active
  6702. else
  6703. res.Add(new LSL_Integer(0));
  6704. res.Add(new LSL_Vector(shape.LightColorR, // color
  6705. shape.LightColorG,
  6706. shape.LightColorB));
  6707. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  6708. res.Add(new LSL_Float(shape.LightRadius)); // radius
  6709. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  6710. break;
  6711. case (int)ScriptBaseClass.PRIM_GLOW:
  6712. // TODO--------------
  6713. if (remain < 1)
  6714. return res;
  6715. face=(int)rules.GetLSLIntegerItem(idx++);
  6716. res.Add(new LSL_Float(0));
  6717. break;
  6718. case (int)ScriptBaseClass.PRIM_TEXT:
  6719. Color4 textColor = part.GetTextColor();
  6720. res.Add(part.Text);
  6721. res.Add(new LSL_Vector(textColor.R,
  6722. textColor.G,
  6723. textColor.B));
  6724. res.Add(new LSL_Float(textColor.A));
  6725. break;
  6726. }
  6727. }
  6728. return res;
  6729. }
  6730. // <remarks>
  6731. // <para>
  6732. // The .NET definition of base 64 is:
  6733. // <list>
  6734. // <item>
  6735. // Significant: A-Z a-z 0-9 + -
  6736. // </item>
  6737. // <item>
  6738. // Whitespace: \t \n \r ' '
  6739. // </item>
  6740. // <item>
  6741. // Valueless: =
  6742. // </item>
  6743. // <item>
  6744. // End-of-string: \0 or '=='
  6745. // </item>
  6746. // </list>
  6747. // </para>
  6748. // <para>
  6749. // Each point in a base-64 string represents
  6750. // a 6 bit value. A 32-bit integer can be
  6751. // represented using 6 characters (with some
  6752. // redundancy).
  6753. // </para>
  6754. // <para>
  6755. // LSL requires a base64 string to be 8
  6756. // characters in length. LSL also uses '/'
  6757. // rather than '-' (MIME compliant).
  6758. // </para>
  6759. // <para>
  6760. // RFC 1341 used as a reference (as specified
  6761. // by the SecondLife Wiki).
  6762. // </para>
  6763. // <para>
  6764. // SL do not record any kind of exception for
  6765. // these functions, so the string to integer
  6766. // conversion returns '0' if an invalid
  6767. // character is encountered during conversion.
  6768. // </para>
  6769. // <para>
  6770. // References
  6771. // <list>
  6772. // <item>
  6773. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  6774. // </item>
  6775. // <item>
  6776. // </item>
  6777. // </list>
  6778. // </para>
  6779. // </remarks>
  6780. // <summary>
  6781. // Table for converting 6-bit integers into
  6782. // base-64 characters
  6783. // </summary>
  6784. protected static readonly char[] i2ctable =
  6785. {
  6786. 'A','B','C','D','E','F','G','H',
  6787. 'I','J','K','L','M','N','O','P',
  6788. 'Q','R','S','T','U','V','W','X',
  6789. 'Y','Z',
  6790. 'a','b','c','d','e','f','g','h',
  6791. 'i','j','k','l','m','n','o','p',
  6792. 'q','r','s','t','u','v','w','x',
  6793. 'y','z',
  6794. '0','1','2','3','4','5','6','7',
  6795. '8','9',
  6796. '+','/'
  6797. };
  6798. // <summary>
  6799. // Table for converting base-64 characters
  6800. // into 6-bit integers.
  6801. // </summary>
  6802. protected static readonly int[] c2itable =
  6803. {
  6804. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  6805. -1,-1,-1,-1,-1,-1,-1,-1,
  6806. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  6807. -1,-1,-1,-1,-1,-1,-1,-1,
  6808. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  6809. -1,-1,-1,63,-1,-1,-1,64,
  6810. 53,54,55,56,57,58,59,60, // 3x
  6811. 61,62,-1,-1,-1,0,-1,-1,
  6812. -1,1,2,3,4,5,6,7, // 4x
  6813. 8,9,10,11,12,13,14,15,
  6814. 16,17,18,19,20,21,22,23, // 5x
  6815. 24,25,26,-1,-1,-1,-1,-1,
  6816. -1,27,28,29,30,31,32,33, // 6x
  6817. 34,35,36,37,38,39,40,41,
  6818. 42,43,44,45,46,47,48,49, // 7x
  6819. 50,51,52,-1,-1,-1,-1,-1,
  6820. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  6821. -1,-1,-1,-1,-1,-1,-1,-1,
  6822. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  6823. -1,-1,-1,-1,-1,-1,-1,-1,
  6824. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  6825. -1,-1,-1,-1,-1,-1,-1,-1,
  6826. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  6827. -1,-1,-1,-1,-1,-1,-1,-1,
  6828. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  6829. -1,-1,-1,-1,-1,-1,-1,-1,
  6830. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  6831. -1,-1,-1,-1,-1,-1,-1,-1,
  6832. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  6833. -1,-1,-1,-1,-1,-1,-1,-1,
  6834. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  6835. -1,-1,-1,-1,-1,-1,-1,-1
  6836. };
  6837. // <summary>
  6838. // Converts a 32-bit integer into a Base64
  6839. // character string. Base64 character strings
  6840. // are always 8 characters long. All iinteger
  6841. // values are acceptable.
  6842. // </summary>
  6843. // <param name="number">
  6844. // 32-bit integer to be converted.
  6845. // </param>
  6846. // <returns>
  6847. // 8 character string. The 1st six characters
  6848. // contain the encoded number, the last two
  6849. // characters are padded with "=".
  6850. // </returns>
  6851. public LSL_String llIntegerToBase64(int number)
  6852. {
  6853. // uninitialized string
  6854. char[] imdt = new char[8];
  6855. m_host.AddScriptLPS(1);
  6856. // Manually unroll the loop
  6857. imdt[7] = '=';
  6858. imdt[6] = '=';
  6859. imdt[5] = i2ctable[number<<4 & 0x3F];
  6860. imdt[4] = i2ctable[number>>2 & 0x3F];
  6861. imdt[3] = i2ctable[number>>8 & 0x3F];
  6862. imdt[2] = i2ctable[number>>14 & 0x3F];
  6863. imdt[1] = i2ctable[number>>20 & 0x3F];
  6864. imdt[0] = i2ctable[number>>26 & 0x3F];
  6865. return new string(imdt);
  6866. }
  6867. // <summary>
  6868. // Converts an eight character base-64 string
  6869. // into a 32-bit integer.
  6870. // </summary>
  6871. // <param name="str">
  6872. // 8 characters string to be converted. Other
  6873. // length strings return zero.
  6874. // </param>
  6875. // <returns>
  6876. // Returns an integer representing the
  6877. // encoded value providedint he 1st 6
  6878. // characters of the string.
  6879. // </returns>
  6880. // <remarks>
  6881. // This is coded to behave like LSL's
  6882. // implementation (I think), based upon the
  6883. // information available at the Wiki.
  6884. // If more than 8 characters are supplied,
  6885. // zero is returned.
  6886. // If a NULL string is supplied, zero will
  6887. // be returned.
  6888. // If fewer than 6 characters are supplied, then
  6889. // the answer will reflect a partial
  6890. // accumulation.
  6891. // <para>
  6892. // The 6-bit segments are
  6893. // extracted left-to-right in big-endian mode,
  6894. // which means that segment 6 only contains the
  6895. // two low-order bits of the 32 bit integer as
  6896. // its high order 2 bits. A short string therefore
  6897. // means loss of low-order information. E.g.
  6898. //
  6899. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  6900. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  6901. // |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|
  6902. // |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|
  6903. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  6904. //
  6905. // </para>
  6906. // </remarks>
  6907. public LSL_Integer llBase64ToInteger(string str)
  6908. {
  6909. int number = 0;
  6910. int digit;
  6911. m_host.AddScriptLPS(1);
  6912. // Require a well-fromed base64 string
  6913. if (str.Length > 8)
  6914. return 0;
  6915. // The loop is unrolled in the interests
  6916. // of performance and simple necessity.
  6917. //
  6918. // MUST find 6 digits to be well formed
  6919. // -1 == invalid
  6920. // 0 == padding
  6921. if ((digit = c2itable[str[0]]) <= 0)
  6922. {
  6923. return digit < 0 ? (int)0 : number;
  6924. }
  6925. number += --digit<<26;
  6926. if ((digit = c2itable[str[1]]) <= 0)
  6927. {
  6928. return digit < 0 ? (int)0 : number;
  6929. }
  6930. number += --digit<<20;
  6931. if ((digit = c2itable[str[2]]) <= 0)
  6932. {
  6933. return digit < 0 ? (int)0 : number;
  6934. }
  6935. number += --digit<<14;
  6936. if ((digit = c2itable[str[3]]) <= 0)
  6937. {
  6938. return digit < 0 ? (int)0 : number;
  6939. }
  6940. number += --digit<<8;
  6941. if ((digit = c2itable[str[4]]) <= 0)
  6942. {
  6943. return digit < 0 ? (int)0 : number;
  6944. }
  6945. number += --digit<<2;
  6946. if ((digit = c2itable[str[5]]) <= 0)
  6947. {
  6948. return digit < 0 ? (int)0 : number;
  6949. }
  6950. number += --digit>>4;
  6951. // ignore trailing padding
  6952. return number;
  6953. }
  6954. public LSL_Float llGetGMTclock()
  6955. {
  6956. m_host.AddScriptLPS(1);
  6957. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  6958. }
  6959. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  6960. {
  6961. m_host.AddScriptLPS(1);
  6962. if (m_UrlModule != null)
  6963. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  6964. return String.Empty;
  6965. }
  6966. public LSL_String llGetSimulatorHostname()
  6967. {
  6968. m_host.AddScriptLPS(1);
  6969. return System.Environment.MachineName;
  6970. }
  6971. // <summary>
  6972. // Scan the string supplied in 'src' and
  6973. // tokenize it based upon two sets of
  6974. // tokenizers provided in two lists,
  6975. // separators and spacers.
  6976. // </summary>
  6977. //
  6978. // <remarks>
  6979. // Separators demarcate tokens and are
  6980. // elided as they are encountered. Spacers
  6981. // also demarcate tokens, but are themselves
  6982. // retained as tokens.
  6983. //
  6984. // Both separators and spacers may be arbitrarily
  6985. // long strings. i.e. ":::".
  6986. //
  6987. // The function returns an ordered list
  6988. // representing the tokens found in the supplied
  6989. // sources string. If two successive tokenizers
  6990. // are encountered, then a NULL entry is added
  6991. // to the list.
  6992. //
  6993. // It is a precondition that the source and
  6994. // toekizer lisst are non-null. If they are null,
  6995. // then a null pointer exception will be thrown
  6996. // while their lengths are being determined.
  6997. //
  6998. // A small amount of working memoryis required
  6999. // of approximately 8*#tokenizers.
  7000. //
  7001. // There are many ways in which this function
  7002. // can be implemented, this implementation is
  7003. // fairly naive and assumes that when the
  7004. // function is invooked with a short source
  7005. // string and/or short lists of tokenizers, then
  7006. // performance will not be an issue.
  7007. //
  7008. // In order to minimize the perofrmance
  7009. // effects of long strings, or large numbers
  7010. // of tokeizers, the function skips as far as
  7011. // possible whenever a toekenizer is found,
  7012. // and eliminates redundant tokenizers as soon
  7013. // as is possible.
  7014. //
  7015. // The implementation tries to avoid any copying
  7016. // of arrays or other objects.
  7017. // </remarks>
  7018. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  7019. {
  7020. int beginning = 0;
  7021. int srclen = src.Length;
  7022. int seplen = separators.Length;
  7023. object[] separray = separators.Data;
  7024. int spclen = spacers.Length;
  7025. object[] spcarray = spacers.Data;
  7026. int mlen = seplen+spclen;
  7027. int[] offset = new int[mlen+1];
  7028. bool[] active = new bool[mlen];
  7029. int best;
  7030. int j;
  7031. // Initial capacity reduces resize cost
  7032. LSL_List tokens = new LSL_List();
  7033. m_host.AddScriptLPS(1);
  7034. // All entries are initially valid
  7035. for (int i = 0; i < mlen; i++)
  7036. active[i] = true;
  7037. offset[mlen] = srclen;
  7038. while (beginning < srclen)
  7039. {
  7040. best = mlen; // as bad as it gets
  7041. // Scan for separators
  7042. for (j = 0; j < seplen; j++)
  7043. {
  7044. if (active[j])
  7045. {
  7046. // scan all of the markers
  7047. if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
  7048. {
  7049. // not present at all
  7050. active[j] = false;
  7051. }
  7052. else
  7053. {
  7054. // present and correct
  7055. if (offset[j] < offset[best])
  7056. {
  7057. // closest so far
  7058. best = j;
  7059. if (offset[best] == beginning)
  7060. break;
  7061. }
  7062. }
  7063. }
  7064. }
  7065. // Scan for spacers
  7066. if (offset[best] != beginning)
  7067. {
  7068. for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
  7069. {
  7070. if (active[j])
  7071. {
  7072. // scan all of the markers
  7073. if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
  7074. {
  7075. // not present at all
  7076. active[j] = false;
  7077. }
  7078. else
  7079. {
  7080. // present and correct
  7081. if (offset[j] < offset[best])
  7082. {
  7083. // closest so far
  7084. best = j;
  7085. }
  7086. }
  7087. }
  7088. }
  7089. }
  7090. // This is the normal exit from the scanning loop
  7091. if (best == mlen)
  7092. {
  7093. // no markers were found on this pass
  7094. // so we're pretty much done
  7095. tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
  7096. break;
  7097. }
  7098. // Otherwise we just add the newly delimited token
  7099. // and recalculate where the search should continue.
  7100. tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning)));
  7101. if (best < seplen)
  7102. {
  7103. beginning = offset[best] + (separray[best].ToString()).Length;
  7104. }
  7105. else
  7106. {
  7107. beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
  7108. tokens.Add(new LSL_String(spcarray[best - seplen].ToString()));
  7109. }
  7110. }
  7111. // This an awkward an not very intuitive boundary case. If the
  7112. // last substring is a tokenizer, then there is an implied trailing
  7113. // null list entry. Hopefully the single comparison will not be too
  7114. // arduous. Alternatively the 'break' could be replced with a return
  7115. // but that's shabby programming.
  7116. if (beginning == srclen)
  7117. {
  7118. if (srclen != 0)
  7119. tokens.Add(new LSL_String(""));
  7120. }
  7121. return tokens;
  7122. }
  7123. public LSL_Integer llGetObjectPermMask(int mask)
  7124. {
  7125. m_host.AddScriptLPS(1);
  7126. int permmask = 0;
  7127. if (mask == ScriptBaseClass.MASK_BASE)//0
  7128. {
  7129. permmask = (int)m_host.BaseMask;
  7130. }
  7131. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  7132. {
  7133. permmask = (int)m_host.OwnerMask;
  7134. }
  7135. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  7136. {
  7137. permmask = (int)m_host.GroupMask;
  7138. }
  7139. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  7140. {
  7141. permmask = (int)m_host.EveryoneMask;
  7142. }
  7143. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  7144. {
  7145. permmask = (int)m_host.NextOwnerMask;
  7146. }
  7147. return permmask;
  7148. }
  7149. public void llSetObjectPermMask(int mask, int value)
  7150. {
  7151. m_host.AddScriptLPS(1);
  7152. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  7153. {
  7154. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  7155. {
  7156. if (mask == ScriptBaseClass.MASK_BASE)//0
  7157. {
  7158. m_host.BaseMask = (uint)value;
  7159. }
  7160. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  7161. {
  7162. m_host.OwnerMask = (uint)value;
  7163. }
  7164. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  7165. {
  7166. m_host.GroupMask = (uint)value;
  7167. }
  7168. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  7169. {
  7170. m_host.EveryoneMask = (uint)value;
  7171. }
  7172. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  7173. {
  7174. m_host.NextOwnerMask = (uint)value;
  7175. }
  7176. }
  7177. }
  7178. }
  7179. public LSL_Integer llGetInventoryPermMask(string item, int mask)
  7180. {
  7181. m_host.AddScriptLPS(1);
  7182. lock (m_host.TaskInventory)
  7183. {
  7184. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  7185. {
  7186. if (inv.Value.Name == item)
  7187. {
  7188. switch (mask)
  7189. {
  7190. case 0:
  7191. return (int)inv.Value.BasePermissions;
  7192. case 1:
  7193. return (int)inv.Value.CurrentPermissions;
  7194. case 2:
  7195. return (int)inv.Value.GroupPermissions;
  7196. case 3:
  7197. return (int)inv.Value.EveryonePermissions;
  7198. case 4:
  7199. return (int)inv.Value.NextPermissions;
  7200. }
  7201. }
  7202. }
  7203. }
  7204. return -1;
  7205. }
  7206. public void llSetInventoryPermMask(string item, int mask, int value)
  7207. {
  7208. m_host.AddScriptLPS(1);
  7209. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  7210. {
  7211. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  7212. {
  7213. lock (m_host.TaskInventory)
  7214. {
  7215. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  7216. {
  7217. if (inv.Value.Name == item)
  7218. {
  7219. switch (mask)
  7220. {
  7221. case 0:
  7222. inv.Value.BasePermissions = (uint)value;
  7223. break;
  7224. case 1:
  7225. inv.Value.CurrentPermissions = (uint)value;
  7226. break;
  7227. case 2:
  7228. inv.Value.GroupPermissions = (uint)value;
  7229. break;
  7230. case 3:
  7231. inv.Value.EveryonePermissions = (uint)value;
  7232. break;
  7233. case 4:
  7234. inv.Value.NextPermissions = (uint)value;
  7235. break;
  7236. }
  7237. }
  7238. }
  7239. }
  7240. }
  7241. }
  7242. }
  7243. public LSL_String llGetInventoryCreator(string item)
  7244. {
  7245. m_host.AddScriptLPS(1);
  7246. lock (m_host.TaskInventory)
  7247. {
  7248. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  7249. {
  7250. if (inv.Value.Name == item)
  7251. {
  7252. return inv.Value.CreatorID.ToString();
  7253. }
  7254. }
  7255. }
  7256. llSay(0, "No item name '" + item + "'");
  7257. return String.Empty;
  7258. }
  7259. public void llOwnerSay(string msg)
  7260. {
  7261. m_host.AddScriptLPS(1);
  7262. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  7263. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  7264. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  7265. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  7266. }
  7267. public LSL_String llRequestSecureURL()
  7268. {
  7269. m_host.AddScriptLPS(1);
  7270. if (m_UrlModule != null)
  7271. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString();
  7272. return UUID.Zero.ToString();
  7273. }
  7274. public LSL_String llRequestSimulatorData(string simulator, int data)
  7275. {
  7276. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL");
  7277. try
  7278. {
  7279. m_host.AddScriptLPS(1);
  7280. string reply = String.Empty;
  7281. GridRegion info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  7282. switch (data)
  7283. {
  7284. case 5: // DATA_SIM_POS
  7285. if (info == null)
  7286. {
  7287. ScriptSleep(1000);
  7288. return UUID.Zero.ToString();
  7289. }
  7290. reply = new LSL_Vector(
  7291. info.RegionLocX * Constants.RegionSize,
  7292. info.RegionLocY * Constants.RegionSize,
  7293. 0).ToString();
  7294. break;
  7295. case 6: // DATA_SIM_STATUS
  7296. if (info != null)
  7297. reply = "up"; // Duh!
  7298. else
  7299. reply = "unknown";
  7300. break;
  7301. case 7: // DATA_SIM_RATING
  7302. if (info == null)
  7303. {
  7304. ScriptSleep(1000);
  7305. return UUID.Zero.ToString();
  7306. }
  7307. int access = info.Maturity;
  7308. if (access == 0)
  7309. reply = "PG";
  7310. else if (access == 1)
  7311. reply = "MATURE";
  7312. else if (access == 2)
  7313. reply = "ADULT";
  7314. else
  7315. reply = "UNKNOWN";
  7316. break;
  7317. case 128:
  7318. if (ossl != null)
  7319. ossl.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData");
  7320. reply = "OpenSim";
  7321. break;
  7322. default:
  7323. ScriptSleep(1000);
  7324. return UUID.Zero.ToString(); // Raise no event
  7325. }
  7326. UUID rq = UUID.Random();
  7327. UUID tid = AsyncCommands.
  7328. DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString());
  7329. AsyncCommands.
  7330. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  7331. ScriptSleep(1000);
  7332. return tid.ToString();
  7333. }
  7334. catch(Exception)
  7335. {
  7336. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  7337. return UUID.Zero.ToString();
  7338. }
  7339. }
  7340. public LSL_String llRequestURL()
  7341. {
  7342. m_host.AddScriptLPS(1);
  7343. if (m_UrlModule != null)
  7344. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString();
  7345. return UUID.Zero.ToString();
  7346. }
  7347. public void llForceMouselook(int mouselook)
  7348. {
  7349. m_host.AddScriptLPS(1);
  7350. m_host.SetForceMouselook(mouselook != 0);
  7351. }
  7352. public LSL_Float llGetObjectMass(string id)
  7353. {
  7354. m_host.AddScriptLPS(1);
  7355. UUID key = new UUID();
  7356. if (UUID.TryParse(id, out key))
  7357. {
  7358. try
  7359. {
  7360. SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  7361. if (obj != null)
  7362. return (double)obj.GetMass();
  7363. // the object is null so the key is for an avatar
  7364. ScenePresence avatar = World.GetScenePresence(key);
  7365. if (avatar != null)
  7366. if (avatar.IsChildAgent)
  7367. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  7368. // child agents have a mass of 1.0
  7369. return 1;
  7370. else
  7371. return (double)avatar.PhysicsActor.Mass;
  7372. }
  7373. catch (KeyNotFoundException)
  7374. {
  7375. return 0; // The Object/Agent not in the region so just return zero
  7376. }
  7377. }
  7378. return 0;
  7379. }
  7380. /// <summary>
  7381. /// illListReplaceList removes the sub-list defined by the inclusive indices
  7382. /// start and end and inserts the src list in its place. The inclusive
  7383. /// nature of the indices means that at least one element must be deleted
  7384. /// if the indices are within the bounds of the existing list. I.e. 2,2
  7385. /// will remove the element at index 2 and replace it with the source
  7386. /// list. Both indices may be negative, with the usual interpretation. An
  7387. /// interesting case is where end is lower than start. As these indices
  7388. /// bound the list to be removed, then 0->end, and start->lim are removed
  7389. /// and the source list is added as a suffix.
  7390. /// </summary>
  7391. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  7392. {
  7393. LSL_List pref = null;
  7394. m_host.AddScriptLPS(1);
  7395. // Note that although we have normalized, both
  7396. // indices could still be negative.
  7397. if (start < 0)
  7398. {
  7399. start = start+dest.Length;
  7400. }
  7401. if (end < 0)
  7402. {
  7403. end = end+dest.Length;
  7404. }
  7405. // The comventional case, remove a sequence starting with
  7406. // start and ending with end. And then insert the source
  7407. // list.
  7408. if (start <= end)
  7409. {
  7410. // If greater than zero, then there is going to be a
  7411. // surviving prefix. Otherwise the inclusive nature
  7412. // of the indices mean that we're going to add the
  7413. // source list as a prefix.
  7414. if (start > 0)
  7415. {
  7416. pref = dest.GetSublist(0,start-1);
  7417. // Only add a suffix if there is something
  7418. // beyond the end index (it's inclusive too).
  7419. if (end + 1 < dest.Length)
  7420. {
  7421. return pref + src + dest.GetSublist(end + 1, -1);
  7422. }
  7423. else
  7424. {
  7425. return pref + src;
  7426. }
  7427. }
  7428. // If start is less than or equal to zero, then
  7429. // the new list is simply a prefix. We still need to
  7430. // figure out any necessary surgery to the destination
  7431. // based upon end. Note that if end exceeds the upper
  7432. // bound in this case, the entire destination list
  7433. // is removed.
  7434. else
  7435. {
  7436. if (end + 1 < dest.Length)
  7437. {
  7438. return src + dest.GetSublist(end + 1, -1);
  7439. }
  7440. else
  7441. {
  7442. return src;
  7443. }
  7444. }
  7445. }
  7446. // Finally, if start > end, we strip away a prefix and
  7447. // a suffix, to leave the list that sits <between> ens
  7448. // and start, and then tag on the src list. AT least
  7449. // that's my interpretation. We can get sublist to do
  7450. // this for us. Note that one, or both of the indices
  7451. // might have been negative.
  7452. else
  7453. {
  7454. return dest.GetSublist(end + 1, start - 1) + src;
  7455. }
  7456. }
  7457. public void llLoadURL(string avatar_id, string message, string url)
  7458. {
  7459. m_host.AddScriptLPS(1);
  7460. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  7461. if (null != dm)
  7462. dm.SendUrlToUser(
  7463. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  7464. ScriptSleep(10000);
  7465. }
  7466. public void llParcelMediaCommandList(LSL_List commandList)
  7467. {
  7468. // TODO: Not implemented yet (missing in libomv?):
  7469. // 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)
  7470. m_host.AddScriptLPS(1);
  7471. // according to the docs, this command only works if script owner and land owner are the same
  7472. // lets add estate owners and gods, too, and use the generic permission check.
  7473. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  7474. if (!World.Permissions.CanEditParcel(m_host.OwnerID, landObject)) return;
  7475. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  7476. byte loop = 0;
  7477. LandData landData = landObject.LandData;
  7478. string url = landData.MediaURL;
  7479. string texture = landData.MediaID.ToString();
  7480. bool autoAlign = landData.MediaAutoScale != 0;
  7481. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  7482. string description = "";
  7483. int width = 0;
  7484. int height = 0;
  7485. ParcelMediaCommandEnum? commandToSend = null;
  7486. float time = 0.0f; // default is from start
  7487. ScenePresence presence = null;
  7488. for (int i = 0; i < commandList.Data.Length; i++)
  7489. {
  7490. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i];
  7491. switch (command)
  7492. {
  7493. case ParcelMediaCommandEnum.Agent:
  7494. // we send only to one agent
  7495. if ((i + 1) < commandList.Length)
  7496. {
  7497. if (commandList.Data[i + 1] is LSL_String)
  7498. {
  7499. UUID agentID;
  7500. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  7501. {
  7502. presence = World.GetScenePresence(agentID);
  7503. }
  7504. }
  7505. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  7506. ++i;
  7507. }
  7508. break;
  7509. case ParcelMediaCommandEnum.Loop:
  7510. loop = 1;
  7511. commandToSend = command;
  7512. update = true; //need to send the media update packet to set looping
  7513. break;
  7514. case ParcelMediaCommandEnum.Play:
  7515. loop = 0;
  7516. commandToSend = command;
  7517. update = true; //need to send the media update packet to make sure it doesn't loop
  7518. break;
  7519. case ParcelMediaCommandEnum.Pause:
  7520. case ParcelMediaCommandEnum.Stop:
  7521. case ParcelMediaCommandEnum.Unload:
  7522. commandToSend = command;
  7523. break;
  7524. case ParcelMediaCommandEnum.Url:
  7525. if ((i + 1) < commandList.Length)
  7526. {
  7527. if (commandList.Data[i + 1] is LSL_String)
  7528. {
  7529. url = (LSL_String)commandList.Data[i + 1];
  7530. update = true;
  7531. }
  7532. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_URL must be a string.");
  7533. ++i;
  7534. }
  7535. break;
  7536. case ParcelMediaCommandEnum.Texture:
  7537. if ((i + 1) < commandList.Length)
  7538. {
  7539. if (commandList.Data[i + 1] is LSL_String)
  7540. {
  7541. texture = (LSL_String)commandList.Data[i + 1];
  7542. update = true;
  7543. }
  7544. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or key.");
  7545. ++i;
  7546. }
  7547. break;
  7548. case ParcelMediaCommandEnum.Time:
  7549. if ((i + 1) < commandList.Length)
  7550. {
  7551. if (commandList.Data[i + 1] is LSL_Float)
  7552. {
  7553. time = (float)(LSL_Float)commandList.Data[i + 1];
  7554. }
  7555. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TIME must be a float.");
  7556. ++i;
  7557. }
  7558. break;
  7559. case ParcelMediaCommandEnum.AutoAlign:
  7560. if ((i + 1) < commandList.Length)
  7561. {
  7562. if (commandList.Data[i + 1] is LSL_Integer)
  7563. {
  7564. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  7565. update = true;
  7566. }
  7567. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer.");
  7568. ++i;
  7569. }
  7570. break;
  7571. case ParcelMediaCommandEnum.Type:
  7572. if ((i + 1) < commandList.Length)
  7573. {
  7574. if (commandList.Data[i + 1] is LSL_String)
  7575. {
  7576. mediaType = (LSL_String)commandList.Data[i + 1];
  7577. update = true;
  7578. }
  7579. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string.");
  7580. ++i;
  7581. }
  7582. break;
  7583. case ParcelMediaCommandEnum.Desc:
  7584. if ((i + 1) < commandList.Length)
  7585. {
  7586. if (commandList.Data[i + 1] is LSL_String)
  7587. {
  7588. description = (LSL_String)commandList.Data[i + 1];
  7589. update = true;
  7590. }
  7591. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_DESC must be a string.");
  7592. ++i;
  7593. }
  7594. break;
  7595. case ParcelMediaCommandEnum.Size:
  7596. if ((i + 2) < commandList.Length)
  7597. {
  7598. if (commandList.Data[i + 1] is LSL_Integer)
  7599. {
  7600. if (commandList.Data[i + 2] is LSL_Integer)
  7601. {
  7602. width = (LSL_Integer)commandList.Data[i + 1];
  7603. height = (LSL_Integer)commandList.Data[i + 2];
  7604. update = true;
  7605. }
  7606. else ShoutError("The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer.");
  7607. }
  7608. else ShoutError("The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer.");
  7609. i += 2;
  7610. }
  7611. break;
  7612. default:
  7613. NotImplemented("llParcelMediaCommandList parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  7614. break;
  7615. }//end switch
  7616. }//end for
  7617. // if we didn't get a presence, we send to all and change the url
  7618. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  7619. // did something important change or do we only start/stop/pause?
  7620. if (update)
  7621. {
  7622. if (presence == null)
  7623. {
  7624. // we send to all
  7625. landData.MediaID = new UUID(texture);
  7626. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  7627. landData.MediaSize[0] = width;
  7628. landData.MediaSize[1] = height;
  7629. landData.MediaType = mediaType;
  7630. // do that one last, it will cause a ParcelPropertiesUpdate
  7631. landObject.SetMediaUrl(url);
  7632. // now send to all (non-child) agents
  7633. World.ForEachScenePresence(delegate(ScenePresence sp)
  7634. {
  7635. if (!sp.IsChildAgent)
  7636. {
  7637. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  7638. landData.MediaID,
  7639. landData.MediaAutoScale,
  7640. mediaType,
  7641. description,
  7642. width, height,
  7643. loop);
  7644. }
  7645. });
  7646. }
  7647. else if (!presence.IsChildAgent)
  7648. {
  7649. // we only send to one (root) agent
  7650. presence.ControllingClient.SendParcelMediaUpdate(url,
  7651. new UUID(texture),
  7652. autoAlign ? (byte)1 : (byte)0,
  7653. mediaType,
  7654. description,
  7655. width, height,
  7656. loop);
  7657. }
  7658. }
  7659. if (commandToSend != null)
  7660. {
  7661. // the commandList contained a start/stop/... command, too
  7662. if (presence == null)
  7663. {
  7664. // send to all (non-child) agents
  7665. World.ForEachScenePresence(delegate(ScenePresence sp)
  7666. {
  7667. if (!sp.IsChildAgent)
  7668. {
  7669. sp.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  7670. (ParcelMediaCommandEnum)commandToSend,
  7671. time);
  7672. }
  7673. });
  7674. }
  7675. else if (!presence.IsChildAgent)
  7676. {
  7677. presence.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  7678. (ParcelMediaCommandEnum)commandToSend,
  7679. time);
  7680. }
  7681. }
  7682. ScriptSleep(2000);
  7683. }
  7684. public LSL_List llParcelMediaQuery(LSL_List aList)
  7685. {
  7686. m_host.AddScriptLPS(1);
  7687. LSL_List list = new LSL_List();
  7688. //TO DO: make the implementation for the missing commands
  7689. //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)
  7690. for (int i = 0; i < aList.Data.Length; i++)
  7691. {
  7692. if (aList.Data[i] != null)
  7693. {
  7694. switch ((ParcelMediaCommandEnum) aList.Data[i])
  7695. {
  7696. case ParcelMediaCommandEnum.Url:
  7697. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
  7698. break;
  7699. case ParcelMediaCommandEnum.Desc:
  7700. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).Description));
  7701. break;
  7702. case ParcelMediaCommandEnum.Texture:
  7703. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaID.ToString()));
  7704. break;
  7705. case ParcelMediaCommandEnum.Type:
  7706. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaType));
  7707. break;
  7708. case ParcelMediaCommandEnum.Size:
  7709. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaSize[0]));
  7710. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaSize[1]));
  7711. break;
  7712. default:
  7713. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  7714. NotImplemented("llParcelMediaQuery parameter do not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  7715. break;
  7716. }
  7717. }
  7718. }
  7719. ScriptSleep(2000);
  7720. return list;
  7721. }
  7722. public LSL_Integer llModPow(int a, int b, int c)
  7723. {
  7724. m_host.AddScriptLPS(1);
  7725. Int64 tmp = 0;
  7726. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  7727. ScriptSleep(1000);
  7728. return Convert.ToInt32(tmp);
  7729. }
  7730. public LSL_Integer llGetInventoryType(string name)
  7731. {
  7732. m_host.AddScriptLPS(1);
  7733. lock (m_host.TaskInventory)
  7734. {
  7735. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  7736. {
  7737. if (inv.Value.Name == name)
  7738. {
  7739. return inv.Value.Type;
  7740. }
  7741. }
  7742. }
  7743. return -1;
  7744. }
  7745. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  7746. {
  7747. m_host.AddScriptLPS(1);
  7748. if (quick_pay_buttons.Data.Length < 4)
  7749. {
  7750. LSLError("List must have at least 4 elements");
  7751. return;
  7752. }
  7753. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  7754. m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0];
  7755. m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1];
  7756. m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2];
  7757. m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3];
  7758. m_host.ParentGroup.HasGroupChanged = true;
  7759. }
  7760. public LSL_Vector llGetCameraPos()
  7761. {
  7762. m_host.AddScriptLPS(1);
  7763. UUID invItemID = InventorySelf();
  7764. if (invItemID == UUID.Zero)
  7765. return new LSL_Vector();
  7766. lock (m_host.TaskInventory)
  7767. {
  7768. if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
  7769. return new LSL_Vector();
  7770. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  7771. {
  7772. ShoutError("No permissions to track the camera");
  7773. return new LSL_Vector();
  7774. }
  7775. }
  7776. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  7777. if (presence != null)
  7778. {
  7779. LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
  7780. return pos;
  7781. }
  7782. return new LSL_Vector();
  7783. }
  7784. public LSL_Rotation llGetCameraRot()
  7785. {
  7786. m_host.AddScriptLPS(1);
  7787. UUID invItemID = InventorySelf();
  7788. if (invItemID == UUID.Zero)
  7789. return new LSL_Rotation();
  7790. lock (m_host.TaskInventory)
  7791. {
  7792. if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
  7793. return new LSL_Rotation();
  7794. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  7795. {
  7796. ShoutError("No permissions to track the camera");
  7797. return new LSL_Rotation();
  7798. }
  7799. }
  7800. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  7801. if (presence != null)
  7802. {
  7803. return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
  7804. }
  7805. return new LSL_Rotation();
  7806. }
  7807. /// <summary>
  7808. /// The SL implementation does nothing, it is deprecated
  7809. /// This duplicates SL
  7810. /// </summary>
  7811. public void llSetPrimURL(string url)
  7812. {
  7813. m_host.AddScriptLPS(1);
  7814. ScriptSleep(2000);
  7815. }
  7816. /// <summary>
  7817. /// The SL implementation shouts an error, it is deprecated
  7818. /// This duplicates SL
  7819. /// </summary>
  7820. public void llRefreshPrimURL()
  7821. {
  7822. m_host.AddScriptLPS(1);
  7823. ShoutError("llRefreshPrimURL - not yet supported");
  7824. ScriptSleep(20000);
  7825. }
  7826. public LSL_String llEscapeURL(string url)
  7827. {
  7828. m_host.AddScriptLPS(1);
  7829. try
  7830. {
  7831. return Uri.EscapeDataString(url);
  7832. }
  7833. catch (Exception ex)
  7834. {
  7835. return "llEscapeURL: " + ex.ToString();
  7836. }
  7837. }
  7838. public LSL_String llUnescapeURL(string url)
  7839. {
  7840. m_host.AddScriptLPS(1);
  7841. try
  7842. {
  7843. return Uri.UnescapeDataString(url);
  7844. }
  7845. catch (Exception ex)
  7846. {
  7847. return "llUnescapeURL: " + ex.ToString();
  7848. }
  7849. }
  7850. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  7851. {
  7852. m_host.AddScriptLPS(1);
  7853. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
  7854. if (detectedParams == null) return; // only works on the first detected avatar
  7855. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  7856. if (avatar != null)
  7857. {
  7858. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, simname,
  7859. new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
  7860. new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
  7861. }
  7862. ScriptSleep(1000);
  7863. }
  7864. public void llAddToLandBanList(string avatar, double hours)
  7865. {
  7866. m_host.AddScriptLPS(1);
  7867. UUID key;
  7868. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  7869. if (land.OwnerID == m_host.OwnerID)
  7870. {
  7871. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  7872. if (UUID.TryParse(avatar, out key))
  7873. {
  7874. entry.AgentID = key;
  7875. entry.Flags = AccessList.Ban;
  7876. entry.Time = DateTime.Now.AddHours(hours);
  7877. land.ParcelAccessList.Add(entry);
  7878. }
  7879. }
  7880. ScriptSleep(100);
  7881. }
  7882. public void llRemoveFromLandPassList(string avatar)
  7883. {
  7884. m_host.AddScriptLPS(1);
  7885. UUID key;
  7886. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  7887. if (land.OwnerID == m_host.OwnerID)
  7888. {
  7889. if (UUID.TryParse(avatar, out key))
  7890. {
  7891. foreach (ParcelManager.ParcelAccessEntry entry in land.ParcelAccessList)
  7892. {
  7893. if (entry.AgentID == key && entry.Flags == AccessList.Access)
  7894. {
  7895. land.ParcelAccessList.Remove(entry);
  7896. break;
  7897. }
  7898. }
  7899. }
  7900. }
  7901. ScriptSleep(100);
  7902. }
  7903. public void llRemoveFromLandBanList(string avatar)
  7904. {
  7905. m_host.AddScriptLPS(1);
  7906. UUID key;
  7907. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  7908. if (land.OwnerID == m_host.OwnerID)
  7909. {
  7910. if (UUID.TryParse(avatar, out key))
  7911. {
  7912. foreach (ParcelManager.ParcelAccessEntry entry in land.ParcelAccessList)
  7913. {
  7914. if (entry.AgentID == key && entry.Flags == AccessList.Ban)
  7915. {
  7916. land.ParcelAccessList.Remove(entry);
  7917. break;
  7918. }
  7919. }
  7920. }
  7921. }
  7922. ScriptSleep(100);
  7923. }
  7924. public void llSetCameraParams(LSL_List rules)
  7925. {
  7926. m_host.AddScriptLPS(1);
  7927. // our key in the object we are in
  7928. UUID invItemID = InventorySelf();
  7929. if (invItemID == UUID.Zero) return;
  7930. // the object we are in
  7931. UUID objectID = m_host.ParentUUID;
  7932. if (objectID == UUID.Zero) return;
  7933. UUID agentID;
  7934. lock (m_host.TaskInventory)
  7935. {
  7936. // we need the permission first, to know which avatar we want to set the camera for
  7937. agentID = m_host.TaskInventory[invItemID].PermsGranter;
  7938. if (agentID == UUID.Zero) return;
  7939. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
  7940. }
  7941. ScenePresence presence = World.GetScenePresence(agentID);
  7942. // we are not interested in child-agents
  7943. if (presence.IsChildAgent) return;
  7944. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  7945. object[] data = rules.Data;
  7946. for (int i = 0; i < data.Length; ++i) {
  7947. int type = Convert.ToInt32(data[i++].ToString());
  7948. if (i >= data.Length) break; // odd number of entries => ignore the last
  7949. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  7950. switch (type) {
  7951. case ScriptBaseClass.CAMERA_FOCUS:
  7952. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  7953. case ScriptBaseClass.CAMERA_POSITION:
  7954. LSL_Vector v = (LSL_Vector)data[i];
  7955. parameters.Add(type + 1, (float)v.x);
  7956. parameters.Add(type + 2, (float)v.y);
  7957. parameters.Add(type + 3, (float)v.z);
  7958. break;
  7959. default:
  7960. // TODO: clean that up as soon as the implicit casts are in
  7961. if (data[i] is LSL_Float)
  7962. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  7963. else if (data[i] is LSL_Integer)
  7964. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  7965. else parameters.Add(type, Convert.ToSingle(data[i]));
  7966. break;
  7967. }
  7968. }
  7969. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  7970. }
  7971. public void llClearCameraParams()
  7972. {
  7973. m_host.AddScriptLPS(1);
  7974. // our key in the object we are in
  7975. UUID invItemID=InventorySelf();
  7976. if (invItemID == UUID.Zero) return;
  7977. // the object we are in
  7978. UUID objectID = m_host.ParentUUID;
  7979. if (objectID == UUID.Zero) return;
  7980. // we need the permission first, to know which avatar we want to clear the camera for
  7981. UUID agentID;
  7982. lock (m_host.TaskInventory)
  7983. {
  7984. agentID = m_host.TaskInventory[invItemID].PermsGranter;
  7985. if (agentID == UUID.Zero) return;
  7986. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
  7987. }
  7988. ScenePresence presence = World.GetScenePresence(agentID);
  7989. // we are not interested in child-agents
  7990. if (presence.IsChildAgent) return;
  7991. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  7992. }
  7993. public LSL_Float llListStatistics(int operation, LSL_List src)
  7994. {
  7995. m_host.AddScriptLPS(1);
  7996. LSL_List nums = LSL_List.ToDoubleList(src);
  7997. switch (operation)
  7998. {
  7999. case ScriptBaseClass.LIST_STAT_RANGE:
  8000. return nums.Range();
  8001. case ScriptBaseClass.LIST_STAT_MIN:
  8002. return nums.Min();
  8003. case ScriptBaseClass.LIST_STAT_MAX:
  8004. return nums.Max();
  8005. case ScriptBaseClass.LIST_STAT_MEAN:
  8006. return nums.Mean();
  8007. case ScriptBaseClass.LIST_STAT_MEDIAN:
  8008. return nums.Median();
  8009. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  8010. return nums.NumericLength();
  8011. case ScriptBaseClass.LIST_STAT_STD_DEV:
  8012. return nums.StdDev();
  8013. case ScriptBaseClass.LIST_STAT_SUM:
  8014. return nums.Sum();
  8015. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  8016. return nums.SumSqrs();
  8017. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  8018. return nums.GeometricMean();
  8019. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  8020. return nums.HarmonicMean();
  8021. default:
  8022. return 0.0;
  8023. }
  8024. }
  8025. public LSL_Integer llGetUnixTime()
  8026. {
  8027. m_host.AddScriptLPS(1);
  8028. return Util.UnixTimeSinceEpoch();
  8029. }
  8030. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  8031. {
  8032. m_host.AddScriptLPS(1);
  8033. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  8034. }
  8035. public LSL_Integer llGetRegionFlags()
  8036. {
  8037. m_host.AddScriptLPS(1);
  8038. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  8039. if (estate == null)
  8040. return 67108864;
  8041. return (int)estate.GetRegionFlags();
  8042. }
  8043. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  8044. {
  8045. m_host.AddScriptLPS(1);
  8046. string ret = String.Empty;
  8047. string src1 = llBase64ToString(str1);
  8048. string src2 = llBase64ToString(str2);
  8049. int c = 0;
  8050. for (int i = 0; i < src1.Length; i++)
  8051. {
  8052. ret += (char) (src1[i] ^ src2[c]);
  8053. c++;
  8054. if (c >= src2.Length)
  8055. c = 0;
  8056. }
  8057. return llStringToBase64(ret);
  8058. }
  8059. public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
  8060. {
  8061. // Partial implementation: support for parameter flags needed
  8062. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  8063. // parameter flags support are implemented in ScriptsHttpRequests.cs
  8064. // in StartHttpRequest
  8065. m_host.AddScriptLPS(1);
  8066. IHttpRequestModule httpScriptMod =
  8067. m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  8068. List<string> param = new List<string>();
  8069. foreach (object o in parameters.Data)
  8070. {
  8071. param.Add(o.ToString());
  8072. }
  8073. Vector3 position = m_host.AbsolutePosition;
  8074. Vector3 velocity = m_host.Velocity;
  8075. Quaternion rotation = m_host.RotationOffset;
  8076. string ownerName = String.Empty;
  8077. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  8078. if (scenePresence == null)
  8079. ownerName = resolveName(m_host.OwnerID);
  8080. else
  8081. ownerName = scenePresence.Name;
  8082. RegionInfo regionInfo = World.RegionInfo;
  8083. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  8084. string shard = "OpenSim";
  8085. IConfigSource config = m_ScriptEngine.ConfigSource;
  8086. if (config.Configs["Network"] != null)
  8087. {
  8088. shard = config.Configs["Network"].GetString(
  8089. "user_server_url", "http://127.0.0.1:" + ConfigSettings.DefaultUserServerHttpPort.ToString());
  8090. shard = config.Configs["Network"].GetString("shard", shard);
  8091. }
  8092. httpHeaders["X-SecondLife-Shard"] = shard;
  8093. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  8094. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  8095. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  8096. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  8097. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  8098. 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);
  8099. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  8100. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  8101. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  8102. if (userAgent != null)
  8103. httpHeaders["User-Agent"] = userAgent;
  8104. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  8105. Regex r = new Regex(authregex);
  8106. int[] gnums = r.GetGroupNumbers();
  8107. Match m = r.Match(url);
  8108. if (m.Success) {
  8109. for (int i = 1; i < gnums.Length; i++) {
  8110. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  8111. //CaptureCollection cc = g.Captures;
  8112. }
  8113. if (m.Groups.Count == 5) {
  8114. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  8115. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  8116. }
  8117. }
  8118. UUID reqID = httpScriptMod.
  8119. StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body);
  8120. if (reqID != UUID.Zero)
  8121. return reqID.ToString();
  8122. else
  8123. return null;
  8124. }
  8125. public void llHTTPResponse(LSL_Key id, int status, string body)
  8126. {
  8127. // Partial implementation: support for parameter flags needed
  8128. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  8129. m_host.AddScriptLPS(1);
  8130. if (m_UrlModule != null)
  8131. m_UrlModule.HttpResponse(new UUID(id), status,body);
  8132. }
  8133. public void llResetLandBanList()
  8134. {
  8135. m_host.AddScriptLPS(1);
  8136. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  8137. if (land.OwnerID == m_host.OwnerID)
  8138. {
  8139. foreach (ParcelManager.ParcelAccessEntry entry in land.ParcelAccessList)
  8140. {
  8141. if (entry.Flags == AccessList.Ban)
  8142. {
  8143. land.ParcelAccessList.Remove(entry);
  8144. }
  8145. }
  8146. }
  8147. ScriptSleep(100);
  8148. }
  8149. public void llResetLandPassList()
  8150. {
  8151. m_host.AddScriptLPS(1);
  8152. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  8153. if (land.OwnerID == m_host.OwnerID)
  8154. {
  8155. foreach (ParcelManager.ParcelAccessEntry entry in land.ParcelAccessList)
  8156. {
  8157. if (entry.Flags == AccessList.Access)
  8158. {
  8159. land.ParcelAccessList.Remove(entry);
  8160. }
  8161. }
  8162. }
  8163. ScriptSleep(100);
  8164. }
  8165. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  8166. {
  8167. m_host.AddScriptLPS(1);
  8168. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  8169. if (land == null)
  8170. {
  8171. return 0;
  8172. }
  8173. else
  8174. {
  8175. if (sim_wide != 0)
  8176. {
  8177. if (category == 0)
  8178. {
  8179. return land.SimwidePrims;
  8180. }
  8181. else
  8182. {
  8183. //public int simwideArea = 0;
  8184. return 0;
  8185. }
  8186. }
  8187. else
  8188. {
  8189. if (category == 0)//Total Prims
  8190. {
  8191. return 0;//land.
  8192. }
  8193. else if (category == 1)//Owner Prims
  8194. {
  8195. return land.OwnerPrims;
  8196. }
  8197. else if (category == 2)//Group Prims
  8198. {
  8199. return land.GroupPrims;
  8200. }
  8201. else if (category == 3)//Other Prims
  8202. {
  8203. return land.OtherPrims;
  8204. }
  8205. else if (category == 4)//Selected
  8206. {
  8207. return land.SelectedPrims;
  8208. }
  8209. else if (category == 5)//Temp
  8210. {
  8211. return 0;//land.
  8212. }
  8213. }
  8214. }
  8215. return 0;
  8216. }
  8217. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  8218. {
  8219. m_host.AddScriptLPS(1);
  8220. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  8221. LSL_List ret = new LSL_List();
  8222. if (land != null)
  8223. {
  8224. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  8225. {
  8226. ret.Add(detectedParams.Key.ToString());
  8227. ret.Add(detectedParams.Value);
  8228. }
  8229. }
  8230. ScriptSleep(2000);
  8231. return ret;
  8232. }
  8233. public LSL_Integer llGetObjectPrimCount(string object_id)
  8234. {
  8235. m_host.AddScriptLPS(1);
  8236. SceneObjectPart part = World.GetSceneObjectPart(new UUID(object_id));
  8237. if (part == null)
  8238. {
  8239. return 0;
  8240. }
  8241. else
  8242. {
  8243. return part.ParentGroup.PrimCount;
  8244. }
  8245. }
  8246. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  8247. {
  8248. m_host.AddScriptLPS(1);
  8249. // Alondria: This currently just is utilizing the normal grid's 0.22 prims/m2 calculation
  8250. // Which probably will be irrelevent in OpenSim....
  8251. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  8252. float bonusfactor = (float)World.RegionInfo.RegionSettings.ObjectBonus;
  8253. if (land == null)
  8254. {
  8255. return 0;
  8256. }
  8257. if (sim_wide != 0)
  8258. {
  8259. decimal v = land.SimwideArea * (decimal)(0.22) * (decimal)bonusfactor;
  8260. return (int)v;
  8261. }
  8262. else
  8263. {
  8264. decimal v = land.Area * (decimal)(0.22) * (decimal)bonusfactor;
  8265. return (int)v;
  8266. }
  8267. }
  8268. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  8269. {
  8270. m_host.AddScriptLPS(1);
  8271. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  8272. if (land == null)
  8273. {
  8274. return new LSL_List(0);
  8275. }
  8276. LSL_List ret = new LSL_List();
  8277. foreach (object o in param.Data)
  8278. {
  8279. switch (o.ToString())
  8280. {
  8281. case "0":
  8282. ret = ret + new LSL_List(land.Name);
  8283. break;
  8284. case "1":
  8285. ret = ret + new LSL_List(land.Description);
  8286. break;
  8287. case "2":
  8288. ret = ret + new LSL_List(land.OwnerID.ToString());
  8289. break;
  8290. case "3":
  8291. ret = ret + new LSL_List(land.GroupID.ToString());
  8292. break;
  8293. case "4":
  8294. ret = ret + new LSL_List(land.Area);
  8295. break;
  8296. default:
  8297. ret = ret + new LSL_List(0);
  8298. break;
  8299. }
  8300. }
  8301. return ret;
  8302. }
  8303. public LSL_String llStringTrim(string src, int type)
  8304. {
  8305. m_host.AddScriptLPS(1);
  8306. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  8307. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  8308. if (type == (int)ScriptBaseClass.STRING_TRIM) { return src.Trim(); }
  8309. return src;
  8310. }
  8311. public LSL_List llGetObjectDetails(string id, LSL_List args)
  8312. {
  8313. m_host.AddScriptLPS(1);
  8314. LSL_List ret = new LSL_List();
  8315. UUID key = new UUID();
  8316. if (UUID.TryParse(id, out key))
  8317. {
  8318. ScenePresence av = World.GetScenePresence(key);
  8319. if (av != null)
  8320. {
  8321. foreach (object o in args.Data)
  8322. {
  8323. switch (o.ToString())
  8324. {
  8325. case "1":
  8326. ret.Add(av.Firstname + " " + av.Lastname);
  8327. break;
  8328. case "2":
  8329. ret.Add("");
  8330. break;
  8331. case "3":
  8332. ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  8333. break;
  8334. case "4":
  8335. ret.Add(new LSL_Rotation((double)av.Rotation.X, (double)av.Rotation.Y, (double)av.Rotation.Z, (double)av.Rotation.W));
  8336. break;
  8337. case "5":
  8338. ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z));
  8339. break;
  8340. case "6":
  8341. ret.Add(id);
  8342. break;
  8343. case "7":
  8344. ret.Add(UUID.Zero.ToString());
  8345. break;
  8346. case "8":
  8347. ret.Add(UUID.Zero.ToString());
  8348. break;
  8349. }
  8350. }
  8351. return ret;
  8352. }
  8353. SceneObjectPart obj = World.GetSceneObjectPart(key);
  8354. if (obj != null)
  8355. {
  8356. foreach (object o in args.Data)
  8357. {
  8358. switch (o.ToString())
  8359. {
  8360. case "1":
  8361. ret.Add(obj.Name);
  8362. break;
  8363. case "2":
  8364. ret.Add(obj.Description);
  8365. break;
  8366. case "3":
  8367. ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
  8368. break;
  8369. case "4":
  8370. ret.Add(new LSL_Rotation(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
  8371. break;
  8372. case "5":
  8373. ret.Add(new LSL_Vector(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
  8374. break;
  8375. case "6":
  8376. ret.Add(obj.OwnerID.ToString());
  8377. break;
  8378. case "7":
  8379. ret.Add(obj.GroupID.ToString());
  8380. break;
  8381. case "8":
  8382. ret.Add(obj.CreatorID.ToString());
  8383. break;
  8384. }
  8385. }
  8386. return ret;
  8387. }
  8388. }
  8389. return new LSL_List();
  8390. }
  8391. internal UUID ScriptByName(string name)
  8392. {
  8393. lock (m_host.TaskInventory)
  8394. {
  8395. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  8396. {
  8397. if (item.Type == 10 && item.Name == name)
  8398. return item.ItemID;
  8399. }
  8400. }
  8401. return UUID.Zero;
  8402. }
  8403. internal void ShoutError(string msg)
  8404. {
  8405. llShout(ScriptBaseClass.DEBUG_CHANNEL, msg);
  8406. }
  8407. internal void NotImplemented(string command)
  8408. {
  8409. if (throwErrorOnNotImplemented)
  8410. throw new NotImplementedException("Command not implemented: " + command);
  8411. }
  8412. internal void Deprecated(string command)
  8413. {
  8414. throw new Exception("Command deprecated: " + command);
  8415. }
  8416. internal void LSLError(string msg)
  8417. {
  8418. throw new Exception("LSL Runtime Error: " + msg);
  8419. }
  8420. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  8421. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  8422. {
  8423. World.AssetService.Get(assetID.ToString(), this,
  8424. delegate(string i, object sender, AssetBase a)
  8425. {
  8426. UUID uuid = UUID.Zero;
  8427. UUID.TryParse(i, out uuid);
  8428. cb(uuid, a);
  8429. });
  8430. }
  8431. public LSL_String llGetNumberOfNotecardLines(string name)
  8432. {
  8433. m_host.AddScriptLPS(1);
  8434. TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  8435. UUID assetID = UUID.Zero;
  8436. if (!UUID.TryParse(name, out assetID))
  8437. {
  8438. foreach (TaskInventoryItem item in itemsDictionary.Values)
  8439. {
  8440. if (item.Type == 7 && item.Name == name)
  8441. {
  8442. assetID = item.AssetID;
  8443. break;
  8444. }
  8445. }
  8446. }
  8447. if (assetID == UUID.Zero)
  8448. {
  8449. // => complain loudly, as specified by the LSL docs
  8450. ShoutError("Notecard '" + name + "' could not be found.");
  8451. return UUID.Zero.ToString();
  8452. }
  8453. // was: UUID tid = tid = AsyncCommands.
  8454. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString());
  8455. if (NotecardCache.IsCached(assetID))
  8456. {
  8457. AsyncCommands.
  8458. DataserverPlugin.DataserverReply(assetID.ToString(),
  8459. NotecardCache.GetLines(assetID).ToString());
  8460. ScriptSleep(100);
  8461. return tid.ToString();
  8462. }
  8463. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  8464. {
  8465. if (a == null || a.Type != 7)
  8466. {
  8467. ShoutError("Notecard '" + name + "' could not be found.");
  8468. return;
  8469. }
  8470. System.Text.UTF8Encoding enc =
  8471. new System.Text.UTF8Encoding();
  8472. string data = enc.GetString(a.Data);
  8473. //m_log.Debug(data);
  8474. NotecardCache.Cache(id, data);
  8475. AsyncCommands.
  8476. DataserverPlugin.DataserverReply(id.ToString(),
  8477. NotecardCache.GetLines(id).ToString());
  8478. });
  8479. ScriptSleep(100);
  8480. return tid.ToString();
  8481. }
  8482. public LSL_String llGetNotecardLine(string name, int line)
  8483. {
  8484. m_host.AddScriptLPS(1);
  8485. TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  8486. UUID assetID = UUID.Zero;
  8487. if (!UUID.TryParse(name, out assetID))
  8488. {
  8489. foreach (TaskInventoryItem item in itemsDictionary.Values)
  8490. {
  8491. if (item.Type == 7 && item.Name == name)
  8492. {
  8493. assetID = item.AssetID;
  8494. break;
  8495. }
  8496. }
  8497. }
  8498. if (assetID == UUID.Zero)
  8499. {
  8500. // => complain loudly, as specified by the LSL docs
  8501. ShoutError("Notecard '" + name + "' could not be found.");
  8502. return UUID.Zero.ToString();
  8503. }
  8504. // was: UUID tid = tid = AsyncCommands.
  8505. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString());
  8506. if (NotecardCache.IsCached(assetID))
  8507. {
  8508. AsyncCommands.DataserverPlugin.DataserverReply(assetID.ToString(),
  8509. NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  8510. ScriptSleep(100);
  8511. return tid.ToString();
  8512. }
  8513. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  8514. {
  8515. if (a == null || a.Type != 7)
  8516. {
  8517. ShoutError("Notecard '" + name + "' could not be found.");
  8518. return;
  8519. }
  8520. System.Text.UTF8Encoding enc =
  8521. new System.Text.UTF8Encoding();
  8522. string data = enc.GetString(a.Data);
  8523. //m_log.Debug(data);
  8524. NotecardCache.Cache(id, data);
  8525. AsyncCommands.DataserverPlugin.DataserverReply(id.ToString(),
  8526. NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax));
  8527. });
  8528. ScriptSleep(100);
  8529. return tid.ToString();
  8530. }
  8531. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  8532. {
  8533. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  8534. if (obj == null)
  8535. return;
  8536. if (obj.OwnerID != m_host.OwnerID)
  8537. return;
  8538. SetPrimParams(obj, rules);
  8539. }
  8540. public LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  8541. {
  8542. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  8543. if (obj == null)
  8544. return new LSL_List();
  8545. if (obj.OwnerID != m_host.OwnerID)
  8546. return new LSL_List();
  8547. return GetLinkPrimitiveParams(obj, rules);
  8548. }
  8549. }
  8550. public class NotecardCache
  8551. {
  8552. protected class Notecard
  8553. {
  8554. public string[] text;
  8555. public DateTime lastRef;
  8556. }
  8557. protected static Dictionary<UUID, Notecard> m_Notecards =
  8558. new Dictionary<UUID, Notecard>();
  8559. public static void Cache(UUID assetID, string text)
  8560. {
  8561. CacheCheck();
  8562. lock (m_Notecards)
  8563. {
  8564. if (m_Notecards.ContainsKey(assetID))
  8565. return;
  8566. Notecard nc = new Notecard();
  8567. nc.lastRef = DateTime.Now;
  8568. nc.text = SLUtil.ParseNotecardToList(text).ToArray();
  8569. m_Notecards[assetID] = nc;
  8570. }
  8571. }
  8572. public static bool IsCached(UUID assetID)
  8573. {
  8574. lock (m_Notecards)
  8575. {
  8576. return m_Notecards.ContainsKey(assetID);
  8577. }
  8578. }
  8579. public static int GetLines(UUID assetID)
  8580. {
  8581. if (!IsCached(assetID))
  8582. return -1;
  8583. lock (m_Notecards)
  8584. {
  8585. m_Notecards[assetID].lastRef = DateTime.Now;
  8586. return m_Notecards[assetID].text.Length;
  8587. }
  8588. }
  8589. public static string GetLine(UUID assetID, int line, int maxLength)
  8590. {
  8591. if (line < 0)
  8592. return "";
  8593. string data;
  8594. if (!IsCached(assetID))
  8595. return "";
  8596. lock (m_Notecards)
  8597. {
  8598. m_Notecards[assetID].lastRef = DateTime.Now;
  8599. if (line >= m_Notecards[assetID].text.Length)
  8600. return "\n\n\n";
  8601. data = m_Notecards[assetID].text[line];
  8602. if (data.Length > maxLength)
  8603. data = data.Substring(0, maxLength);
  8604. return data;
  8605. }
  8606. }
  8607. public static void CacheCheck()
  8608. {
  8609. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  8610. {
  8611. Notecard nc = m_Notecards[key];
  8612. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  8613. m_Notecards.Remove(key);
  8614. }
  8615. }
  8616. }
  8617. }