LSL_Api.cs 334 KB

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