LSL_ScriptCommands.cs 220 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474
  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 Axiom.Math;
  34. using libsecondlife;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.Environment;
  37. using OpenSim.Region.Environment.Interfaces;
  38. using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney;
  39. using OpenSim.Region.Environment.Modules.World.Land;
  40. using OpenSim.Region.Environment.Scenes;
  41. using OpenSim.Region.ScriptEngine.XEngine;
  42. using OpenSim.Region.ScriptEngine.XEngine.Script;
  43. namespace OpenSim.Region.ScriptEngine.XEngine
  44. {
  45. /// <summary>
  46. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  47. /// </summary>
  48. public class LSL_ScriptCommands : MarshalByRefObject, ILSL_ScriptCommands
  49. {
  50. // private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  51. internal XEngine m_ScriptEngine;
  52. internal XScriptInstance m_Instance;
  53. internal SceneObjectPart m_host;
  54. internal uint m_localID;
  55. internal LLUUID m_itemID;
  56. internal bool throwErrorOnNotImplemented = true;
  57. public LSL_ScriptCommands(XEngine ScriptEngine, XScriptInstance instance, SceneObjectPart host, uint localID, LLUUID itemID)
  58. {
  59. m_ScriptEngine = ScriptEngine;
  60. m_Instance = instance;
  61. m_host = host;
  62. m_localID = localID;
  63. m_itemID = itemID;
  64. //m_log.Info(ScriptEngineName, "LSL_BaseClass.Start() called. Hosted by [" + m_host.Name + ":" + m_host.UUID + "@" + m_host.AbsolutePosition + "]");
  65. }
  66. private DateTime m_timer = DateTime.Now;
  67. private string m_state = "default";
  68. private bool m_waitingForScriptAnswer=false;
  69. public string State
  70. {
  71. get { return m_Instance.State; }
  72. set { m_Instance.State = value; }
  73. }
  74. public void state(string newState)
  75. {
  76. m_Instance.SetState(newState);
  77. }
  78. // Object never expires
  79. public override Object InitializeLifetimeService()
  80. {
  81. //Console.WriteLine("LSL_BuiltIn_Commands: InitializeLifetimeService()");
  82. // return null;
  83. ILease lease = (ILease)base.InitializeLifetimeService();
  84. if (lease.CurrentState == LeaseState.Initial)
  85. {
  86. lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1);
  87. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
  88. // lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
  89. }
  90. return lease;
  91. }
  92. public Scene World
  93. {
  94. get { return m_ScriptEngine.World; }
  95. }
  96. public void llSay(int channelID, string text)
  97. {
  98. m_host.AddScriptLPS(1);
  99. if(text.Length > 1023)
  100. text=text.Substring(0, 1023);
  101. World.SimChat(Helpers.StringToField(text),
  102. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  103. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  104. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  105. }
  106. // Extension commands use this:
  107. public ICommander GetCommander(string name)
  108. {
  109. return World.GetCommander(name);
  110. }
  111. private LLUUID InventorySelf()
  112. {
  113. LLUUID invItemID=new LLUUID();
  114. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  115. {
  116. if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
  117. {
  118. invItemID=inv.Key;
  119. break;
  120. }
  121. }
  122. return invItemID;
  123. }
  124. private LLUUID InventoryKey(string name, int type)
  125. {
  126. m_host.AddScriptLPS(1);
  127. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  128. {
  129. if (inv.Value.Name == name)
  130. {
  131. if (inv.Value.Type != type)
  132. return LLUUID.Zero;
  133. return inv.Value.AssetID.ToString();
  134. }
  135. }
  136. return LLUUID.Zero;
  137. }
  138. private LLUUID InventoryKey(string name)
  139. {
  140. m_host.AddScriptLPS(1);
  141. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  142. {
  143. if (inv.Value.Name == name)
  144. {
  145. return inv.Value.AssetID.ToString();
  146. }
  147. }
  148. return LLUUID.Zero;
  149. }
  150. public void osSetRegionWaterHeight(double height)
  151. {
  152. m_host.AddScriptLPS(1);
  153. //Check to make sure that the script's owner is the estate manager/master
  154. //World.Permissions.GenericEstatePermission(
  155. if (World.ExternalChecks.ExternalChecksCanBeGodLike(m_host.OwnerID))
  156. {
  157. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  158. }
  159. }
  160. //These are the implementations of the various ll-functions used by the LSL scripts.
  161. //starting out, we use the System.Math library for trig functions. - ckrinke 8-14-07
  162. public double llSin(double f)
  163. {
  164. m_host.AddScriptLPS(1);
  165. return (double)Math.Sin(f);
  166. }
  167. public double llCos(double f)
  168. {
  169. m_host.AddScriptLPS(1);
  170. return (double)Math.Cos(f);
  171. }
  172. public double llTan(double f)
  173. {
  174. m_host.AddScriptLPS(1);
  175. return (double)Math.Tan(f);
  176. }
  177. public double llAtan2(double x, double y)
  178. {
  179. m_host.AddScriptLPS(1);
  180. return (double)Math.Atan2(y, x);
  181. }
  182. public double llSqrt(double f)
  183. {
  184. m_host.AddScriptLPS(1);
  185. return (double)Math.Sqrt(f);
  186. }
  187. public double llPow(double fbase, double fexponent)
  188. {
  189. m_host.AddScriptLPS(1);
  190. return (double)Math.Pow(fbase, fexponent);
  191. }
  192. public LSL_Types.LSLInteger llAbs(int i)
  193. {
  194. m_host.AddScriptLPS(1);
  195. return (int)Math.Abs(i);
  196. }
  197. public double llFabs(double f)
  198. {
  199. m_host.AddScriptLPS(1);
  200. return (double)Math.Abs(f);
  201. }
  202. public double llFrand(double mag)
  203. {
  204. m_host.AddScriptLPS(1);
  205. lock (Util.RandomClass)
  206. {
  207. return Util.RandomClass.NextDouble() * mag;
  208. }
  209. }
  210. public LSL_Types.LSLInteger llFloor(double f)
  211. {
  212. m_host.AddScriptLPS(1);
  213. return (int)Math.Floor(f);
  214. }
  215. public LSL_Types.LSLInteger llCeil(double f)
  216. {
  217. m_host.AddScriptLPS(1);
  218. return (int)Math.Ceiling(f);
  219. }
  220. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  221. public LSL_Types.LSLInteger llRound(double f)
  222. {
  223. m_host.AddScriptLPS(1);
  224. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  225. }
  226. //This next group are vector operations involving squaring and square root. ckrinke
  227. public double llVecMag(LSL_Types.Vector3 v)
  228. {
  229. m_host.AddScriptLPS(1);
  230. return LSL_Types.Vector3.Mag(v);
  231. }
  232. public LSL_Types.Vector3 llVecNorm(LSL_Types.Vector3 v)
  233. {
  234. m_host.AddScriptLPS(1);
  235. double mag = LSL_Types.Vector3.Mag(v);
  236. LSL_Types.Vector3 nor = new LSL_Types.Vector3();
  237. nor.x = v.x / mag;
  238. nor.y = v.y / mag;
  239. nor.z = v.z / mag;
  240. return nor;
  241. }
  242. public double llVecDist(LSL_Types.Vector3 a, LSL_Types.Vector3 b)
  243. {
  244. m_host.AddScriptLPS(1);
  245. double dx = a.x - b.x;
  246. double dy = a.y - b.y;
  247. double dz = a.z - b.z;
  248. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  249. }
  250. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  251. // Utility function for llRot2Euler
  252. // normalize an angle between 0 - 2*PI (0 and 360 degrees)
  253. private double NormalizeAngle(double angle)
  254. {
  255. angle = angle % (Math.PI * 2);
  256. if (angle < 0) angle = angle + Math.PI * 2;
  257. return angle;
  258. }
  259. // Old implementation of llRot2Euler, now normalized
  260. public LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r)
  261. {
  262. m_host.AddScriptLPS(1);
  263. //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke
  264. LSL_Types.Quaternion t = new LSL_Types.Quaternion(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s);
  265. double m = (t.x + t.y + t.z + t.s);
  266. if (m == 0) return new LSL_Types.Vector3();
  267. double n = 2 * (r.y * r.s + r.x * r.z);
  268. double p = m * m - n * n;
  269. if (p > 0)
  270. return new LSL_Types.Vector3(NormalizeAngle(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s))),
  271. NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))),
  272. NormalizeAngle(Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s))));
  273. else if (n > 0)
  274. return new LSL_Types.Vector3(0.0, Math.PI / 2, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
  275. else
  276. return new LSL_Types.Vector3(0.0, -Math.PI / 2, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
  277. }
  278. // Xantor's newer llEuler2Rot() *try the second* inverted quaternions (-x,-y,-z,w) as LL seems to like
  279. // New and improved, now actually works as described. Prim rotates as expected as does llRot2Euler.
  280. /* From wiki:
  281. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  282. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  283. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  284. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  285. */
  286. public LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v)
  287. {
  288. m_host.AddScriptLPS(1);
  289. double x,y,z,s,s_i;
  290. double cosX = Math.Cos(v.x);
  291. double cosY = Math.Cos(v.y);
  292. double cosZ = Math.Cos(v.z);
  293. double sinX = Math.Sin(v.x);
  294. double sinY = Math.Sin(v.y);
  295. double sinZ = Math.Sin(v.z);
  296. s = Math.Sqrt(cosY * cosZ - sinX * sinY * sinZ + cosX * cosZ + cosX * cosY + 1.0f) * 0.5f;
  297. if (Math.Abs(s) < 0.00001) // null rotation
  298. {
  299. x = 0.0f;
  300. y = 1.0f;
  301. z = 0.0f;
  302. }
  303. else
  304. {
  305. s_i = 1.0f / (4.0f * s);
  306. x = - (-sinX * cosY - cosX * sinY * sinZ - sinX * cosZ) * s_i;
  307. y = - (-cosX * sinY * cosZ + sinX * sinZ - sinY) * s_i;
  308. z = - (-cosY * sinZ - sinX * sinY * cosZ - cosX * sinZ) * s_i;
  309. }
  310. return new LSL_Types.Quaternion(x, y, z, s);
  311. }
  312. public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
  313. {
  314. m_host.AddScriptLPS(1);
  315. NotImplemented("llAxes2Rot");
  316. return new LSL_Types.Quaternion();
  317. }
  318. public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
  319. {
  320. m_host.AddScriptLPS(1);
  321. return (new LSL_Types.Vector3(1,0,0) * r);
  322. }
  323. public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r)
  324. {
  325. m_host.AddScriptLPS(1);
  326. return (new LSL_Types.Vector3(0, 1, 0) * r);
  327. }
  328. public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r)
  329. {
  330. m_host.AddScriptLPS(1);
  331. return (new LSL_Types.Vector3(0, 0, 1) * r);
  332. }
  333. public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b)
  334. {
  335. //A and B should both be normalized
  336. m_host.AddScriptLPS(1);
  337. double dotProduct = LSL_Types.Vector3.Dot(a, b);
  338. LSL_Types.Vector3 crossProduct = LSL_Types.Vector3.Cross(a, b);
  339. double magProduct = LSL_Types.Vector3.Mag(a) * LSL_Types.Vector3.Mag(b);
  340. double angle = Math.Acos(dotProduct / magProduct);
  341. LSL_Types.Vector3 axis = LSL_Types.Vector3.Norm(crossProduct);
  342. double s = Math.Sin(angle / 2);
  343. return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2));
  344. }
  345. public void llWhisper(int channelID, string text)
  346. {
  347. m_host.AddScriptLPS(1);
  348. if(text.Length > 1023)
  349. text=text.Substring(0, 1023);
  350. World.SimChat(Helpers.StringToField(text),
  351. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  352. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  353. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  354. }
  355. public void llShout(int channelID, string text)
  356. {
  357. m_host.AddScriptLPS(1);
  358. if(text.Length > 1023)
  359. text=text.Substring(0, 1023);
  360. World.SimChat(Helpers.StringToField(text),
  361. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  362. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  363. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  364. }
  365. public void llRegionSay(int channelID, string text)
  366. {
  367. if (channelID == 0)
  368. {
  369. LSLError("Cannot use llRegionSay() on channel 0");
  370. return;
  371. }
  372. if(text.Length > 1023)
  373. text=text.Substring(0, 1023);
  374. m_host.AddScriptLPS(1);
  375. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  376. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  377. }
  378. public LSL_Types.LSLInteger llListen(int channelID, string name, string ID, string msg)
  379. {
  380. m_host.AddScriptLPS(1);
  381. LLUUID keyID;
  382. LLUUID.TryParse(ID, out keyID);
  383. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  384. return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg);
  385. }
  386. public void llListenControl(int number, int active)
  387. {
  388. m_host.AddScriptLPS(1);
  389. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  390. wComm.ListenControl(m_itemID, number, active);
  391. }
  392. public void llListenRemove(int number)
  393. {
  394. m_host.AddScriptLPS(1);
  395. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  396. wComm.ListenRemove(m_itemID, number);
  397. }
  398. public void llSensor(string name, string id, int type, double range, double arc)
  399. {
  400. m_host.AddScriptLPS(1);
  401. LLUUID keyID = LLUUID.Zero;
  402. LLUUID.TryParse(id, out keyID);
  403. m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host);
  404. }
  405. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  406. {
  407. m_host.AddScriptLPS(1);
  408. LLUUID keyID = LLUUID.Zero;
  409. LLUUID.TryParse(id, out keyID);
  410. m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host);
  411. }
  412. public void llSensorRemove()
  413. {
  414. m_host.AddScriptLPS(1);
  415. m_ScriptEngine.m_ASYNCLSLCommandManager.m_SensorRepeat.UnSetSenseRepeaterEvents(m_localID, m_itemID);
  416. }
  417. public string resolveName(LLUUID objecUUID)
  418. {
  419. // try avatar username surname
  420. UserProfileData profile = World.CommsManager.UserService.GetUserProfile(objecUUID);
  421. if (profile != null)
  422. {
  423. string avatarname = profile.FirstName + " " + profile.SurName;
  424. return avatarname;
  425. }
  426. // try an scene object
  427. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  428. if (SOP != null)
  429. {
  430. string objectname = SOP.Name;
  431. return objectname;
  432. }
  433. EntityBase SensedObject;
  434. lock (World.Entities)
  435. {
  436. World.Entities.TryGetValue(objecUUID, out SensedObject);
  437. }
  438. if (SensedObject == null)
  439. return String.Empty;
  440. return SensedObject.Name;
  441. }
  442. public string llDetectedName(int number)
  443. {
  444. m_host.AddScriptLPS(1);
  445. LLUUID sensedUUID = m_ScriptEngine.GetDetectID(m_itemID, number);
  446. if(sensedUUID != null)
  447. return resolveName(sensedUUID);
  448. return String.Empty;
  449. }
  450. public LLUUID uuidDetectedKey(int number)
  451. {
  452. return m_ScriptEngine.GetDetectID(m_itemID, number);
  453. }
  454. public EntityBase entityDetectedKey(int number)
  455. {
  456. LLUUID sensedUUID = m_ScriptEngine.GetDetectID(m_itemID, number);
  457. if(sensedUUID != null)
  458. {
  459. EntityBase SensedObject = null;
  460. lock (World.Entities)
  461. {
  462. World.Entities.TryGetValue(sensedUUID, out SensedObject);
  463. }
  464. return SensedObject;
  465. }
  466. return null;
  467. }
  468. public string llDetectedKey(int number)
  469. {
  470. m_host.AddScriptLPS(1);
  471. LLUUID SensedUUID = uuidDetectedKey(number);
  472. if (SensedUUID == LLUUID.Zero)
  473. return String.Empty;
  474. return SensedUUID.ToString();
  475. }
  476. public string llDetectedOwner(int number)
  477. {
  478. // returns UUID of owner of object detected
  479. m_host.AddScriptLPS(1);
  480. EntityBase SensedObject = entityDetectedKey(number);
  481. if (SensedObject ==null)
  482. return String.Empty;
  483. LLUUID SensedUUID = uuidDetectedKey(number);
  484. if (World.GetScenePresence(SensedUUID) == null)
  485. {
  486. // sensed object is not an avatar
  487. // so get the owner of the sensed object
  488. SceneObjectPart SOP = World.GetSceneObjectPart(SensedUUID);
  489. if (SOP != null) { return SOP.ObjectOwner.ToString(); }
  490. }
  491. else
  492. {
  493. // sensed object is an avatar, and so must be its own owner
  494. return SensedUUID.ToString();
  495. }
  496. return String.Empty;
  497. }
  498. public LSL_Types.LSLInteger llDetectedType(int number)
  499. {
  500. m_host.AddScriptLPS(1);
  501. EntityBase SensedObject = entityDetectedKey(number);
  502. if (SensedObject == null)
  503. return 0;
  504. int mask = 0;
  505. LLUUID SensedUUID = uuidDetectedKey(number);
  506. LSL_Types.Vector3 ZeroVector = new LSL_Types.Vector3(0, 0, 0);
  507. if (World.GetScenePresence(SensedUUID) != null) mask |= 0x01; // actor
  508. if (SensedObject.Velocity.Equals(ZeroVector))
  509. mask |= 0x04; // passive non-moving
  510. else
  511. mask |= 0x02; // active moving
  512. if (SensedObject is IScript) mask |= 0x08; // Scripted. It COULD have one hidden ...
  513. return mask;
  514. }
  515. public LSL_Types.Vector3 llDetectedPos(int number)
  516. {
  517. m_host.AddScriptLPS(1);
  518. EntityBase SensedObject = entityDetectedKey(number);
  519. if (SensedObject == null)
  520. return new LSL_Types.Vector3(0, 0, 0);
  521. return new LSL_Types.Vector3(SensedObject.AbsolutePosition.X,SensedObject.AbsolutePosition.Y,SensedObject.AbsolutePosition.Z);
  522. }
  523. public LSL_Types.Vector3 llDetectedVel(int number)
  524. {
  525. m_host.AddScriptLPS(1);
  526. EntityBase SensedObject = entityDetectedKey(number);
  527. if (SensedObject == null)
  528. return new LSL_Types.Vector3(0, 0, 0);
  529. return new LSL_Types.Vector3(SensedObject.Velocity.X, SensedObject.Velocity.Y, SensedObject.Velocity.Z);
  530. // return new LSL_Types.Vector3();
  531. }
  532. public LSL_Types.Vector3 llDetectedGrab(int number)
  533. {
  534. m_host.AddScriptLPS(1);
  535. XDetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number);
  536. return parms.OffsetPos;
  537. }
  538. public LSL_Types.Quaternion llDetectedRot(int number)
  539. {
  540. m_host.AddScriptLPS(1);
  541. EntityBase SensedObject = entityDetectedKey(number);
  542. if (SensedObject == null)
  543. return new LSL_Types.Quaternion();
  544. return new LSL_Types.Quaternion(SensedObject.Rotation.x, SensedObject.Rotation.y, SensedObject.Rotation.z, SensedObject.Rotation.w);
  545. }
  546. public LSL_Types.LSLInteger llDetectedGroup(int number)
  547. {
  548. m_host.AddScriptLPS(1);
  549. NotImplemented("llDetectedGroup");
  550. return 0;
  551. }
  552. public LSL_Types.LSLInteger llDetectedLinkNumber(int number)
  553. {
  554. m_host.AddScriptLPS(1);
  555. NotImplemented("llDetectedLinkNumber");
  556. return 0;
  557. }
  558. public void llDie()
  559. {
  560. m_host.AddScriptLPS(1);
  561. World.DeleteSceneObject(m_host.ParentGroup);
  562. }
  563. public double llGround(LSL_Types.Vector3 offset)
  564. {
  565. m_host.AddScriptLPS(1);
  566. int x = (int)(m_host.AbsolutePosition.X + offset.x);
  567. int y = (int)(m_host.AbsolutePosition.Y + offset.y);
  568. return World.GetLandHeight(x, y);
  569. }
  570. public double llCloud(LSL_Types.Vector3 offset)
  571. {
  572. m_host.AddScriptLPS(1);
  573. NotImplemented("llCloud");
  574. return 0;
  575. }
  576. public LSL_Types.Vector3 llWind(LSL_Types.Vector3 offset)
  577. {
  578. m_host.AddScriptLPS(1);
  579. NotImplemented("llWind");
  580. return new LSL_Types.Vector3();
  581. }
  582. public void llSetStatus(int status, int value)
  583. {
  584. m_host.AddScriptLPS(1);
  585. int statusrotationaxis = 0;
  586. if ((status & BuiltIn_Commands_BaseClass.STATUS_PHYSICS) == BuiltIn_Commands_BaseClass.STATUS_PHYSICS)
  587. {
  588. if (value == 1)
  589. m_host.ScriptSetPhysicsStatus(true);
  590. else
  591. m_host.ScriptSetPhysicsStatus(false);
  592. }
  593. if ((status & BuiltIn_Commands_BaseClass.STATUS_PHANTOM) == BuiltIn_Commands_BaseClass.STATUS_PHANTOM)
  594. {
  595. if (value == 1)
  596. m_host.ScriptSetPhantomStatus(true);
  597. else
  598. m_host.ScriptSetPhantomStatus(false);
  599. }
  600. if ((status & BuiltIn_Commands_BaseClass.STATUS_CAST_SHADOWS) == BuiltIn_Commands_BaseClass.STATUS_CAST_SHADOWS)
  601. {
  602. m_host.AddFlag(LLObject.ObjectFlags.CastShadows);
  603. }
  604. if ((status & BuiltIn_Commands_BaseClass.STATUS_ROTATE_X) == BuiltIn_Commands_BaseClass.STATUS_ROTATE_X)
  605. {
  606. statusrotationaxis |= BuiltIn_Commands_BaseClass.STATUS_ROTATE_X;
  607. }
  608. if ((status & BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y) == BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y)
  609. {
  610. statusrotationaxis |= BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y;
  611. }
  612. if ((status & BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z) == BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z)
  613. {
  614. statusrotationaxis |= BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z;
  615. }
  616. if ((status & BuiltIn_Commands_BaseClass.STATUS_BLOCK_GRAB) == BuiltIn_Commands_BaseClass.STATUS_BLOCK_GRAB)
  617. {
  618. NotImplemented("llSetStatus - STATUS_BLOCK_GRAB");
  619. }
  620. if ((status & BuiltIn_Commands_BaseClass.STATUS_DIE_AT_EDGE) == BuiltIn_Commands_BaseClass.STATUS_DIE_AT_EDGE)
  621. {
  622. if (value == 1)
  623. m_host.SetDieAtEdge(true);
  624. else
  625. m_host.SetDieAtEdge(false);
  626. }
  627. if ((status & BuiltIn_Commands_BaseClass.STATUS_RETURN_AT_EDGE) == BuiltIn_Commands_BaseClass.STATUS_RETURN_AT_EDGE)
  628. {
  629. NotImplemented("llSetStatus - STATUS_RETURN_AT_EDGE");
  630. }
  631. if ((status & BuiltIn_Commands_BaseClass.STATUS_SANDBOX) == BuiltIn_Commands_BaseClass.STATUS_SANDBOX)
  632. {
  633. NotImplemented("llSetStatus - STATUS_SANDBOX");
  634. }
  635. if (statusrotationaxis != 0)
  636. {
  637. m_host.SetAxisRotation(statusrotationaxis, value);
  638. }
  639. }
  640. public LSL_Types.LSLInteger llGetStatus(int status)
  641. {
  642. m_host.AddScriptLPS(1);
  643. // Console.WriteLine(m_host.UUID.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  644. switch (status)
  645. {
  646. case BuiltIn_Commands_BaseClass.STATUS_PHYSICS:
  647. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Physics) == (uint)LLObject.ObjectFlags.Physics)
  648. {
  649. return 1;
  650. }
  651. return 0;
  652. case BuiltIn_Commands_BaseClass.STATUS_PHANTOM:
  653. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Phantom) == (uint)LLObject.ObjectFlags.Phantom)
  654. {
  655. return 1;
  656. }
  657. return 0;
  658. case BuiltIn_Commands_BaseClass.STATUS_CAST_SHADOWS:
  659. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.CastShadows) == (uint)LLObject.ObjectFlags.CastShadows)
  660. {
  661. return 1;
  662. }
  663. return 0;
  664. case BuiltIn_Commands_BaseClass.STATUS_BLOCK_GRAB:
  665. NotImplemented("llGetStatus - STATUS_BLOCK_GRAB");
  666. return 0;
  667. case BuiltIn_Commands_BaseClass.STATUS_DIE_AT_EDGE:
  668. if (m_host.GetDieAtEdge())
  669. return 1;
  670. else
  671. return 0;
  672. case BuiltIn_Commands_BaseClass.STATUS_RETURN_AT_EDGE:
  673. NotImplemented("llGetStatus - STATUS_RETURN_AT_EDGE");
  674. return 0;
  675. case BuiltIn_Commands_BaseClass.STATUS_ROTATE_X:
  676. NotImplemented("llGetStatus - STATUS_ROTATE_X");
  677. return 0;
  678. case BuiltIn_Commands_BaseClass.STATUS_ROTATE_Y:
  679. NotImplemented("llGetStatus - STATUS_ROTATE_Y");
  680. return 0;
  681. case BuiltIn_Commands_BaseClass.STATUS_ROTATE_Z:
  682. NotImplemented("llGetStatus - STATUS_ROTATE_Z");
  683. return 0;
  684. case BuiltIn_Commands_BaseClass.STATUS_SANDBOX:
  685. NotImplemented("llGetStatus - STATUS_SANDBOX");
  686. return 0;
  687. }
  688. return 0;
  689. }
  690. public void llSetScale(LSL_Types.Vector3 scale)
  691. {
  692. m_host.AddScriptLPS(1);
  693. SetScale(m_host, scale);
  694. }
  695. private void SetScale(SceneObjectPart part, LSL_Types.Vector3 scale)
  696. {
  697. // TODO: this needs to trigger a persistance save as well
  698. LLVector3 tmp = part.Scale;
  699. tmp.X = (float)scale.x;
  700. tmp.Y = (float)scale.y;
  701. tmp.Z = (float)scale.z;
  702. part.Scale = tmp;
  703. part.SendFullUpdateToAllClients();
  704. }
  705. public LSL_Types.Vector3 llGetScale()
  706. {
  707. m_host.AddScriptLPS(1);
  708. return new LSL_Types.Vector3(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  709. }
  710. public void llSetColor(LSL_Types.Vector3 color, int face)
  711. {
  712. m_host.AddScriptLPS(1);
  713. SetColor(m_host, color, face);
  714. }
  715. private void SetColor(SceneObjectPart part, LSL_Types.Vector3 color, int face)
  716. {
  717. LLObject.TextureEntry tex = part.Shape.Textures;
  718. LLColor texcolor;
  719. if (face > -1)
  720. {
  721. texcolor = tex.CreateFace((uint)face).RGBA;
  722. texcolor.R = (float)Math.Abs(color.x - 1);
  723. texcolor.G = (float)Math.Abs(color.y - 1);
  724. texcolor.B = (float)Math.Abs(color.z - 1);
  725. tex.FaceTextures[face].RGBA = texcolor;
  726. part.UpdateTexture(tex);
  727. return;
  728. }
  729. else if (face == -1)
  730. {
  731. for (uint i = 0; i < 32; i++)
  732. {
  733. if (tex.FaceTextures[i] != null)
  734. {
  735. texcolor = tex.FaceTextures[i].RGBA;
  736. texcolor.R = (float)Math.Abs(color.x - 1);
  737. texcolor.G = (float)Math.Abs(color.y - 1);
  738. texcolor.B = (float)Math.Abs(color.z - 1);
  739. tex.FaceTextures[i].RGBA = texcolor;
  740. }
  741. texcolor = tex.DefaultTexture.RGBA;
  742. texcolor.R = (float)Math.Abs(color.x - 1);
  743. texcolor.G = (float)Math.Abs(color.y - 1);
  744. texcolor.B = (float)Math.Abs(color.z - 1);
  745. tex.DefaultTexture.RGBA = texcolor;
  746. }
  747. part.UpdateTexture(tex);
  748. return;
  749. }
  750. }
  751. public double llGetAlpha(int face)
  752. {
  753. m_host.AddScriptLPS(1);
  754. LLObject.TextureEntry tex = m_host.Shape.Textures;
  755. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  756. {
  757. return (double)((tex.DefaultTexture.RGBA.A * 255) / 255);
  758. }
  759. if (face > -1)
  760. {
  761. return (double)((tex.GetFace((uint)face).RGBA.A * 255) / 255);
  762. }
  763. return 0;
  764. }
  765. public void llSetAlpha(double alpha, int face)
  766. {
  767. m_host.AddScriptLPS(1);
  768. SetAlpha(m_host, alpha, face);
  769. }
  770. private void SetAlpha(SceneObjectPart part, double alpha, int face)
  771. {
  772. LLObject.TextureEntry tex = part.Shape.Textures;
  773. LLColor texcolor;
  774. if (face > -1)
  775. {
  776. texcolor = tex.CreateFace((uint)face).RGBA;
  777. texcolor.A = (float)Math.Abs(alpha - 1);
  778. tex.FaceTextures[face].RGBA = texcolor;
  779. part.UpdateTexture(tex);
  780. return;
  781. }
  782. else if (face == -1)
  783. {
  784. for (int i = 0; i < 32; i++)
  785. {
  786. if (tex.FaceTextures[i] != null)
  787. {
  788. texcolor = tex.FaceTextures[i].RGBA;
  789. texcolor.A = (float)Math.Abs(alpha - 1);
  790. tex.FaceTextures[i].RGBA = texcolor;
  791. }
  792. }
  793. texcolor = tex.DefaultTexture.RGBA;
  794. texcolor.A = (float)Math.Abs(alpha - 1);
  795. tex.DefaultTexture.RGBA = texcolor;
  796. part.UpdateTexture(tex);
  797. return;
  798. }
  799. }
  800. public LSL_Types.Vector3 llGetColor(int face)
  801. {
  802. m_host.AddScriptLPS(1);
  803. LLObject.TextureEntry tex = m_host.Shape.Textures;
  804. LLColor texcolor;
  805. LSL_Types.Vector3 rgb;
  806. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  807. {
  808. texcolor = tex.DefaultTexture.RGBA;
  809. rgb.x = (255 - (texcolor.R * 255)) / 255;
  810. rgb.y = (255 - (texcolor.G * 255)) / 255;
  811. rgb.z = (255 - (texcolor.B * 255)) / 255;
  812. return rgb;
  813. }
  814. if (face > -1)
  815. {
  816. texcolor = tex.GetFace((uint)face).RGBA;
  817. rgb.x = (255 - (texcolor.R * 255)) / 255;
  818. rgb.y = (255 - (texcolor.G * 255)) / 255;
  819. rgb.z = (255 - (texcolor.B * 255)) / 255;
  820. return rgb;
  821. }
  822. else
  823. {
  824. return new LSL_Types.Vector3();
  825. }
  826. }
  827. public void llSetTexture(string texture, int face)
  828. {
  829. m_host.AddScriptLPS(1);
  830. SetTexture(m_host, texture, face);
  831. }
  832. private void SetTexture(SceneObjectPart part, string texture, int face)
  833. {
  834. LLUUID textureID=new LLUUID();
  835. if (!LLUUID.TryParse(texture, out textureID))
  836. {
  837. textureID=InventoryKey(texture, (int)AssetType.Texture);
  838. }
  839. if (textureID == LLUUID.Zero)
  840. return;
  841. LLObject.TextureEntry tex = part.Shape.Textures;
  842. if (face > -1)
  843. {
  844. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  845. texface.TextureID = textureID;
  846. tex.FaceTextures[face] = texface;
  847. part.UpdateTexture(tex);
  848. return;
  849. }
  850. else if (face == -1)
  851. {
  852. for (uint i = 0; i < 32; i++)
  853. {
  854. if (tex.FaceTextures[i] != null)
  855. {
  856. tex.FaceTextures[i].TextureID = textureID;
  857. }
  858. }
  859. tex.DefaultTexture.TextureID = textureID;
  860. part.UpdateTexture(tex);
  861. return;
  862. }
  863. }
  864. public void llScaleTexture(double u, double v, int face)
  865. {
  866. m_host.AddScriptLPS(1);
  867. ScaleTexture(m_host, u, v, face);
  868. }
  869. private void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  870. {
  871. LLObject.TextureEntry tex = part.Shape.Textures;
  872. if (face > -1)
  873. {
  874. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  875. texface.RepeatU = (float)u;
  876. texface.RepeatV = (float)v;
  877. tex.FaceTextures[face] = texface;
  878. part.UpdateTexture(tex);
  879. return;
  880. }
  881. if (face == -1)
  882. {
  883. for (int i = 0; i < 32; i++)
  884. {
  885. if (tex.FaceTextures[i] != null)
  886. {
  887. tex.FaceTextures[i].RepeatU = (float)u;
  888. tex.FaceTextures[i].RepeatV = (float)v;
  889. }
  890. }
  891. tex.DefaultTexture.RepeatU = (float)u;
  892. tex.DefaultTexture.RepeatV = (float)v;
  893. part.UpdateTexture(tex);
  894. return;
  895. }
  896. }
  897. public void llOffsetTexture(double u, double v, int face)
  898. {
  899. m_host.AddScriptLPS(1);
  900. OffsetTexture(m_host, u, v, face);
  901. }
  902. private void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  903. {
  904. LLObject.TextureEntry tex = part.Shape.Textures;
  905. if (face > -1)
  906. {
  907. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  908. texface.OffsetU = (float)u;
  909. texface.OffsetV = (float)v;
  910. tex.FaceTextures[face] = texface;
  911. part.UpdateTexture(tex);
  912. return;
  913. }
  914. if (face == -1)
  915. {
  916. for (int i = 0; i < 32; i++)
  917. {
  918. if (tex.FaceTextures[i] != null)
  919. {
  920. tex.FaceTextures[i].OffsetU = (float)u;
  921. tex.FaceTextures[i].OffsetV = (float)v;
  922. }
  923. }
  924. tex.DefaultTexture.OffsetU = (float)u;
  925. tex.DefaultTexture.OffsetV = (float)v;
  926. part.UpdateTexture(tex);
  927. return;
  928. }
  929. }
  930. public void llRotateTexture(double rotation, int face)
  931. {
  932. m_host.AddScriptLPS(1);
  933. RotateTexture(m_host, rotation, face);
  934. }
  935. private void RotateTexture(SceneObjectPart part, double rotation, int face)
  936. {
  937. LLObject.TextureEntry tex = part.Shape.Textures;
  938. if (face > -1)
  939. {
  940. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  941. texface.Rotation = (float)rotation;
  942. tex.FaceTextures[face] = texface;
  943. part.UpdateTexture(tex);
  944. return;
  945. }
  946. if (face == -1)
  947. {
  948. for (int i = 0; i < 32; i++)
  949. {
  950. if (tex.FaceTextures[i] != null)
  951. {
  952. tex.FaceTextures[i].Rotation = (float)rotation;
  953. }
  954. }
  955. tex.DefaultTexture.Rotation = (float)rotation;
  956. part.UpdateTexture(tex);
  957. return;
  958. }
  959. }
  960. public string llGetTexture(int face)
  961. {
  962. m_host.AddScriptLPS(1);
  963. LLObject.TextureEntry tex = m_host.Shape.Textures;
  964. if (face == -1)
  965. {
  966. face = 0;
  967. }
  968. if (face > -1)
  969. {
  970. LLObject.TextureEntryFace texface;
  971. texface = tex.GetFace((uint)face);
  972. return texface.TextureID.ToString();
  973. }
  974. else
  975. {
  976. return String.Empty;
  977. }
  978. }
  979. public void llSetPos(LSL_Types.Vector3 pos)
  980. {
  981. m_host.AddScriptLPS(1);
  982. SetPos(m_host, pos);
  983. }
  984. private void SetPos(SceneObjectPart part, LSL_Types.Vector3 pos)
  985. {
  986. if (part.ParentID != 0)
  987. {
  988. part.UpdateOffSet(new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  989. }
  990. else
  991. {
  992. part.UpdateGroupPosition(new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  993. }
  994. }
  995. public LSL_Types.Vector3 llGetPos()
  996. {
  997. m_host.AddScriptLPS(1);
  998. return new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  999. m_host.AbsolutePosition.Y,
  1000. m_host.AbsolutePosition.Z);
  1001. }
  1002. public LSL_Types.Vector3 llGetLocalPos()
  1003. {
  1004. m_host.AddScriptLPS(1);
  1005. if (m_host.ParentID != 0)
  1006. {
  1007. return new LSL_Types.Vector3(m_host.OffsetPosition.X,
  1008. m_host.OffsetPosition.Y,
  1009. m_host.OffsetPosition.Z);
  1010. }
  1011. else
  1012. {
  1013. return new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  1014. m_host.AbsolutePosition.Y,
  1015. m_host.AbsolutePosition.Z);
  1016. }
  1017. }
  1018. public void llSetRot(LSL_Types.Quaternion rot)
  1019. {
  1020. m_host.AddScriptLPS(1);
  1021. SetRot(m_host, rot);
  1022. }
  1023. private void SetRot(SceneObjectPart part, LSL_Types.Quaternion rot)
  1024. {
  1025. part.UpdateRotation(new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s));
  1026. // Update rotation does not move the object in the physics scene if it's a linkset.
  1027. part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition;
  1028. }
  1029. public LSL_Types.Quaternion llGetRot()
  1030. {
  1031. m_host.AddScriptLPS(1);
  1032. LLQuaternion q = m_host.RotationOffset;
  1033. return new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
  1034. }
  1035. public LSL_Types.Quaternion llGetLocalRot()
  1036. {
  1037. m_host.AddScriptLPS(1);
  1038. return new LSL_Types.Quaternion(m_host.RotationOffset.X, m_host.RotationOffset.Y, m_host.RotationOffset.Z, m_host.RotationOffset.W);
  1039. }
  1040. public void llSetForce(LSL_Types.Vector3 force, int local)
  1041. {
  1042. m_host.AddScriptLPS(1);
  1043. NotImplemented("llSetForce");
  1044. }
  1045. public LSL_Types.Vector3 llGetForce()
  1046. {
  1047. m_host.AddScriptLPS(1);
  1048. NotImplemented("llGetForce");
  1049. return new LSL_Types.Vector3();
  1050. }
  1051. public LSL_Types.LSLInteger llTarget(LSL_Types.Vector3 position, double range)
  1052. {
  1053. m_host.AddScriptLPS(1);
  1054. return m_host.registerTargetWaypoint(new LLVector3((float)position.x, (float)position.y, (float)position.z), (float)range);
  1055. }
  1056. public void llTargetRemove(int number)
  1057. {
  1058. m_host.AddScriptLPS(1);
  1059. m_host.unregisterTargetWaypoint(number);
  1060. }
  1061. public LSL_Types.LSLInteger llRotTarget(LSL_Types.Quaternion rot, double error)
  1062. {
  1063. m_host.AddScriptLPS(1);
  1064. NotImplemented("llRotTarget");
  1065. return 0;
  1066. }
  1067. public void llRotTargetRemove(int number)
  1068. {
  1069. m_host.AddScriptLPS(1);
  1070. NotImplemented("llRotTargetRemove");
  1071. }
  1072. public void llMoveToTarget(LSL_Types.Vector3 target, double tau)
  1073. {
  1074. m_host.AddScriptLPS(1);
  1075. m_host.MoveToTarget(new LLVector3((float)target.x, (float)target.y, (float)target.z), (float)tau);
  1076. }
  1077. public void llStopMoveToTarget()
  1078. {
  1079. m_host.AddScriptLPS(1);
  1080. m_host.StopMoveToTarget();
  1081. }
  1082. public void llApplyImpulse(LSL_Types.Vector3 force, int local)
  1083. {
  1084. m_host.AddScriptLPS(1);
  1085. //No energy force yet
  1086. if (force.x > 20000)
  1087. force.x = 20000;
  1088. if (force.y > 20000)
  1089. force.y = 20000;
  1090. if (force.z > 20000)
  1091. force.z = 20000;
  1092. if (local == 1)
  1093. {
  1094. m_host.ApplyImpulse(new LLVector3((float)force.x, (float)force.y, (float)force.z), true);
  1095. }
  1096. else
  1097. {
  1098. m_host.ApplyImpulse(new LLVector3((float)force.x,(float)force.y,(float)force.z), false);
  1099. }
  1100. }
  1101. public void llApplyRotationalImpulse(LSL_Types.Vector3 force, int local)
  1102. {
  1103. m_host.AddScriptLPS(1);
  1104. NotImplemented("llApplyRotationalImpulse");
  1105. }
  1106. public void llSetTorque(LSL_Types.Vector3 torque, int local)
  1107. {
  1108. m_host.AddScriptLPS(1);
  1109. NotImplemented("llSetTorque");
  1110. }
  1111. public LSL_Types.Vector3 llGetTorque()
  1112. {
  1113. m_host.AddScriptLPS(1);
  1114. NotImplemented("llGetTorque");
  1115. return new LSL_Types.Vector3();
  1116. }
  1117. public void llSetForceAndTorque(LSL_Types.Vector3 force, LSL_Types.Vector3 torque, int local)
  1118. {
  1119. m_host.AddScriptLPS(1);
  1120. NotImplemented("llSetForceAndTorque");
  1121. }
  1122. public LSL_Types.Vector3 llGetVel()
  1123. {
  1124. m_host.AddScriptLPS(1);
  1125. return new LSL_Types.Vector3(m_host.Velocity.X, m_host.Velocity.Y, m_host.Velocity.Z);
  1126. }
  1127. public LSL_Types.Vector3 llGetAccel()
  1128. {
  1129. m_host.AddScriptLPS(1);
  1130. return new LSL_Types.Vector3(m_host.Acceleration.X, m_host.Acceleration.Y, m_host.Acceleration.Z);
  1131. }
  1132. public LSL_Types.Vector3 llGetOmega()
  1133. {
  1134. m_host.AddScriptLPS(1);
  1135. return new LSL_Types.Vector3(m_host.RotationalVelocity.X, m_host.RotationalVelocity.Y, m_host.RotationalVelocity.Z);
  1136. }
  1137. public double llGetTimeOfDay()
  1138. {
  1139. m_host.AddScriptLPS(1);
  1140. NotImplemented("llGetTimeOfDay");
  1141. return 0;
  1142. }
  1143. public double llGetWallclock()
  1144. {
  1145. m_host.AddScriptLPS(1);
  1146. return DateTime.Now.TimeOfDay.TotalSeconds;
  1147. }
  1148. public double llGetTime()
  1149. {
  1150. m_host.AddScriptLPS(1);
  1151. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1152. return (double)((ScriptTime.TotalMilliseconds / 1000)*World.TimeDilation);
  1153. }
  1154. public void llResetTime()
  1155. {
  1156. m_host.AddScriptLPS(1);
  1157. m_timer = DateTime.Now;
  1158. }
  1159. public double llGetAndResetTime()
  1160. {
  1161. m_host.AddScriptLPS(1);
  1162. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1163. m_timer = DateTime.Now;
  1164. return (double)((ScriptTime.TotalMilliseconds / 1000)*World.TimeDilation);
  1165. }
  1166. public void llSound()
  1167. {
  1168. m_host.AddScriptLPS(1);
  1169. // This function has been deprecated
  1170. // see http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSound
  1171. Deprecated("llSound");
  1172. }
  1173. public void llPlaySound(string sound, double volume)
  1174. {
  1175. m_host.AddScriptLPS(1);
  1176. m_host.SendSound(sound, volume, false, 0);
  1177. }
  1178. public void llLoopSound(string sound, double volume)
  1179. {
  1180. m_host.AddScriptLPS(1);
  1181. m_host.SendSound(sound, volume, false, 1);
  1182. }
  1183. public void llLoopSoundMaster(string sound, double volume)
  1184. {
  1185. m_host.AddScriptLPS(1);
  1186. NotImplemented("llLoopSoundMaster");
  1187. }
  1188. public void llLoopSoundSlave(string sound, double volume)
  1189. {
  1190. m_host.AddScriptLPS(1);
  1191. NotImplemented("llLoopSoundSlave");
  1192. }
  1193. public void llPlaySoundSlave(string sound, double volume)
  1194. {
  1195. m_host.AddScriptLPS(1);
  1196. NotImplemented("llPlaySoundSlave");
  1197. }
  1198. public void llTriggerSound(string sound, double volume)
  1199. {
  1200. m_host.AddScriptLPS(1);
  1201. m_host.SendSound(sound, volume, true, 0);
  1202. }
  1203. public void llStopSound()
  1204. {
  1205. m_host.AddScriptLPS(1);
  1206. m_host.SendSound(LLUUID.Zero.ToString(), 1.0, false, 2);
  1207. }
  1208. public void llPreloadSound(string sound)
  1209. {
  1210. m_host.AddScriptLPS(1);
  1211. m_host.PreloadSound(sound);
  1212. }
  1213. /// <summary>
  1214. /// Return a portion of the designated string bounded by
  1215. /// inclusive indices (start and end). As usual, the negative
  1216. /// indices, and the tolerance for out-of-bound values, makes
  1217. /// this more complicated than it might otherwise seem.
  1218. /// </summary>
  1219. public string llGetSubString(string src, int start, int end)
  1220. {
  1221. m_host.AddScriptLPS(1);
  1222. // Normalize indices (if negative).
  1223. // After normlaization they may still be
  1224. // negative, but that is now relative to
  1225. // the start, rather than the end, of the
  1226. // sequence.
  1227. if (start < 0)
  1228. {
  1229. start = src.Length+start;
  1230. }
  1231. if (end < 0)
  1232. {
  1233. end = src.Length+end;
  1234. }
  1235. // Conventional substring
  1236. if (start <= end)
  1237. {
  1238. // Implies both bounds are out-of-range.
  1239. if (end < 0 || start >= src.Length)
  1240. {
  1241. return String.Empty;
  1242. }
  1243. // If end is positive, then it directly
  1244. // corresponds to the lengt of the substring
  1245. // needed (plus one of course). BUT, it
  1246. // must be within bounds.
  1247. if (end >= src.Length)
  1248. {
  1249. end = src.Length-1;
  1250. }
  1251. if (start < 0)
  1252. {
  1253. return src.Substring(0,end+1);
  1254. }
  1255. // Both indices are positive
  1256. return src.Substring(start, (end+1) - start);
  1257. }
  1258. // Inverted substring (end < start)
  1259. else
  1260. {
  1261. // Implies both indices are below the
  1262. // lower bound. In the inverted case, that
  1263. // means the entire string will be returned
  1264. // unchanged.
  1265. if (start < 0)
  1266. {
  1267. return src;
  1268. }
  1269. // If both indices are greater than the upper
  1270. // bound the result may seem initially counter
  1271. // intuitive.
  1272. if (end >= src.Length)
  1273. {
  1274. return src;
  1275. }
  1276. if (end < 0)
  1277. {
  1278. if (start < src.Length)
  1279. {
  1280. return src.Substring(start);
  1281. }
  1282. else
  1283. {
  1284. return String.Empty;
  1285. }
  1286. }
  1287. else
  1288. {
  1289. if (start < src.Length)
  1290. {
  1291. return src.Substring(0,end+1) + src.Substring(start);
  1292. }
  1293. else
  1294. {
  1295. return src.Substring(0,end+1);
  1296. }
  1297. }
  1298. }
  1299. }
  1300. /// <summary>
  1301. /// Delete substring removes the specified substring bounded
  1302. /// by the inclusive indices start and end. Indices may be
  1303. /// negative (indicating end-relative) and may be inverted,
  1304. /// i.e. end < start.
  1305. /// </summary>
  1306. public string llDeleteSubString(string src, int start, int end)
  1307. {
  1308. m_host.AddScriptLPS(1);
  1309. // Normalize indices (if negative).
  1310. // After normlaization they may still be
  1311. // negative, but that is now relative to
  1312. // the start, rather than the end, of the
  1313. // sequence.
  1314. if (start < 0)
  1315. {
  1316. start = src.Length+start;
  1317. }
  1318. if (end < 0)
  1319. {
  1320. end = src.Length+end;
  1321. }
  1322. // Conventionally delimited substring
  1323. if (start <= end)
  1324. {
  1325. // If both bounds are outside of the existing
  1326. // string, then return unchanges.
  1327. if (end < 0 || start >= src.Length)
  1328. {
  1329. return src;
  1330. }
  1331. // At least one bound is in-range, so we
  1332. // need to clip the out-of-bound argument.
  1333. if (start < 0)
  1334. {
  1335. start = 0;
  1336. }
  1337. if (end >= src.Length)
  1338. {
  1339. end = src.Length-1;
  1340. }
  1341. return src.Remove(start,end-start+1);
  1342. }
  1343. // Inverted substring
  1344. else
  1345. {
  1346. // In this case, out of bounds means that
  1347. // the existing string is part of the cut.
  1348. if (start < 0 || end >= src.Length)
  1349. {
  1350. return String.Empty;
  1351. }
  1352. if (end > 0)
  1353. {
  1354. if (start < src.Length)
  1355. {
  1356. return src.Remove(start).Remove(0,end+1);
  1357. }
  1358. else
  1359. {
  1360. return src.Remove(0,end+1);
  1361. }
  1362. }
  1363. else
  1364. {
  1365. if (start < src.Length)
  1366. {
  1367. return src.Remove(start);
  1368. }
  1369. else
  1370. {
  1371. return src;
  1372. }
  1373. }
  1374. }
  1375. }
  1376. /// <summary>
  1377. /// Insert string inserts the specified string identified by src
  1378. /// at the index indicated by index. Index may be negative, in
  1379. /// which case it is end-relative. The index may exceed either
  1380. /// string bound, with the result being a concatenation.
  1381. /// </summary>
  1382. public string llInsertString(string dest, int index, string src)
  1383. {
  1384. m_host.AddScriptLPS(1);
  1385. // Normalize indices (if negative).
  1386. // After normlaization they may still be
  1387. // negative, but that is now relative to
  1388. // the start, rather than the end, of the
  1389. // sequence.
  1390. if (index < 0)
  1391. {
  1392. index = dest.Length+index;
  1393. // Negative now means it is less than the lower
  1394. // bound of the string.
  1395. if (index < 0)
  1396. {
  1397. return src+dest;
  1398. }
  1399. }
  1400. if (index >= dest.Length)
  1401. {
  1402. return dest+src;
  1403. }
  1404. // The index is in bounds.
  1405. // In this case the index refers to the index that will
  1406. // be assigned to the first character of the inserted string.
  1407. // So unlike the other string operations, we do not add one
  1408. // to get the correct string length.
  1409. return dest.Substring(0,index)+src+dest.Substring(index);
  1410. }
  1411. public string llToUpper(string src)
  1412. {
  1413. m_host.AddScriptLPS(1);
  1414. return src.ToUpper();
  1415. }
  1416. public string llToLower(string src)
  1417. {
  1418. m_host.AddScriptLPS(1);
  1419. return src.ToLower();
  1420. }
  1421. public LSL_Types.LSLInteger llGiveMoney(string destination, int amount)
  1422. {
  1423. LLUUID invItemID=InventorySelf();
  1424. if (invItemID == LLUUID.Zero)
  1425. return 0;
  1426. m_host.AddScriptLPS(1);
  1427. if (m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1428. return 0;
  1429. if ((m_host.TaskInventory[invItemID].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_DEBIT) == 0)
  1430. {
  1431. LSLError("No permissions to give money");
  1432. return 0;
  1433. }
  1434. LLUUID toID=new LLUUID();
  1435. if (!LLUUID.TryParse(destination, out toID))
  1436. {
  1437. LSLError("Bad key in llGiveMoney");
  1438. return 0;
  1439. }
  1440. IMoneyModule money=World.RequestModuleInterface<IMoneyModule>();
  1441. if (money == null)
  1442. {
  1443. NotImplemented("llGiveMoney");
  1444. return 0;
  1445. }
  1446. bool result=money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  1447. if (result)
  1448. return 1;
  1449. return 0;
  1450. }
  1451. public void llMakeExplosion()
  1452. {
  1453. m_host.AddScriptLPS(1);
  1454. NotImplemented("llMakeExplosion");
  1455. }
  1456. public void llMakeFountain()
  1457. {
  1458. m_host.AddScriptLPS(1);
  1459. NotImplemented("llMakeFountain");
  1460. }
  1461. public void llMakeSmoke()
  1462. {
  1463. m_host.AddScriptLPS(1);
  1464. NotImplemented("llMakeSmoke");
  1465. }
  1466. public void llMakeFire()
  1467. {
  1468. m_host.AddScriptLPS(1);
  1469. NotImplemented("llMakeFire");
  1470. }
  1471. public void llRezObject(string inventory, LSL_Types.Vector3 pos, LSL_Types.Vector3 vel, LSL_Types.Quaternion rot, int param)
  1472. {
  1473. m_host.AddScriptLPS(1);
  1474. //NotImplemented("llRezObject");
  1475. bool found = false;
  1476. // Instead of using return;, I'm using continue; because in our TaskInventory implementation
  1477. // it's possible to have two items with the same task inventory name.
  1478. // this is an easter egg of sorts.
  1479. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  1480. {
  1481. if (inv.Value.Name == inventory)
  1482. {
  1483. // make sure we're an object.
  1484. if (inv.Value.InvType != (int)InventoryType.Object)
  1485. {
  1486. llSay(0, "Unable to create requested object. Object is missing from database.");
  1487. continue;
  1488. }
  1489. LLVector3 llpos = new LLVector3((float)pos.x, (float)pos.y, (float)pos.z);
  1490. // test if we're further away then 10m
  1491. if (Util.GetDistanceTo(llpos, m_host.AbsolutePosition) > 10)
  1492. return; // wiki says, if it's further away then 10m, silently fail.
  1493. LLVector3 llvel = new LLVector3((float)vel.x, (float)vel.y, (float)vel.z);
  1494. // need the magnitude later
  1495. float velmag = (float)Util.GetMagnitude(llvel);
  1496. SceneObjectGroup new_group = World.RezObject(inv.Value, llpos, new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), llvel, param);
  1497. // If either of these are null, then there was an unknown error.
  1498. if (new_group == null)
  1499. continue;
  1500. if (new_group.RootPart == null)
  1501. continue;
  1502. // objects rezzed with this method are die_at_edge by default.
  1503. new_group.RootPart.SetDieAtEdge(true);
  1504. m_ScriptEngine.PostScriptEvent(m_itemID, new XEventParams(
  1505. "object_rez", new Object[] {
  1506. new LSL_Types.LSLString(
  1507. new_group.RootPart.UUID.ToString()) },
  1508. new XDetectParams[0]));
  1509. float groupmass = new_group.GetMass();
  1510. //Recoil.
  1511. llApplyImpulse(new LSL_Types.Vector3(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0);
  1512. found = true;
  1513. //script delay
  1514. System.Threading.Thread.Sleep((int)((groupmass * velmag) / 10));
  1515. break;
  1516. }
  1517. }
  1518. if (!found)
  1519. llSay(0, "Could not find object " + inventory);
  1520. }
  1521. public void llLookAt(LSL_Types.Vector3 target, double strength, double damping)
  1522. {
  1523. m_host.AddScriptLPS(1);
  1524. NotImplemented("llLookAt");
  1525. }
  1526. public void llStopLookAt()
  1527. {
  1528. m_host.AddScriptLPS(1);
  1529. NotImplemented("llStopLookAt");
  1530. }
  1531. public void llSetTimerEvent(double sec)
  1532. {
  1533. m_host.AddScriptLPS(1);
  1534. // Setting timer repeat
  1535. m_ScriptEngine.m_ASYNCLSLCommandManager.m_Timer.SetTimerEvent(m_localID, m_itemID, sec);
  1536. }
  1537. public void llSleep(double sec)
  1538. {
  1539. m_host.AddScriptLPS(1);
  1540. Thread.Sleep((int)(sec * 1000));
  1541. }
  1542. public double llGetMass()
  1543. {
  1544. m_host.AddScriptLPS(1);
  1545. return m_host.GetMass();
  1546. }
  1547. public void llCollisionFilter(string name, string id, int accept)
  1548. {
  1549. m_host.AddScriptLPS(1);
  1550. NotImplemented("llCollisionFilter");
  1551. }
  1552. public void llTakeControls(int controls, int accept, int pass_on)
  1553. {
  1554. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  1555. {
  1556. return;
  1557. }
  1558. if (m_host.TaskInventory[InventorySelf()].PermsGranter != LLUUID.Zero)
  1559. {
  1560. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[InventorySelf()].PermsGranter);
  1561. if (presence != null)
  1562. {
  1563. if ((m_host.TaskInventory[InventorySelf()].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  1564. {
  1565. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID);
  1566. }
  1567. }
  1568. }
  1569. m_host.AddScriptLPS(1);
  1570. //NotImplemented("llTakeControls");
  1571. }
  1572. public void llReleaseControls()
  1573. {
  1574. m_host.AddScriptLPS(1);
  1575. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  1576. {
  1577. return;
  1578. }
  1579. if (m_host.TaskInventory[InventorySelf()].PermsGranter != LLUUID.Zero)
  1580. {
  1581. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[InventorySelf()].PermsGranter);
  1582. if (presence != null)
  1583. {
  1584. if ((m_host.TaskInventory[InventorySelf()].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  1585. {
  1586. // Unregister controls from Presence
  1587. presence.UnRegisterControlEventsToScript(m_localID, m_itemID);
  1588. // Remove Take Control permission.
  1589. m_host.TaskInventory[InventorySelf()].PermsMask &= ~BuiltIn_Commands_BaseClass.PERMISSION_TAKE_CONTROLS;
  1590. }
  1591. }
  1592. }
  1593. }
  1594. public void llAttachToAvatar(int attachment)
  1595. {
  1596. m_host.AddScriptLPS(1);
  1597. NotImplemented("llAttachToAvatar");
  1598. }
  1599. public void llDetachFromAvatar()
  1600. {
  1601. m_host.AddScriptLPS(1);
  1602. NotImplemented("llDetachFromAvatar");
  1603. }
  1604. public void llTakeCamera()
  1605. {
  1606. m_host.AddScriptLPS(1);
  1607. NotImplemented("llTakeCamera");
  1608. }
  1609. public void llReleaseCamera()
  1610. {
  1611. m_host.AddScriptLPS(1);
  1612. NotImplemented("llReleaseCamera");
  1613. }
  1614. public string llGetOwner()
  1615. {
  1616. m_host.AddScriptLPS(1);
  1617. return m_host.ObjectOwner.ToString();
  1618. }
  1619. public void llInstantMessage(string user, string message)
  1620. {
  1621. m_host.AddScriptLPS(1);
  1622. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  1623. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  1624. // but I don't think we have a list of scenes available from here.
  1625. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  1626. // user is a UUID
  1627. // TODO: figure out values for client, fromSession, and imSessionID
  1628. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  1629. LLUUID friendTransactionID = LLUUID.Random();
  1630. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  1631. GridInstantMessage msg = new GridInstantMessage();
  1632. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.UUID;
  1633. msg.fromAgentSession = new Guid(friendTransactionID.ToString());// fromAgentSession.UUID;
  1634. msg.toAgentID = new Guid(user); // toAgentID.UUID;
  1635. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  1636. Console.WriteLine("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  1637. Console.WriteLine("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  1638. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  1639. //if (client != null)
  1640. //{
  1641. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  1642. //}
  1643. //else
  1644. //{
  1645. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  1646. //}
  1647. msg.message = message;
  1648. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  1649. msg.fromGroup = false;// fromGroup;
  1650. msg.offline = (byte)0; //offline;
  1651. msg.ParentEstateID = 0; //ParentEstateID;
  1652. msg.Position = new sLLVector3();// new sLLVector3(m_host.AbsolutePosition);
  1653. msg.RegionID = World.RegionInfo.RegionID.UUID;//RegionID.UUID;
  1654. msg.binaryBucket = new byte[0];// binaryBucket;
  1655. World.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
  1656. // NotImplemented("llInstantMessage");
  1657. }
  1658. public void llEmail(string address, string subject, string message)
  1659. {
  1660. m_host.AddScriptLPS(1);
  1661. NotImplemented("llEmail");
  1662. }
  1663. public void llGetNextEmail(string address, string subject)
  1664. {
  1665. m_host.AddScriptLPS(1);
  1666. NotImplemented("llGetNextEmail");
  1667. }
  1668. public string llGetKey()
  1669. {
  1670. m_host.AddScriptLPS(1);
  1671. return m_host.UUID.ToString();
  1672. }
  1673. public void llSetBuoyancy(double buoyancy)
  1674. {
  1675. m_host.AddScriptLPS(1);
  1676. if (m_host.ParentGroup != null)
  1677. {
  1678. if (m_host.ParentGroup.RootPart != null)
  1679. {
  1680. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  1681. }
  1682. }
  1683. }
  1684. public void llSetHoverHeight(double height, int water, double tau)
  1685. {
  1686. m_host.AddScriptLPS(1);
  1687. NotImplemented("llSetHoverHeight");
  1688. }
  1689. public void llStopHover()
  1690. {
  1691. m_host.AddScriptLPS(1);
  1692. NotImplemented("llStopHover");
  1693. }
  1694. public void llMinEventDelay(double delay)
  1695. {
  1696. m_host.AddScriptLPS(1);
  1697. NotImplemented("llMinEventDelay");
  1698. }
  1699. public void llSoundPreload()
  1700. {
  1701. m_host.AddScriptLPS(1);
  1702. NotImplemented("llSoundPreload");
  1703. }
  1704. public void llRotLookAt(LSL_Types.Quaternion target, double strength, double damping)
  1705. {
  1706. m_host.AddScriptLPS(1);
  1707. NotImplemented("llRotLookAt");
  1708. }
  1709. public LSL_Types.LSLInteger llStringLength(string str)
  1710. {
  1711. m_host.AddScriptLPS(1);
  1712. if (str.Length > 0)
  1713. {
  1714. return str.Length;
  1715. }
  1716. else
  1717. {
  1718. return 0;
  1719. }
  1720. }
  1721. public void llStartAnimation(string anim)
  1722. {
  1723. m_host.AddScriptLPS(1);
  1724. LLUUID invItemID=InventorySelf();
  1725. if (invItemID == LLUUID.Zero)
  1726. return;
  1727. if (m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1728. return;
  1729. if ((m_host.TaskInventory[invItemID].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  1730. {
  1731. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[invItemID].PermsGranter);
  1732. if (presence != null)
  1733. {
  1734. // Do NOT try to parse LLUUID, animations cannot be triggered by ID
  1735. LLUUID animID=InventoryKey(anim, (int)AssetType.Animation);
  1736. if (animID == LLUUID.Zero)
  1737. presence.AddAnimation(anim);
  1738. else
  1739. presence.AddAnimation(animID);
  1740. }
  1741. }
  1742. }
  1743. public void llStopAnimation(string anim)
  1744. {
  1745. m_host.AddScriptLPS(1);
  1746. LLUUID invItemID=InventorySelf();
  1747. if (invItemID == LLUUID.Zero)
  1748. return;
  1749. if (m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1750. return;
  1751. if ((m_host.TaskInventory[invItemID].PermsMask & BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  1752. {
  1753. LLUUID animID = new LLUUID();
  1754. if (!LLUUID.TryParse(anim, out animID))
  1755. {
  1756. animID=InventoryKey(anim);
  1757. }
  1758. if (animID == LLUUID.Zero)
  1759. return;
  1760. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[invItemID].PermsGranter);
  1761. if (presence != null)
  1762. {
  1763. if (animID == LLUUID.Zero)
  1764. presence.RemoveAnimation(anim);
  1765. else
  1766. presence.RemoveAnimation(animID);
  1767. }
  1768. }
  1769. }
  1770. public void llPointAt()
  1771. {
  1772. m_host.AddScriptLPS(1);
  1773. NotImplemented("llPointAt");
  1774. }
  1775. public void llStopPointAt()
  1776. {
  1777. m_host.AddScriptLPS(1);
  1778. NotImplemented("llStopPointAt");
  1779. }
  1780. public void llTargetOmega(LSL_Types.Vector3 axis, double spinrate, double gain)
  1781. {
  1782. m_host.AddScriptLPS(1);
  1783. m_host.RotationalVelocity = new LLVector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  1784. m_host.AngularVelocity = new LLVector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  1785. m_host.ScheduleTerseUpdate();
  1786. m_host.SendTerseUpdateToAllClients();
  1787. }
  1788. public LSL_Types.LSLInteger llGetStartParameter()
  1789. {
  1790. m_host.AddScriptLPS(1);
  1791. // NotImplemented("llGetStartParameter");
  1792. return m_host.ParentGroup.StartParameter;
  1793. }
  1794. public void llGodLikeRezObject(string inventory, LSL_Types.Vector3 pos)
  1795. {
  1796. m_host.AddScriptLPS(1);
  1797. NotImplemented("llGodLikeRezObject");
  1798. }
  1799. public void llRequestPermissions(string agent, int perm)
  1800. {
  1801. LLUUID agentID=new LLUUID();
  1802. if (!LLUUID.TryParse(agent, out agentID))
  1803. return;
  1804. LLUUID invItemID=InventorySelf();
  1805. if (invItemID == LLUUID.Zero)
  1806. return; // Not in a prim? How??
  1807. if (agentID == LLUUID.Zero || perm == 0) // Releasing permissions
  1808. {
  1809. m_host.TaskInventory[invItemID].PermsGranter=LLUUID.Zero;
  1810. m_host.TaskInventory[invItemID].PermsMask=0;
  1811. m_ScriptEngine.PostScriptEvent(m_itemID, new XEventParams(
  1812. "run_time_permissions", new Object[] {
  1813. new LSL_Types.LSLInteger(0) },
  1814. new XDetectParams[0]));
  1815. return;
  1816. }
  1817. m_host.AddScriptLPS(1);
  1818. if (m_host.ParentGroup.RootPart.m_IsAttachment && agent == m_host.ParentGroup.RootPart.m_attachedAvatar)
  1819. {
  1820. // When attached, certain permissions are implicit if requested from owner
  1821. int implicitPerms = BuiltIn_Commands_BaseClass.PERMISSION_TAKE_CONTROLS |
  1822. BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION |
  1823. BuiltIn_Commands_BaseClass.PERMISSION_ATTACH;
  1824. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  1825. {
  1826. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1827. m_host.TaskInventory[invItemID].PermsMask=perm;
  1828. m_ScriptEngine.PostScriptEvent(m_itemID, new XEventParams(
  1829. "run_time_permissions", new Object[] {
  1830. new LSL_Types.LSLInteger(perm) },
  1831. new XDetectParams[0]));
  1832. return;
  1833. }
  1834. }
  1835. else if (m_host.m_sitTargetAvatar == agentID) // Sitting avatar
  1836. {
  1837. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  1838. int implicitPerms = BuiltIn_Commands_BaseClass.PERMISSION_TRIGGER_ANIMATION |
  1839. BuiltIn_Commands_BaseClass.PERMISSION_TRACK_CAMERA;
  1840. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  1841. {
  1842. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1843. m_host.TaskInventory[invItemID].PermsMask=perm;
  1844. m_ScriptEngine.PostScriptEvent(m_itemID, new XEventParams(
  1845. "run_time_permissions", new Object[] {
  1846. new LSL_Types.LSLInteger(perm) },
  1847. new XDetectParams[0]));
  1848. return;
  1849. }
  1850. }
  1851. ScenePresence presence = World.GetScenePresence(agentID);
  1852. if (presence != null)
  1853. {
  1854. string ownerName=resolveName(m_host.ParentGroup.RootPart.OwnerID);
  1855. if (ownerName == String.Empty)
  1856. ownerName="(hippos)";
  1857. if (!m_waitingForScriptAnswer)
  1858. {
  1859. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1860. m_host.TaskInventory[invItemID].PermsMask=0;
  1861. presence.ControllingClient.OnScriptAnswer+=handleScriptAnswer;
  1862. m_waitingForScriptAnswer=true;
  1863. }
  1864. presence.ControllingClient.SendScriptQuestion(m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
  1865. return;
  1866. }
  1867. // Requested agent is not in range, refuse perms
  1868. m_ScriptEngine.PostScriptEvent(m_itemID, new XEventParams(
  1869. "run_time_permissions", new Object[] {
  1870. new LSL_Types.LSLInteger(0) },
  1871. new XDetectParams[0]));
  1872. }
  1873. void handleScriptAnswer(IClientAPI client, LLUUID taskID, LLUUID itemID, int answer)
  1874. {
  1875. if (taskID != m_host.UUID)
  1876. return;
  1877. LLUUID invItemID=InventorySelf();
  1878. if (invItemID == LLUUID.Zero)
  1879. return;
  1880. client.OnScriptAnswer-=handleScriptAnswer;
  1881. m_waitingForScriptAnswer=false;
  1882. m_host.TaskInventory[invItemID].PermsMask=answer;
  1883. m_ScriptEngine.PostScriptEvent(m_itemID, new XEventParams(
  1884. "run_time_permissions", new Object[] {
  1885. new LSL_Types.LSLInteger(answer) },
  1886. new XDetectParams[0]));
  1887. }
  1888. public string llGetPermissionsKey()
  1889. {
  1890. m_host.AddScriptLPS(1);
  1891. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1892. {
  1893. if (item.Type == 10 && item.ItemID == m_itemID)
  1894. {
  1895. return item.PermsGranter.ToString();
  1896. }
  1897. }
  1898. return LLUUID.Zero.ToString();
  1899. }
  1900. public LSL_Types.LSLInteger llGetPermissions()
  1901. {
  1902. m_host.AddScriptLPS(1);
  1903. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1904. {
  1905. if (item.Type == 10 && item.ItemID == m_itemID)
  1906. {
  1907. return item.PermsMask;
  1908. }
  1909. }
  1910. return 0;
  1911. }
  1912. public LSL_Types.LSLInteger llGetLinkNumber()
  1913. {
  1914. m_host.AddScriptLPS(1);
  1915. if (m_host.ParentGroup.Children.Count > 0)
  1916. {
  1917. return m_host.LinkNum + 1;
  1918. }
  1919. else
  1920. {
  1921. return 0;
  1922. }
  1923. }
  1924. public void llSetLinkColor(int linknumber, LSL_Types.Vector3 color, int face)
  1925. {
  1926. m_host.AddScriptLPS(1);
  1927. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  1928. if (linknumber > -1)
  1929. {
  1930. LLObject.TextureEntry tex = part.Shape.Textures;
  1931. LLColor texcolor;
  1932. if (face > -1)
  1933. {
  1934. texcolor = tex.CreateFace((uint)face).RGBA;
  1935. texcolor.R = (float)Math.Abs(color.x - 1);
  1936. texcolor.G = (float)Math.Abs(color.y - 1);
  1937. texcolor.B = (float)Math.Abs(color.z - 1);
  1938. tex.FaceTextures[face].RGBA = texcolor;
  1939. part.UpdateTexture(tex);
  1940. return;
  1941. }
  1942. else if (face == -1)
  1943. {
  1944. texcolor = tex.DefaultTexture.RGBA;
  1945. texcolor.R = (float)Math.Abs(color.x - 1);
  1946. texcolor.G = (float)Math.Abs(color.y - 1);
  1947. texcolor.B = (float)Math.Abs(color.z - 1);
  1948. tex.DefaultTexture.RGBA = texcolor;
  1949. for (uint i = 0; i < 32; i++)
  1950. {
  1951. if (tex.FaceTextures[i] != null)
  1952. {
  1953. texcolor = tex.FaceTextures[i].RGBA;
  1954. texcolor.R = (float)Math.Abs(color.x - 1);
  1955. texcolor.G = (float)Math.Abs(color.y - 1);
  1956. texcolor.B = (float)Math.Abs(color.z - 1);
  1957. tex.FaceTextures[i].RGBA = texcolor;
  1958. }
  1959. }
  1960. texcolor = tex.DefaultTexture.RGBA;
  1961. texcolor.R = (float)Math.Abs(color.x - 1);
  1962. texcolor.G = (float)Math.Abs(color.y - 1);
  1963. texcolor.B = (float)Math.Abs(color.z - 1);
  1964. tex.DefaultTexture.RGBA = texcolor;
  1965. part.UpdateTexture(tex);
  1966. return;
  1967. }
  1968. return;
  1969. }
  1970. else if (linknumber == -1)
  1971. {
  1972. int num = m_host.ParentGroup.PrimCount;
  1973. for (int w = 0; w < num; w++)
  1974. {
  1975. linknumber = w;
  1976. part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  1977. LLObject.TextureEntry tex = part.Shape.Textures;
  1978. LLColor texcolor;
  1979. if (face > -1)
  1980. {
  1981. texcolor = tex.CreateFace((uint)face).RGBA;
  1982. texcolor.R = (float)Math.Abs(color.x - 1);
  1983. texcolor.G = (float)Math.Abs(color.y - 1);
  1984. texcolor.B = (float)Math.Abs(color.z - 1);
  1985. tex.FaceTextures[face].RGBA = texcolor;
  1986. part.UpdateTexture(tex);
  1987. }
  1988. else if (face == -1)
  1989. {
  1990. texcolor = tex.DefaultTexture.RGBA;
  1991. texcolor.R = (float)Math.Abs(color.x - 1);
  1992. texcolor.G = (float)Math.Abs(color.y - 1);
  1993. texcolor.B = (float)Math.Abs(color.z - 1);
  1994. tex.DefaultTexture.RGBA = texcolor;
  1995. for (uint i = 0; i < 32; i++)
  1996. {
  1997. if (tex.FaceTextures[i] != null)
  1998. {
  1999. texcolor = tex.FaceTextures[i].RGBA;
  2000. texcolor.R = (float)Math.Abs(color.x - 1);
  2001. texcolor.G = (float)Math.Abs(color.y - 1);
  2002. texcolor.B = (float)Math.Abs(color.z - 1);
  2003. tex.FaceTextures[i].RGBA = texcolor;
  2004. }
  2005. }
  2006. texcolor = tex.DefaultTexture.RGBA;
  2007. texcolor.R = (float)Math.Abs(color.x - 1);
  2008. texcolor.G = (float)Math.Abs(color.y - 1);
  2009. texcolor.B = (float)Math.Abs(color.z - 1);
  2010. tex.DefaultTexture.RGBA = texcolor;
  2011. part.UpdateTexture(tex);
  2012. }
  2013. }
  2014. return;
  2015. }
  2016. }
  2017. public void llCreateLink(string target, int parent)
  2018. {
  2019. m_host.AddScriptLPS(1);
  2020. NotImplemented("llCreateLink");
  2021. }
  2022. public void llBreakLink(int linknum)
  2023. {
  2024. m_host.AddScriptLPS(1);
  2025. NotImplemented("llBreakLink");
  2026. }
  2027. public void llBreakAllLinks()
  2028. {
  2029. m_host.AddScriptLPS(1);
  2030. NotImplemented("llBreakAllLinks");
  2031. }
  2032. public string llGetLinkKey(int linknum)
  2033. {
  2034. m_host.AddScriptLPS(1);
  2035. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  2036. if (part != null)
  2037. {
  2038. return part.UUID.ToString();
  2039. }
  2040. else
  2041. {
  2042. return LLUUID.Zero.ToString();
  2043. }
  2044. }
  2045. public string llGetLinkName(int linknum)
  2046. {
  2047. m_host.AddScriptLPS(1);
  2048. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  2049. if (part != null)
  2050. {
  2051. return part.Name;
  2052. }
  2053. else
  2054. {
  2055. return LLUUID.Zero.ToString();
  2056. }
  2057. }
  2058. public LSL_Types.LSLInteger llGetInventoryNumber(int type)
  2059. {
  2060. m_host.AddScriptLPS(1);
  2061. int count = 0;
  2062. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2063. {
  2064. if (inv.Value.Type == type || type == -1)
  2065. {
  2066. count = count + 1;
  2067. }
  2068. }
  2069. return count;
  2070. }
  2071. public string llGetInventoryName(int type, int number)
  2072. {
  2073. m_host.AddScriptLPS(1);
  2074. ArrayList keys = new ArrayList();
  2075. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2076. {
  2077. if (inv.Value.Type == type || type == -1)
  2078. {
  2079. keys.Add(inv.Value.Name);
  2080. }
  2081. }
  2082. if (keys.Count == 0)
  2083. {
  2084. return String.Empty;
  2085. }
  2086. keys.Sort();
  2087. if (keys.Count > number)
  2088. {
  2089. return (string)keys[number];
  2090. }
  2091. return String.Empty;
  2092. }
  2093. public void llSetScriptState(string name, int run)
  2094. {
  2095. LLUUID item;
  2096. m_host.AddScriptLPS(1);
  2097. // These functions are supposed to be robust,
  2098. // so get the state one step at a time.
  2099. if ((item = ScriptByName(name)) != LLUUID.Zero)
  2100. {
  2101. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
  2102. }
  2103. else
  2104. {
  2105. ShoutError("llSetScriptState: script "+name+" not found");
  2106. }
  2107. }
  2108. public double llGetEnergy()
  2109. {
  2110. m_host.AddScriptLPS(1);
  2111. // TODO: figure out real energy value
  2112. return 1.0f;
  2113. }
  2114. public void llGiveInventory(string destination, string inventory)
  2115. {
  2116. m_host.AddScriptLPS(1);
  2117. NotImplemented("llGiveInventory");
  2118. }
  2119. public void llRemoveInventory(string item)
  2120. {
  2121. m_host.AddScriptLPS(1);
  2122. NotImplemented("llRemoveInventory");
  2123. }
  2124. public void llSetText(string text, LSL_Types.Vector3 color, double alpha)
  2125. {
  2126. m_host.AddScriptLPS(1);
  2127. Vector3 av3 = new Vector3((float)color.x, (float)color.y, (float)color.z);
  2128. m_host.SetText(text, av3, alpha);
  2129. }
  2130. public double llWater(LSL_Types.Vector3 offset)
  2131. {
  2132. m_host.AddScriptLPS(1);
  2133. return World.RegionInfo.EstateSettings.waterHeight;
  2134. }
  2135. public void llPassTouches(int pass)
  2136. {
  2137. m_host.AddScriptLPS(1);
  2138. NotImplemented("llPassTouches");
  2139. }
  2140. public string llRequestAgentData(string id, int data)
  2141. {
  2142. m_host.AddScriptLPS(1);
  2143. UserProfileData userProfile =
  2144. World.CommsManager.UserService.GetUserProfile(id);
  2145. string reply = String.Empty;
  2146. switch(data)
  2147. {
  2148. case 1: // DATA_ONLINE (0|1)
  2149. // TODO: implement fetching of this information
  2150. // if(userProfile.CurrentAgent.AgentOnline)
  2151. // reply = "1";
  2152. // else
  2153. reply = "0";
  2154. break;
  2155. case 2: // DATA_NAME (First Last)
  2156. reply = userProfile.FirstName+" "+userProfile.SurName;
  2157. break;
  2158. case 3: // DATA_BORN (YYYY-MM-DD)
  2159. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  2160. born = born.AddSeconds(userProfile.Created);
  2161. reply = born.ToString("yyyy-MM-dd");
  2162. break;
  2163. case 4: // DATA_RATING (0,0,0,0,0,0)
  2164. reply = "0,0,0,0,0,0";
  2165. break;
  2166. case 8: // DATA_PAYINFO (0|1|2|3)
  2167. reply = "0";
  2168. break;
  2169. default:
  2170. return LLUUID.Zero.ToString(); // Raise no event
  2171. }
  2172. LLUUID rq = LLUUID.Random();
  2173. LLUUID tid = m_ScriptEngine.m_ASYNCLSLCommandManager.
  2174. m_Dataserver.RegisterRequest(m_localID,
  2175. m_itemID, rq.ToString());
  2176. m_ScriptEngine.m_ASYNCLSLCommandManager.
  2177. m_Dataserver.DataserverReply(rq.ToString(), reply);
  2178. return tid.ToString();
  2179. }
  2180. public string llRequestInventoryData(string name)
  2181. {
  2182. m_host.AddScriptLPS(1);
  2183. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2184. {
  2185. if (item.Type == 3 && item.Name == name)
  2186. {
  2187. LLUUID tid = m_ScriptEngine.m_ASYNCLSLCommandManager.
  2188. m_Dataserver.RegisterRequest(m_localID,
  2189. m_itemID, item.AssetID.ToString());
  2190. LLVector3 region = new LLVector3(
  2191. World.RegionInfo.RegionLocX * Constants.RegionSize,
  2192. World.RegionInfo.RegionLocY * Constants.RegionSize,
  2193. 0);
  2194. World.AssetCache.GetAsset(item.AssetID,
  2195. delegate(LLUUID i, AssetBase a)
  2196. {
  2197. AssetLandmark lm = new AssetLandmark(a);
  2198. region += lm.Position;
  2199. string reply = region.ToString();
  2200. m_ScriptEngine.m_ASYNCLSLCommandManager.
  2201. m_Dataserver.DataserverReply(i.ToString(),
  2202. reply);
  2203. }, false);
  2204. return tid.ToString();
  2205. }
  2206. }
  2207. return String.Empty;
  2208. }
  2209. public void llSetDamage(double damage)
  2210. {
  2211. m_host.AddScriptLPS(1);
  2212. NotImplemented("llSetDamage");
  2213. }
  2214. public void llTeleportAgentHome(string agent)
  2215. {
  2216. m_host.AddScriptLPS(1);
  2217. NotImplemented("llTeleportAgentHome");
  2218. }
  2219. public void llModifyLand(int action, int brush)
  2220. {
  2221. m_host.AddScriptLPS(1);
  2222. World.ExternalChecks.ExternalChecksCanTerraformLand(m_host.OwnerID, new LLVector3(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, 0));
  2223. }
  2224. public void llCollisionSound(string impact_sound, double impact_volume)
  2225. {
  2226. m_host.AddScriptLPS(1);
  2227. NotImplemented("llCollisionSound");
  2228. }
  2229. public void llCollisionSprite(string impact_sprite)
  2230. {
  2231. m_host.AddScriptLPS(1);
  2232. NotImplemented("llCollisionSprite");
  2233. }
  2234. public string llGetAnimation(string id)
  2235. {
  2236. m_host.AddScriptLPS(1);
  2237. NotImplemented("llGetAnimation");
  2238. return String.Empty;
  2239. }
  2240. public void llResetScript()
  2241. {
  2242. m_host.AddScriptLPS(1);
  2243. m_ScriptEngine.ResetScript(m_itemID);
  2244. }
  2245. public void llMessageLinked(int linknum, int num, string msg, string id)
  2246. {
  2247. m_host.AddScriptLPS(1);
  2248. uint partLocalID;
  2249. LLUUID partItemID;
  2250. switch ((int)linknum)
  2251. {
  2252. case (int)BuiltIn_Commands_BaseClass.LINK_ROOT:
  2253. SceneObjectPart part = m_host.ParentGroup.RootPart;
  2254. foreach (TaskInventoryItem item in part.TaskInventory.Values)
  2255. {
  2256. if (item.Type == 10)
  2257. {
  2258. partLocalID = part.LocalId;
  2259. partItemID = item.ItemID;
  2260. object[] resobj = new object[]
  2261. {
  2262. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2263. };
  2264. m_ScriptEngine.PostScriptEvent(partItemID,
  2265. new XEventParams("link_message",
  2266. resobj, new XDetectParams[0]));
  2267. }
  2268. }
  2269. break;
  2270. case (int)BuiltIn_Commands_BaseClass.LINK_SET:
  2271. Console.WriteLine("LINK_SET");
  2272. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2273. {
  2274. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2275. {
  2276. if (item.Type == 10)
  2277. {
  2278. partLocalID = partInst.LocalId;
  2279. partItemID = item.ItemID;
  2280. Object[] resobj = new object[]
  2281. {
  2282. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2283. };
  2284. m_ScriptEngine.PostScriptEvent(partItemID,
  2285. new XEventParams("link_message",
  2286. resobj, new XDetectParams[0]));
  2287. }
  2288. }
  2289. }
  2290. break;
  2291. case (int)BuiltIn_Commands_BaseClass.LINK_ALL_OTHERS:
  2292. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2293. {
  2294. if (partInst.LocalId != m_host.LocalId)
  2295. {
  2296. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2297. {
  2298. if (item.Type == 10)
  2299. {
  2300. partLocalID = partInst.LocalId;
  2301. partItemID = item.ItemID;
  2302. Object[] resobj = new object[]
  2303. {
  2304. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2305. };
  2306. m_ScriptEngine.PostScriptEvent(partItemID,
  2307. new XEventParams("link_message",
  2308. resobj, new XDetectParams[0]));
  2309. }
  2310. }
  2311. }
  2312. }
  2313. break;
  2314. case (int)BuiltIn_Commands_BaseClass.LINK_ALL_CHILDREN:
  2315. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2316. {
  2317. if (partInst.LocalId != m_host.ParentGroup.RootPart.LocalId)
  2318. {
  2319. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2320. {
  2321. if (item.Type == 10)
  2322. {
  2323. partLocalID = partInst.LocalId;
  2324. partItemID = item.ItemID;
  2325. Object[] resobj = new object[]
  2326. {
  2327. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2328. };
  2329. m_ScriptEngine.PostScriptEvent(partItemID,
  2330. new XEventParams("link_message",
  2331. resobj, new XDetectParams[0]));
  2332. }
  2333. }
  2334. }
  2335. }
  2336. break;
  2337. case (int)BuiltIn_Commands_BaseClass.LINK_THIS:
  2338. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2339. {
  2340. if (item.Type == 10)
  2341. {
  2342. partItemID = item.ItemID;
  2343. object[] resobj = new object[]
  2344. {
  2345. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2346. };
  2347. m_ScriptEngine.PostScriptEvent(partItemID,
  2348. new XEventParams("link_message",
  2349. resobj, new XDetectParams[0]));
  2350. }
  2351. }
  2352. break;
  2353. default:
  2354. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2355. {
  2356. if ((partInst.LinkNum + 1) == linknum)
  2357. {
  2358. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2359. {
  2360. if (item.Type == 10)
  2361. {
  2362. partLocalID = partInst.LocalId;
  2363. partItemID = item.ItemID;
  2364. Object[] resObjDef = new object[]
  2365. {
  2366. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2367. };
  2368. m_ScriptEngine.PostScriptEvent(partItemID,
  2369. new XEventParams("link_message",
  2370. resObjDef, new XDetectParams[0]));
  2371. }
  2372. }
  2373. }
  2374. }
  2375. break;
  2376. }
  2377. }
  2378. public void llPushObject(string target, LSL_Types.Vector3 impulse, LSL_Types.Vector3 ang_impulse, int local)
  2379. {
  2380. m_host.AddScriptLPS(1);
  2381. NotImplemented("llPushObject");
  2382. }
  2383. public void llPassCollisions(int pass)
  2384. {
  2385. m_host.AddScriptLPS(1);
  2386. NotImplemented("llPassCollisions");
  2387. }
  2388. public string llGetScriptName()
  2389. {
  2390. string result = String.Empty;
  2391. m_host.AddScriptLPS(1);
  2392. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2393. {
  2394. if (item.Type == 10 && item.ItemID == m_itemID)
  2395. {
  2396. result = item.Name!=null?item.Name:String.Empty;
  2397. break;
  2398. }
  2399. }
  2400. return result;
  2401. }
  2402. public LSL_Types.LSLInteger llGetNumberOfSides()
  2403. {
  2404. m_host.AddScriptLPS(1);
  2405. NotImplemented("llGetNumberOfSides");
  2406. return 0;
  2407. }
  2408. /* The new / changed functions were tested with the following LSL script:
  2409. default
  2410. {
  2411. state_entry()
  2412. {
  2413. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  2414. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  2415. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  2416. // convert back and forth between quaternion <-> vector and angle
  2417. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  2418. llOwnerSay("Old rotation was: "+(string) rot);
  2419. llOwnerSay("re-converted rotation is: "+(string) newrot);
  2420. llSetRot(rot); // to check the parameters in the prim
  2421. }
  2422. }
  2423. */
  2424. // Xantor 29/apr/2008
  2425. // Returns rotation described by rotating angle radians about axis.
  2426. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  2427. public LSL_Types.Quaternion llAxisAngle2Rot(LSL_Types.Vector3 axis, double angle)
  2428. {
  2429. m_host.AddScriptLPS(1);
  2430. double x, y, z, s, t;
  2431. s = Math.Cos(angle / 2);
  2432. t = Math.Sin(angle / 2); // temp value to avoid 2 more sin() calcs
  2433. x = axis.x * t;
  2434. y = axis.y * t;
  2435. z = axis.z * t;
  2436. return new LSL_Types.Quaternion(x,y,z,s);
  2437. // NotImplemented("llAxisAngle2Rot");
  2438. }
  2439. // Xantor 29/apr/2008
  2440. // converts a Quaternion to X,Y,Z axis rotations
  2441. public LSL_Types.Vector3 llRot2Axis(LSL_Types.Quaternion rot)
  2442. {
  2443. m_host.AddScriptLPS(1);
  2444. double x,y,z;
  2445. if (rot.s > 1) // normalization needed
  2446. {
  2447. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  2448. rot.z * rot.z + rot.s * rot.s);
  2449. rot.x /= length;
  2450. rot.y /= length;
  2451. rot.z /= length;
  2452. rot.s /= length;
  2453. }
  2454. double angle = 2 * Math.Acos(rot.s);
  2455. double s = Math.Sqrt(1 - rot.s * rot.s);
  2456. if (s < 0.001)
  2457. {
  2458. x = 1;
  2459. y = z = 0;
  2460. }
  2461. else
  2462. {
  2463. x = rot.x / s; // normalise axis
  2464. y = rot.y / s;
  2465. z = rot.z / s;
  2466. }
  2467. return new LSL_Types.Vector3(x,y,z);
  2468. // NotImplemented("llRot2Axis");
  2469. }
  2470. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  2471. public double llRot2Angle(LSL_Types.Quaternion rot)
  2472. {
  2473. m_host.AddScriptLPS(1);
  2474. if (rot.s > 1) // normalization needed
  2475. {
  2476. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  2477. rot.z * rot.z + rot.s * rot.s);
  2478. rot.x /= length;
  2479. rot.y /= length;
  2480. rot.z /= length;
  2481. rot.s /= length;
  2482. }
  2483. double angle = 2 * Math.Acos(rot.s);
  2484. return angle;
  2485. // NotImplemented("llRot2Angle");
  2486. }
  2487. public double llAcos(double val)
  2488. {
  2489. m_host.AddScriptLPS(1);
  2490. return (double)Math.Acos(val);
  2491. }
  2492. public double llAsin(double val)
  2493. {
  2494. m_host.AddScriptLPS(1);
  2495. return (double)Math.Asin(val);
  2496. }
  2497. // Xantor 30/apr/2008
  2498. public double llAngleBetween(LSL_Types.Quaternion a, LSL_Types.Quaternion b)
  2499. {
  2500. m_host.AddScriptLPS(1);
  2501. return (double) Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2;
  2502. // NotImplemented("llAngleBetween");
  2503. }
  2504. public string llGetInventoryKey(string name)
  2505. {
  2506. m_host.AddScriptLPS(1);
  2507. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2508. {
  2509. if (inv.Value.Name == name)
  2510. {
  2511. if ((inv.Value.OwnerMask & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  2512. {
  2513. return inv.Value.AssetID.ToString();
  2514. }
  2515. else
  2516. {
  2517. return LLUUID.Zero.ToString();
  2518. }
  2519. }
  2520. }
  2521. return LLUUID.Zero.ToString();
  2522. }
  2523. public void llAllowInventoryDrop(int add)
  2524. {
  2525. m_host.AddScriptLPS(1);
  2526. NotImplemented("llAllowInventoryDrop");
  2527. }
  2528. public LSL_Types.Vector3 llGetSunDirection()
  2529. {
  2530. m_host.AddScriptLPS(1);
  2531. LSL_Types.Vector3 SunDoubleVector3;
  2532. LLVector3 SunFloatVector3;
  2533. // sunPosition estate setting is set in OpenSim.Region.Environment.Modules.SunModule
  2534. // have to convert from LLVector3 (float) to LSL_Types.Vector3 (double)
  2535. SunFloatVector3 = World.RegionInfo.EstateSettings.sunPosition;
  2536. SunDoubleVector3.x = (double)SunFloatVector3.X;
  2537. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  2538. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  2539. return SunDoubleVector3;
  2540. }
  2541. public LSL_Types.Vector3 llGetTextureOffset(int face)
  2542. {
  2543. m_host.AddScriptLPS(1);
  2544. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2545. LSL_Types.Vector3 offset;
  2546. if (face == -1)
  2547. {
  2548. face = 0;
  2549. }
  2550. offset.x = tex.GetFace((uint)face).OffsetU;
  2551. offset.y = tex.GetFace((uint)face).OffsetV;
  2552. offset.z = 0.0;
  2553. return offset;
  2554. }
  2555. public LSL_Types.Vector3 llGetTextureScale(int side)
  2556. {
  2557. m_host.AddScriptLPS(1);
  2558. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2559. LSL_Types.Vector3 scale;
  2560. if (side == -1)
  2561. {
  2562. side = 0;
  2563. }
  2564. scale.x = tex.GetFace((uint)side).RepeatU;
  2565. scale.y = tex.GetFace((uint)side).RepeatV;
  2566. scale.z = 0.0;
  2567. return scale;
  2568. }
  2569. public double llGetTextureRot(int face)
  2570. {
  2571. m_host.AddScriptLPS(1);
  2572. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2573. if (face == -1)
  2574. {
  2575. face = 0;
  2576. }
  2577. return tex.GetFace((uint)face).Rotation;
  2578. }
  2579. public LSL_Types.LSLInteger llSubStringIndex(string source, string pattern)
  2580. {
  2581. m_host.AddScriptLPS(1);
  2582. return source.IndexOf(pattern);
  2583. }
  2584. public string llGetOwnerKey(string id)
  2585. {
  2586. m_host.AddScriptLPS(1);
  2587. LLUUID key = new LLUUID();
  2588. if (LLUUID.TryParse(id, out key))
  2589. {
  2590. return World.GetSceneObjectPart(World.Entities[key].LocalId).OwnerID.ToString();
  2591. }
  2592. else
  2593. {
  2594. return LLUUID.Zero.ToString();
  2595. }
  2596. }
  2597. public LSL_Types.Vector3 llGetCenterOfMass()
  2598. {
  2599. m_host.AddScriptLPS(1);
  2600. NotImplemented("llGetCenterOfMass");
  2601. return new LSL_Types.Vector3();
  2602. }
  2603. public LSL_Types.list llListSort(LSL_Types.list src, int stride, int ascending)
  2604. {
  2605. m_host.AddScriptLPS(1);
  2606. return src.Sort(stride, ascending);
  2607. }
  2608. public LSL_Types.LSLInteger llGetListLength(LSL_Types.list src)
  2609. {
  2610. m_host.AddScriptLPS(1);
  2611. return src.Length;
  2612. }
  2613. public LSL_Types.LSLInteger llList2Integer(LSL_Types.list src, int index)
  2614. {
  2615. m_host.AddScriptLPS(1);
  2616. if (index < 0)
  2617. {
  2618. index = src.Length + index;
  2619. }
  2620. if (index >= src.Length)
  2621. {
  2622. return 0;
  2623. }
  2624. try
  2625. {
  2626. return Convert.ToInt32(src.Data[index]);
  2627. }
  2628. catch (FormatException)
  2629. {
  2630. return 0;
  2631. }
  2632. }
  2633. public double osList2Double(LSL_Types.list src, int index)
  2634. {
  2635. m_host.AddScriptLPS(1);
  2636. if (index < 0)
  2637. {
  2638. index = src.Length + index;
  2639. }
  2640. if (index >= src.Length)
  2641. {
  2642. return 0.0;
  2643. }
  2644. return Convert.ToDouble(src.Data[index]);
  2645. }
  2646. public double llList2Float(LSL_Types.list src, int index)
  2647. {
  2648. m_host.AddScriptLPS(1);
  2649. if (index < 0)
  2650. {
  2651. index = src.Length + index;
  2652. }
  2653. if (index >= src.Length)
  2654. {
  2655. return 0.0;
  2656. }
  2657. try
  2658. {
  2659. return Convert.ToDouble(src.Data[index]);
  2660. }
  2661. catch (FormatException)
  2662. {
  2663. return 0.0;
  2664. }
  2665. }
  2666. public string llList2String(LSL_Types.list src, int index)
  2667. {
  2668. m_host.AddScriptLPS(1);
  2669. if (index < 0)
  2670. {
  2671. index = src.Length + index;
  2672. }
  2673. if (index >= src.Length)
  2674. {
  2675. return String.Empty;
  2676. }
  2677. return src.Data[index].ToString();
  2678. }
  2679. public string llList2Key(LSL_Types.list src, int index)
  2680. {
  2681. m_host.AddScriptLPS(1);
  2682. if (index < 0)
  2683. {
  2684. index = src.Length + index;
  2685. }
  2686. if (index >= src.Length)
  2687. {
  2688. return "";
  2689. }
  2690. return src.Data[index].ToString();
  2691. }
  2692. public LSL_Types.Vector3 llList2Vector(LSL_Types.list src, int index)
  2693. {
  2694. m_host.AddScriptLPS(1);
  2695. if (index < 0)
  2696. {
  2697. index = src.Length + index;
  2698. }
  2699. if (index >= src.Length)
  2700. {
  2701. return new LSL_Types.Vector3(0, 0, 0);
  2702. }
  2703. if (src.Data[index].GetType() == typeof(LSL_Types.Vector3))
  2704. {
  2705. return (LSL_Types.Vector3)src.Data[index];
  2706. }
  2707. else
  2708. {
  2709. return new LSL_Types.Vector3(src.Data[index].ToString());
  2710. }
  2711. }
  2712. public LSL_Types.Quaternion llList2Rot(LSL_Types.list src, int index)
  2713. {
  2714. m_host.AddScriptLPS(1);
  2715. if (index < 0)
  2716. {
  2717. index = src.Length + index;
  2718. }
  2719. if (index >= src.Length)
  2720. {
  2721. return new LSL_Types.Quaternion(0, 0, 0, 1);
  2722. }
  2723. if (src.Data[index].GetType() == typeof(LSL_Types.Quaternion))
  2724. {
  2725. return (LSL_Types.Quaternion)src.Data[index];
  2726. }
  2727. else
  2728. {
  2729. return new LSL_Types.Quaternion(src.Data[index].ToString());
  2730. }
  2731. }
  2732. public LSL_Types.list llList2List(LSL_Types.list src, int start, int end)
  2733. {
  2734. m_host.AddScriptLPS(1);
  2735. return src.GetSublist(start, end);
  2736. }
  2737. public LSL_Types.list llDeleteSubList(LSL_Types.list src, int start, int end)
  2738. {
  2739. return src.DeleteSublist(end, start);
  2740. }
  2741. public LSL_Types.LSLInteger llGetListEntryType(LSL_Types.list src, int index)
  2742. {
  2743. m_host.AddScriptLPS(1);
  2744. if (index < 0)
  2745. {
  2746. index = src.Length + index;
  2747. }
  2748. if (index >= src.Length)
  2749. {
  2750. return 0;
  2751. }
  2752. if (src.Data[index] is Int32)
  2753. return 1;
  2754. if (src.Data[index] is Double)
  2755. return 2;
  2756. if (src.Data[index] is String)
  2757. {
  2758. LLUUID tuuid;
  2759. if (LLUUID.TryParse(src.Data[index].ToString(), out tuuid))
  2760. {
  2761. return 3;
  2762. }
  2763. else
  2764. {
  2765. return 4;
  2766. }
  2767. }
  2768. if (src.Data[index] is LSL_Types.Vector3)
  2769. return 5;
  2770. if (src.Data[index] is LSL_Types.Quaternion)
  2771. return 6;
  2772. if (src.Data[index] is LSL_Types.list)
  2773. return 7;
  2774. return 0;
  2775. }
  2776. /// <summary>
  2777. /// Process the supplied list and return the
  2778. /// content of the list formatted as a comma
  2779. /// separated list. There is a space after
  2780. /// each comma.
  2781. /// </summary>
  2782. public string llList2CSV(LSL_Types.list src)
  2783. {
  2784. string ret = String.Empty;
  2785. int x = 0;
  2786. m_host.AddScriptLPS(1);
  2787. if (src.Data.Length > 0)
  2788. {
  2789. ret = src.Data[x++].ToString();
  2790. for (; x < src.Data.Length; x++)
  2791. {
  2792. ret += ", "+src.Data[x].ToString();
  2793. }
  2794. }
  2795. return ret;
  2796. }
  2797. /// <summary>
  2798. /// The supplied string is scanned for commas
  2799. /// and converted into a list. Commas are only
  2800. /// effective if they are encountered outside
  2801. /// of '<' '>' delimiters. Any whitespace
  2802. /// before or after an element is trimmed.
  2803. /// </summary>
  2804. public LSL_Types.list llCSV2List(string src)
  2805. {
  2806. LSL_Types.list result = new LSL_Types.list();
  2807. int parens = 0;
  2808. int start = 0;
  2809. int length = 0;
  2810. m_host.AddScriptLPS(1);
  2811. for (int i = 0; i < src.Length; i++)
  2812. {
  2813. switch (src[i])
  2814. {
  2815. case '<' :
  2816. parens++;
  2817. length++;
  2818. break;
  2819. case '>' :
  2820. if (parens > 0)
  2821. parens--;
  2822. length++;
  2823. break;
  2824. case ',' :
  2825. if (parens == 0)
  2826. {
  2827. result.Add(src.Substring(start,length).Trim());
  2828. start += length+1;
  2829. length = 0;
  2830. } else
  2831. length++;
  2832. break;
  2833. default :
  2834. length++;
  2835. break;
  2836. }
  2837. }
  2838. result.Add(src.Substring(start,length).Trim());
  2839. return result;
  2840. }
  2841. /// <summary>
  2842. /// Randomizes the list, be arbitrarily reordering
  2843. /// sublists of stride elements. As the stride approaches
  2844. /// the size of the list, the options become very
  2845. /// limited.
  2846. /// </summary>
  2847. /// <remarks>
  2848. /// This could take a while for very large list
  2849. /// sizes.
  2850. /// </remarks>
  2851. public LSL_Types.list llListRandomize(LSL_Types.list src, int stride)
  2852. {
  2853. LSL_Types.list result;
  2854. Random rand = new Random();
  2855. int chunkk;
  2856. int[] chunks;
  2857. int index1;
  2858. int index2;
  2859. int tmp;
  2860. m_host.AddScriptLPS(1);
  2861. if (stride == 0)
  2862. stride = 1;
  2863. // Stride MUST be a factor of the list length
  2864. // If not, then return the src list. This also
  2865. // traps those cases where stride > length.
  2866. if (src.Length != stride && src.Length%stride == 0)
  2867. {
  2868. chunkk = src.Length/stride;
  2869. chunks = new int[chunkk];
  2870. for (int i = 0; i < chunkk; i++)
  2871. chunks[i] = i;
  2872. for (int i = 0; i < chunkk - 1; i++)
  2873. {
  2874. // randomly select 2 chunks
  2875. index1 = rand.Next(rand.Next(65536));
  2876. index1 = index1%chunkk;
  2877. index2 = rand.Next(rand.Next(65536));
  2878. index2 = index2%chunkk;
  2879. // and swap their relative positions
  2880. tmp = chunks[index1];
  2881. chunks[index1] = chunks[index2];
  2882. chunks[index2] = tmp;
  2883. }
  2884. // Construct the randomized list
  2885. result = new LSL_Types.list();
  2886. for (int i = 0; i < chunkk; i++)
  2887. {
  2888. for (int j = 0; j < stride; j++)
  2889. {
  2890. result.Add(src.Data[chunks[i]*stride+j]);
  2891. }
  2892. }
  2893. }
  2894. else {
  2895. object[] array = new object[src.Length];
  2896. Array.Copy(src.Data, 0, array, 0, src.Length);
  2897. result = new LSL_Types.list(array);
  2898. }
  2899. return result;
  2900. }
  2901. /// <summary>
  2902. /// Elements in the source list starting with 0 and then
  2903. /// every i+stride. If the stride is negative then the scan
  2904. /// is backwards producing an inverted result.
  2905. /// Only those elements that are also in the specified
  2906. /// range are included in the result.
  2907. /// </summary>
  2908. public LSL_Types.list llList2ListStrided(LSL_Types.list src, int start, int end, int stride)
  2909. {
  2910. LSL_Types.list result = new LSL_Types.list();
  2911. int[] si = new int[2];
  2912. int[] ei = new int[2];
  2913. bool twopass = false;
  2914. m_host.AddScriptLPS(1);
  2915. // First step is always to deal with negative indices
  2916. if (start < 0)
  2917. start = src.Length+start;
  2918. if (end < 0)
  2919. end = src.Length+end;
  2920. // Out of bounds indices are OK, just trim them
  2921. // accordingly
  2922. if (start > src.Length)
  2923. start = src.Length;
  2924. if (end > src.Length)
  2925. end = src.Length;
  2926. // There may be one or two ranges to be considered
  2927. if (start != end)
  2928. {
  2929. if (start <= end)
  2930. {
  2931. si[0] = start;
  2932. ei[0] = end;
  2933. }
  2934. else
  2935. {
  2936. si[1] = start;
  2937. ei[1] = src.Length;
  2938. si[0] = 0;
  2939. ei[0] = end;
  2940. twopass = true;
  2941. }
  2942. // The scan always starts from the beginning of the
  2943. // source list, but members are only selected if they
  2944. // fall within the specified sub-range. The specified
  2945. // range values are inclusive.
  2946. // A negative stride reverses the direction of the
  2947. // scan producing an inverted list as a result.
  2948. if (stride == 0)
  2949. stride = 1;
  2950. if (stride > 0)
  2951. {
  2952. for (int i = 0; i < src.Length; i += stride)
  2953. {
  2954. if (i<=ei[0] && i>=si[0])
  2955. result.Add(src.Data[i]);
  2956. if (twopass && i>=si[1] && i<=ei[1])
  2957. result.Add(src.Data[i]);
  2958. }
  2959. }
  2960. else if (stride < 0)
  2961. {
  2962. for (int i = src.Length - 1; i >= 0; i += stride)
  2963. {
  2964. if (i <= ei[0] && i >= si[0])
  2965. result.Add(src.Data[i]);
  2966. if (twopass && i >= si[1] && i <= ei[1])
  2967. result.Add(src.Data[i]);
  2968. }
  2969. }
  2970. }
  2971. return result;
  2972. }
  2973. public LSL_Types.Vector3 llGetRegionCorner()
  2974. {
  2975. m_host.AddScriptLPS(1);
  2976. return new LSL_Types.Vector3(World.RegionInfo.RegionLocX * Constants.RegionSize, World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
  2977. }
  2978. /// <summary>
  2979. /// Insert the list identified by <src> into the
  2980. /// list designated by <dest> such that the first
  2981. /// new element has the index specified by <index>
  2982. /// </summary>
  2983. public LSL_Types.list llListInsertList(LSL_Types.list dest, LSL_Types.list src, int index)
  2984. {
  2985. LSL_Types.list pref = null;
  2986. LSL_Types.list suff = null;
  2987. m_host.AddScriptLPS(1);
  2988. if (index < 0)
  2989. {
  2990. index = index+dest.Length;
  2991. if (index < 0)
  2992. {
  2993. index = 0;
  2994. }
  2995. }
  2996. if (index != 0)
  2997. {
  2998. pref = dest.GetSublist(0,index-1);
  2999. if (index < dest.Length)
  3000. {
  3001. suff = dest.GetSublist(index,-1);
  3002. return pref + src + suff;
  3003. }
  3004. else
  3005. {
  3006. return pref + src;
  3007. }
  3008. }
  3009. else
  3010. {
  3011. if (index < dest.Length)
  3012. {
  3013. suff = dest.GetSublist(index,-1);
  3014. return src + suff;
  3015. }
  3016. else
  3017. {
  3018. return src;
  3019. }
  3020. }
  3021. }
  3022. /// <summary>
  3023. /// Returns the index of the first occurrence of test
  3024. /// in src.
  3025. /// </summary>
  3026. public LSL_Types.LSLInteger llListFindList(LSL_Types.list src, LSL_Types.list test)
  3027. {
  3028. int index = -1;
  3029. int length = src.Length - test.Length + 1;
  3030. m_host.AddScriptLPS(1);
  3031. // If either list is empty, do not match
  3032. if (src.Length != 0 && test.Length != 0)
  3033. {
  3034. for (int i = 0; i < length; i++)
  3035. {
  3036. if (src.Data[i].Equals(test.Data[0]))
  3037. {
  3038. int j;
  3039. for (j = 1; j < test.Length; j++)
  3040. if (!src.Data[i+j].Equals(test.Data[j]))
  3041. break;
  3042. if (j == test.Length)
  3043. {
  3044. index = i;
  3045. break;
  3046. }
  3047. }
  3048. }
  3049. }
  3050. return index;
  3051. }
  3052. public string llGetObjectName()
  3053. {
  3054. m_host.AddScriptLPS(1);
  3055. return m_host.Name!=null?m_host.Name:String.Empty;
  3056. }
  3057. public void llSetObjectName(string name)
  3058. {
  3059. m_host.AddScriptLPS(1);
  3060. m_host.Name = name!=null?name:String.Empty;
  3061. }
  3062. public string llGetDate()
  3063. {
  3064. m_host.AddScriptLPS(1);
  3065. DateTime date = DateTime.Now.ToUniversalTime();
  3066. string result = date.ToString("yyyy-MM-dd");
  3067. return result;
  3068. }
  3069. public LSL_Types.LSLInteger llEdgeOfWorld(LSL_Types.Vector3 pos, LSL_Types.Vector3 dir)
  3070. {
  3071. m_host.AddScriptLPS(1);
  3072. NotImplemented("llEdgeOfWorld");
  3073. return 0;
  3074. }
  3075. public LSL_Types.LSLInteger llGetAgentInfo(string id)
  3076. {
  3077. m_host.AddScriptLPS(1);
  3078. NotImplemented("llGetAgentInfo");
  3079. return 0;
  3080. }
  3081. public void llAdjustSoundVolume(double volume)
  3082. {
  3083. m_host.AddScriptLPS(1);
  3084. m_host.AdjustSoundGain(volume);
  3085. }
  3086. public void llSetSoundQueueing(int queue)
  3087. {
  3088. m_host.AddScriptLPS(1);
  3089. NotImplemented("llSetSoundQueueing");
  3090. }
  3091. public void llSetSoundRadius(double radius)
  3092. {
  3093. m_host.AddScriptLPS(1);
  3094. NotImplemented("llSetSoundRadius");
  3095. }
  3096. public string llKey2Name(string id)
  3097. {
  3098. m_host.AddScriptLPS(1);
  3099. LLUUID key = new LLUUID();
  3100. if (LLUUID.TryParse(id,out key))
  3101. {
  3102. ScenePresence presence = World.GetScenePresence(key);
  3103. if (presence != null)
  3104. {
  3105. return presence.Name;
  3106. }
  3107. if (World.GetSceneObjectPart(key) != null)
  3108. {
  3109. return World.GetSceneObjectPart(key).Name;
  3110. }
  3111. }
  3112. return String.Empty;
  3113. }
  3114. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  3115. {
  3116. m_host.AddScriptLPS(1);
  3117. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  3118. pTexAnim.Flags =(uint) mode;
  3119. //ALL_SIDES
  3120. if (face == -1)
  3121. face = 255;
  3122. pTexAnim.Face = (uint)face;
  3123. pTexAnim.Length = (float)length;
  3124. pTexAnim.Rate = (float)rate;
  3125. pTexAnim.SizeX = (uint)sizex;
  3126. pTexAnim.SizeY = (uint)sizey;
  3127. pTexAnim.Start = (float)start;
  3128. m_host.AddTextureAnimation(pTexAnim);
  3129. m_host.SendFullUpdateToAllClients();
  3130. }
  3131. public void llTriggerSoundLimited(string sound, double volume, LSL_Types.Vector3 top_north_east,
  3132. LSL_Types.Vector3 bottom_south_west)
  3133. {
  3134. m_host.AddScriptLPS(1);
  3135. NotImplemented("llTriggerSoundLimited");
  3136. }
  3137. public void llEjectFromLand(string pest)
  3138. {
  3139. m_host.AddScriptLPS(1);
  3140. NotImplemented("llEjectFromLand");
  3141. }
  3142. public LSL_Types.list llParseString2List(string str, LSL_Types.list separators, LSL_Types.list spacers)
  3143. {
  3144. m_host.AddScriptLPS(1);
  3145. LSL_Types.list ret = new LSL_Types.list();
  3146. object[] delimiters = new object[separators.Length + spacers.Length];
  3147. separators.Data.CopyTo(delimiters, 0);
  3148. spacers.Data.CopyTo(delimiters, separators.Length);
  3149. bool dfound = false;
  3150. do
  3151. {
  3152. dfound = false;
  3153. int cindex = -1;
  3154. string cdeli = "";
  3155. for (int i = 0; i < delimiters.Length; i++)
  3156. {
  3157. int index = str.IndexOf(delimiters[i].ToString());
  3158. bool found = index != -1;
  3159. if (found)
  3160. {
  3161. if ((cindex > index) || (cindex == -1))
  3162. {
  3163. cindex = index;
  3164. cdeli = (string)delimiters[i];
  3165. }
  3166. dfound = dfound || found;
  3167. }
  3168. }
  3169. if (cindex != -1)
  3170. {
  3171. if (cindex > 0)
  3172. {
  3173. ret.Add(str.Substring(0, cindex));
  3174. if (spacers.Contains(cdeli))
  3175. {
  3176. ret.Add(cdeli);
  3177. }
  3178. }
  3179. if (cindex == 0 && spacers.Contains(cdeli))
  3180. {
  3181. ret.Add(cdeli);
  3182. }
  3183. str = str.Substring(cindex + cdeli.Length);
  3184. }
  3185. } while (dfound);
  3186. if (str != "")
  3187. {
  3188. ret.Add(str);
  3189. }
  3190. return ret;
  3191. }
  3192. public LSL_Types.LSLInteger llOverMyLand(string id)
  3193. {
  3194. m_host.AddScriptLPS(1);
  3195. LLUUID key = new LLUUID();
  3196. if (LLUUID.TryParse(id,out key))
  3197. {
  3198. SceneObjectPart obj = new SceneObjectPart();
  3199. obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  3200. if (obj.OwnerID == World.GetLandOwner(obj.AbsolutePosition.X, obj.AbsolutePosition.Y))
  3201. {
  3202. return 1;
  3203. }
  3204. else
  3205. {
  3206. return 0;
  3207. }
  3208. }
  3209. else
  3210. {
  3211. return 0;
  3212. }
  3213. }
  3214. public string llGetLandOwnerAt(LSL_Types.Vector3 pos)
  3215. {
  3216. m_host.AddScriptLPS(1);
  3217. return World.GetLandOwner((float)pos.x, (float)pos.y).ToString();
  3218. }
  3219. public LSL_Types.Vector3 llGetAgentSize(string id)
  3220. {
  3221. m_host.AddScriptLPS(1);
  3222. NotImplemented("llGetAgentSize");
  3223. return new LSL_Types.Vector3();
  3224. }
  3225. public LSL_Types.LSLInteger llSameGroup(string agent)
  3226. {
  3227. m_host.AddScriptLPS(1);
  3228. NotImplemented("llSameGroup");
  3229. return 0;
  3230. }
  3231. public void llUnSit(string id)
  3232. {
  3233. m_host.AddScriptLPS(1);
  3234. LLUUID key = new LLUUID();
  3235. if (LLUUID.TryParse(id, out key))
  3236. {
  3237. ScenePresence av = World.GetScenePresence(key);
  3238. if (av != null)
  3239. {
  3240. if (llAvatarOnSitTarget() == id)
  3241. {
  3242. // if the avatar is sitting on this object, then
  3243. // we can unsit them. We don't want random scripts unsitting random people
  3244. // Lets avoid the popcorn avatar scenario.
  3245. av.StandUp();
  3246. }
  3247. else
  3248. {
  3249. // If the object owner also owns the parcel
  3250. // or
  3251. // if the land is group owned and the object is group owned by the same group
  3252. // or
  3253. // if the object is owned by a person with estate access.
  3254. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition.X, av.AbsolutePosition.Y);
  3255. if (parcel != null)
  3256. {
  3257. if (m_host.ObjectOwner == parcel.landData.ownerID ||
  3258. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.landData.groupID
  3259. && parcel.landData.isGroupOwned) || World.ExternalChecks.ExternalChecksCanBeGodLike(m_host.OwnerID))
  3260. {
  3261. av.StandUp();
  3262. }
  3263. }
  3264. }
  3265. }
  3266. }
  3267. }
  3268. public LSL_Types.Vector3 llGroundSlope(LSL_Types.Vector3 offset)
  3269. {
  3270. m_host.AddScriptLPS(1);
  3271. NotImplemented("llGroundSlope");
  3272. return new LSL_Types.Vector3();
  3273. }
  3274. public LSL_Types.Vector3 llGroundNormal(LSL_Types.Vector3 offset)
  3275. {
  3276. m_host.AddScriptLPS(1);
  3277. NotImplemented("llGroundNormal");
  3278. return new LSL_Types.Vector3();
  3279. }
  3280. public LSL_Types.Vector3 llGroundContour(LSL_Types.Vector3 offset)
  3281. {
  3282. m_host.AddScriptLPS(1);
  3283. NotImplemented("llGroundContour");
  3284. return new LSL_Types.Vector3();
  3285. }
  3286. public LSL_Types.LSLInteger llGetAttached()
  3287. {
  3288. m_host.AddScriptLPS(1);
  3289. NotImplemented("llGetAttached");
  3290. return 0;
  3291. }
  3292. public LSL_Types.LSLInteger llGetFreeMemory()
  3293. {
  3294. m_host.AddScriptLPS(1);
  3295. NotImplemented("llGetFreeMemory");
  3296. return 0;
  3297. }
  3298. public string llGetRegionName()
  3299. {
  3300. m_host.AddScriptLPS(1);
  3301. return World.RegionInfo.RegionName;
  3302. }
  3303. public double llGetRegionTimeDilation()
  3304. {
  3305. m_host.AddScriptLPS(1);
  3306. return (double)World.TimeDilation;
  3307. }
  3308. public double llGetRegionFPS()
  3309. {
  3310. m_host.AddScriptLPS(1);
  3311. //TODO: return actual FPS
  3312. return 10.0f;
  3313. }
  3314. /* particle system rules should be coming into this routine as doubles, that is
  3315. rule[0] should be an integer from this list and rule[1] should be the arg
  3316. for the same integer. wiki.secondlife.com has most of this mapping, but some
  3317. came from http://www.caligari-designs.com/p4u2
  3318. We iterate through the list for 'Count' elements, incrementing by two for each
  3319. iteration and set the members of Primitive.ParticleSystem, one at a time.
  3320. */
  3321. public enum PrimitiveRule : int
  3322. {
  3323. PSYS_PART_FLAGS = 0,
  3324. PSYS_PART_START_COLOR = 1,
  3325. PSYS_PART_START_ALPHA = 2,
  3326. PSYS_PART_END_COLOR = 3,
  3327. PSYS_PART_END_ALPHA = 4,
  3328. PSYS_PART_START_SCALE = 5,
  3329. PSYS_PART_END_SCALE = 6,
  3330. PSYS_PART_MAX_AGE = 7,
  3331. PSYS_SRC_ACCEL = 8,
  3332. PSYS_SRC_PATTERN = 9,
  3333. PSYS_SRC_TEXTURE = 12,
  3334. PSYS_SRC_BURST_RATE = 13,
  3335. PSYS_SRC_BURST_PART_COUNT = 15,
  3336. PSYS_SRC_BURST_RADIUS = 16,
  3337. PSYS_SRC_BURST_SPEED_MIN = 17,
  3338. PSYS_SRC_BURST_SPEED_MAX = 18,
  3339. PSYS_SRC_MAX_AGE = 19,
  3340. PSYS_SRC_TARGET_KEY = 20,
  3341. PSYS_SRC_OMEGA = 21,
  3342. PSYS_SRC_ANGLE_BEGIN = 22,
  3343. PSYS_SRC_ANGLE_END = 23
  3344. }
  3345. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  3346. {
  3347. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  3348. return returnval;
  3349. }
  3350. public void llParticleSystem(LSL_Types.list rules)
  3351. {
  3352. m_host.AddScriptLPS(1);
  3353. Primitive.ParticleSystem prules = new Primitive.ParticleSystem();
  3354. LSL_Types.Vector3 tempv = new LSL_Types.Vector3();
  3355. float tempf = 0;
  3356. for (int i = 0; i < rules.Length; i += 2)
  3357. {
  3358. switch ((int)rules.Data[i])
  3359. {
  3360. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_FLAGS:
  3361. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)((uint)Convert.ToInt32(rules.Data[i + 1].ToString()));
  3362. break;
  3363. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_START_COLOR:
  3364. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3365. prules.PartStartColor.R = (float)tempv.x;
  3366. prules.PartStartColor.G = (float)tempv.y;
  3367. prules.PartStartColor.B = (float)tempv.z;
  3368. break;
  3369. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_START_ALPHA:
  3370. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3371. prules.PartStartColor.A = (float)tempf;
  3372. break;
  3373. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_END_COLOR:
  3374. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3375. //prules.PartEndColor = new LLColor(tempv.x,tempv.y,tempv.z,1);
  3376. prules.PartEndColor.R = (float)tempv.x;
  3377. prules.PartEndColor.G = (float)tempv.y;
  3378. prules.PartEndColor.B = (float)tempv.z;
  3379. break;
  3380. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_END_ALPHA:
  3381. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3382. prules.PartEndColor.A = (float)tempf;
  3383. break;
  3384. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_START_SCALE:
  3385. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3386. prules.PartStartScaleX = (float)tempv.x;
  3387. prules.PartStartScaleY = (float)tempv.y;
  3388. break;
  3389. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_END_SCALE:
  3390. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3391. prules.PartEndScaleX = (float)tempv.x;
  3392. prules.PartEndScaleY = (float)tempv.y;
  3393. break;
  3394. case (int)BuiltIn_Commands_BaseClass.PSYS_PART_MAX_AGE:
  3395. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3396. prules.PartMaxAge = (float)tempf;
  3397. break;
  3398. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_ACCEL:
  3399. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3400. prules.PartAcceleration.X = (float)tempv.x;
  3401. prules.PartAcceleration.Y = (float)tempv.y;
  3402. prules.PartAcceleration.Z = (float)tempv.z;
  3403. break;
  3404. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_PATTERN:
  3405. int tmpi = int.Parse(rules.Data[i + 1].ToString());
  3406. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  3407. break;
  3408. // Xantor 03-May-2008
  3409. // Wiki: PSYS_SRC_TEXTURE string inventory item name or key of the particle texture
  3410. // "" = default texture.
  3411. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_TEXTURE:
  3412. LLUUID tkey = LLUUID.Zero;
  3413. // if we can parse the string as a key, use it.
  3414. if (LLUUID.TryParse(rules.Data[i + 1].ToString(), out tkey))
  3415. {
  3416. prules.Texture = tkey;
  3417. }
  3418. // else try to locate the name in inventory of object. found returns key,
  3419. // not found returns LLUUID.Zero which will translate to the default particle texture
  3420. else
  3421. {
  3422. prules.Texture = InventoryKey(rules.Data[i+1].ToString());
  3423. }
  3424. break;
  3425. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_RATE:
  3426. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3427. prules.BurstRate = (float)tempf;
  3428. break;
  3429. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_PART_COUNT:
  3430. prules.BurstPartCount = (byte)Convert.ToByte(rules.Data[i + 1].ToString());
  3431. break;
  3432. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_RADIUS:
  3433. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3434. prules.BurstRadius = (float)tempf;
  3435. break;
  3436. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_SPEED_MIN:
  3437. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3438. prules.BurstSpeedMin = (float)tempf;
  3439. break;
  3440. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_BURST_SPEED_MAX:
  3441. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3442. prules.BurstSpeedMax = (float)tempf;
  3443. break;
  3444. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_MAX_AGE:
  3445. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3446. prules.MaxAge = (float)tempf;
  3447. break;
  3448. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_TARGET_KEY:
  3449. LLUUID key = LLUUID.Zero;
  3450. if (LLUUID.TryParse(rules.Data[i + 1].ToString(), out key))
  3451. {
  3452. prules.Target = key;
  3453. }
  3454. else
  3455. {
  3456. prules.Target = m_host.UUID;
  3457. }
  3458. break;
  3459. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_OMEGA:
  3460. // AL: This is an assumption, since it is the only thing that would match.
  3461. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3462. prules.AngularVelocity.X = (float)tempv.x;
  3463. prules.AngularVelocity.Y = (float)tempv.y;
  3464. prules.AngularVelocity.Z = (float)tempv.z;
  3465. //cast?? prules.MaxAge = (float)rules[i + 1];
  3466. break;
  3467. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_ANGLE_BEGIN:
  3468. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3469. prules.InnerAngle = (float)tempf;
  3470. break;
  3471. case (int)BuiltIn_Commands_BaseClass.PSYS_SRC_ANGLE_END:
  3472. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3473. prules.OuterAngle = (float)tempf;
  3474. break;
  3475. }
  3476. }
  3477. prules.CRC = 1;
  3478. m_host.AddNewParticleSystem(prules);
  3479. m_host.SendFullUpdateToAllClients();
  3480. }
  3481. public void llGroundRepel(double height, int water, double tau)
  3482. {
  3483. m_host.AddScriptLPS(1);
  3484. NotImplemented("llGroundRepel");
  3485. }
  3486. public void llGiveInventoryList(string destination, string category, LSL_Types.list inventory)
  3487. {
  3488. m_host.AddScriptLPS(1);
  3489. NotImplemented("llGiveInventoryList");
  3490. }
  3491. public void llSetVehicleType(int type)
  3492. {
  3493. m_host.AddScriptLPS(1);
  3494. NotImplemented("llSetVehicleType");
  3495. }
  3496. public void llSetVehicledoubleParam(int param, double value)
  3497. {
  3498. m_host.AddScriptLPS(1);
  3499. NotImplemented("llSetVehicledoubleParam");
  3500. }
  3501. public void llSetVehicleFloatParam(int param, float value)
  3502. {
  3503. m_host.AddScriptLPS(1);
  3504. NotImplemented("llSetVehicleFloatParam");
  3505. }
  3506. public void llSetVehicleVectorParam(int param, LSL_Types.Vector3 vec)
  3507. {
  3508. m_host.AddScriptLPS(1);
  3509. NotImplemented("llSetVehicleVectorParam");
  3510. }
  3511. public void llSetVehicleRotationParam(int param, LSL_Types.Quaternion rot)
  3512. {
  3513. m_host.AddScriptLPS(1);
  3514. NotImplemented("llSetVehicleRotationParam");
  3515. }
  3516. public void llSetVehicleFlags(int flags)
  3517. {
  3518. m_host.AddScriptLPS(1);
  3519. NotImplemented("llSetVehicleFlags");
  3520. }
  3521. public void llRemoveVehicleFlags(int flags)
  3522. {
  3523. m_host.AddScriptLPS(1);
  3524. NotImplemented("llRemoveVehicleFlags");
  3525. }
  3526. public void llSitTarget(LSL_Types.Vector3 offset, LSL_Types.Quaternion rot)
  3527. {
  3528. m_host.AddScriptLPS(1);
  3529. // LSL quaternions can normalize to 0, normal Quaternions can't.
  3530. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  3531. rot.z = 1; // ZERO_ROTATION = 0,0,0,1
  3532. m_host.SetSitTarget(new Vector3((float)offset.x, (float)offset.y, (float)offset.z), new Quaternion((float)rot.s, (float)rot.x, (float)rot.y, (float)rot.z));
  3533. }
  3534. public string llAvatarOnSitTarget()
  3535. {
  3536. m_host.AddScriptLPS(1);
  3537. return m_host.GetAvatarOnSitTarget().ToString();
  3538. //LLUUID AVID = m_host.GetAvatarOnSitTarget();
  3539. //if (AVID != LLUUID.Zero)
  3540. // return AVID.ToString();
  3541. //else
  3542. // return String.Empty;
  3543. }
  3544. public void llAddToLandPassList(string avatar, double hours)
  3545. {
  3546. m_host.AddScriptLPS(1);
  3547. LLUUID key;
  3548. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  3549. if (land.ownerID == m_host.OwnerID)
  3550. {
  3551. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  3552. if (LLUUID.TryParse(avatar, out key))
  3553. {
  3554. entry.AgentID = key;
  3555. entry.Flags = ParcelManager.AccessList.Access;
  3556. entry.Time = DateTime.Now.AddHours(hours);
  3557. land.parcelAccessList.Add(entry);
  3558. }
  3559. }
  3560. }
  3561. public void llSetTouchText(string text)
  3562. {
  3563. m_host.AddScriptLPS(1);
  3564. m_host.TouchName = text;
  3565. }
  3566. public void llSetSitText(string text)
  3567. {
  3568. m_host.AddScriptLPS(1);
  3569. m_host.SitName = text;
  3570. }
  3571. public void llSetCameraEyeOffset(LSL_Types.Vector3 offset)
  3572. {
  3573. m_host.AddScriptLPS(1);
  3574. NotImplemented("llSetCameraEyeOffset");
  3575. }
  3576. public void llSetCameraAtOffset(LSL_Types.Vector3 offset)
  3577. {
  3578. m_host.AddScriptLPS(1);
  3579. NotImplemented("llSetCameraAtOffset");
  3580. }
  3581. public string llDumpList2String(LSL_Types.list src, string seperator)
  3582. {
  3583. m_host.AddScriptLPS(1);
  3584. if (src.Length == 0)
  3585. {
  3586. return String.Empty;
  3587. }
  3588. string ret = String.Empty;
  3589. foreach (object o in src.Data)
  3590. {
  3591. ret = ret + o.ToString() + seperator;
  3592. }
  3593. ret = ret.Substring(0, ret.Length - seperator.Length);
  3594. return ret;
  3595. }
  3596. public LSL_Types.LSLInteger llScriptDanger(LSL_Types.Vector3 pos)
  3597. {
  3598. m_host.AddScriptLPS(1);
  3599. bool result = World.scriptDanger(m_host.LocalId, new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  3600. if (result)
  3601. {
  3602. return 1;
  3603. }
  3604. else
  3605. {
  3606. return 0;
  3607. }
  3608. }
  3609. public void llDialog(string avatar, string message, LSL_Types.list buttons, int chat_channel)
  3610. {
  3611. m_host.AddScriptLPS(1);
  3612. LLUUID av = new LLUUID();
  3613. if (!LLUUID.TryParse(avatar,out av))
  3614. {
  3615. LSLError("First parameter to llDialog needs to be a key");
  3616. return;
  3617. }
  3618. if (buttons.Length > 12)
  3619. {
  3620. LSLError("No more than 12 buttons can be shown");
  3621. return;
  3622. }
  3623. string[] buts = new string[buttons.Length];
  3624. for (int i = 0; i < buttons.Length; i++)
  3625. {
  3626. if (buttons.Data[i].ToString() == String.Empty)
  3627. {
  3628. LSLError("button label cannot be blank");
  3629. return;
  3630. }
  3631. if (buttons.Data[i].ToString().Length > 24)
  3632. {
  3633. LSLError("button label cannot be longer than 24 characters");
  3634. return;
  3635. }
  3636. buts[i] = buttons.Data[i].ToString();
  3637. }
  3638. World.SendDialogToUser(av, m_host.Name, m_host.UUID, m_host.OwnerID, message, new LLUUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  3639. }
  3640. public void llVolumeDetect(int detect)
  3641. {
  3642. m_host.AddScriptLPS(1);
  3643. NotImplemented("llVolumeDetect");
  3644. }
  3645. /// <summary>
  3646. /// Reset the named script. The script must be present
  3647. /// in the same prim.
  3648. /// </summary>
  3649. public void llResetOtherScript(string name)
  3650. {
  3651. LLUUID item;
  3652. m_host.AddScriptLPS(1);
  3653. if ((item = ScriptByName(name)) != LLUUID.Zero)
  3654. m_ScriptEngine.ResetScript(item);
  3655. else
  3656. ShoutError("llResetOtherScript: script "+name+" not found");
  3657. }
  3658. public LSL_Types.LSLInteger llGetScriptState(string name)
  3659. {
  3660. LLUUID item;
  3661. m_host.AddScriptLPS(1);
  3662. if ((item = ScriptByName(name)) != LLUUID.Zero)
  3663. {
  3664. return m_ScriptEngine.GetScriptState(item) ?1:0;
  3665. }
  3666. ShoutError("llGetScriptState: script "+name+" not found");
  3667. // If we didn't find it, then it's safe to
  3668. // assume it is not running.
  3669. return 0;
  3670. }
  3671. public void llRemoteLoadScript()
  3672. {
  3673. m_host.AddScriptLPS(1);
  3674. Deprecated("llRemoteLoadScript");
  3675. }
  3676. public void llSetRemoteScriptAccessPin(int pin)
  3677. {
  3678. m_host.AddScriptLPS(1);
  3679. NotImplemented("llSetRemoteScriptAccessPin");
  3680. }
  3681. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  3682. {
  3683. m_host.AddScriptLPS(1);
  3684. NotImplemented("llRemoteLoadScriptPin");
  3685. }
  3686. // remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
  3687. // Not sure where these constants should live:
  3688. // REMOTE_DATA_CHANNEL = 1
  3689. // REMOTE_DATA_REQUEST = 2
  3690. // REMOTE_DATA_REPLY = 3
  3691. public void llOpenRemoteDataChannel()
  3692. {
  3693. m_host.AddScriptLPS(1);
  3694. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3695. if (xmlrpcMod.IsEnabled())
  3696. {
  3697. LLUUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, LLUUID.Zero);
  3698. object[] resobj = new object[] { new LSL_Types.LSLInteger(1), new LSL_Types.LSLString(channelID.ToString()), new LSL_Types.LSLString(LLUUID.Zero.ToString()), new LSL_Types.LSLString(String.Empty), new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(String.Empty) };
  3699. m_ScriptEngine.PostScriptEvent(m_itemID, new XEventParams(
  3700. "remote_data", resobj,
  3701. new XDetectParams[0]));
  3702. }
  3703. }
  3704. public string llSendRemoteData(string channel, string dest, int idata, string sdata)
  3705. {
  3706. m_host.AddScriptLPS(1);
  3707. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3708. return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString();
  3709. }
  3710. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  3711. {
  3712. m_host.AddScriptLPS(1);
  3713. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3714. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  3715. }
  3716. public void llCloseRemoteDataChannel(string channel)
  3717. {
  3718. m_host.AddScriptLPS(1);
  3719. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3720. xmlrpcMod.CloseXMLRPCChannel(channel);
  3721. }
  3722. public string llMD5String(string src, int nonce)
  3723. {
  3724. m_host.AddScriptLPS(1);
  3725. return Util.Md5Hash(src + ":" + nonce.ToString());
  3726. }
  3727. public void llSetPrimitiveParams(LSL_Types.list rules)
  3728. {
  3729. llSetLinkPrimitiveParams(m_host.LinkNum+1, rules);
  3730. }
  3731. public void llSetLinkPrimitiveParams(int linknumber, LSL_Types.list rules)
  3732. {
  3733. m_host.AddScriptLPS(1);
  3734. SceneObjectPart part=null;
  3735. if (m_host.LinkNum+1 != linknumber)
  3736. {
  3737. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  3738. {
  3739. if ((partInst.LinkNum + 1) == linknumber)
  3740. {
  3741. part = partInst;
  3742. break;
  3743. }
  3744. }
  3745. }
  3746. else
  3747. {
  3748. part = m_host;
  3749. }
  3750. if (part == null)
  3751. return;
  3752. int idx = 0;
  3753. while (idx < rules.Length)
  3754. {
  3755. int code = Convert.ToInt32(rules.Data[idx++]);
  3756. int remain = rules.Length - idx;
  3757. int face;
  3758. LSL_Types.Vector3 v;
  3759. switch (code)
  3760. {
  3761. case 6: // PRIM_POSITION
  3762. if (remain < 1)
  3763. return;
  3764. v=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3765. SetPos(part, v);
  3766. break;
  3767. case 8: // PRIM_ROTATION
  3768. if (remain < 1)
  3769. return;
  3770. LSL_Types.Quaternion q = new LSL_Types.Quaternion(rules.Data[idx++].ToString());
  3771. SetRot(part, q);
  3772. break;
  3773. case 17: // PRIM_TEXTURE
  3774. if (remain < 5)
  3775. return;
  3776. face=Convert.ToInt32(rules.Data[idx++]);
  3777. string tex=rules.Data[idx++].ToString();
  3778. LSL_Types.Vector3 repeats=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3779. LSL_Types.Vector3 offsets=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3780. double rotation=Convert.ToDouble(rules.Data[idx++]);
  3781. SetTexture(part, tex, face);
  3782. ScaleTexture(part, repeats.x, repeats.y, face);
  3783. OffsetTexture(part, offsets.x, offsets.y, face);
  3784. RotateTexture(part, rotation, face);
  3785. break;
  3786. case 18: // PRIM_COLOR
  3787. if (remain < 3)
  3788. return;
  3789. face=Convert.ToInt32(rules.Data[idx++]);
  3790. LSL_Types.Vector3 color=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3791. double alpha=Convert.ToDouble(rules.Data[idx++]);
  3792. SetColor(part, color, face);
  3793. SetAlpha(part, alpha, face);
  3794. break;
  3795. case 7: // PRIM_SIZE
  3796. if (remain < 1)
  3797. return;
  3798. v=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  3799. SetScale(part, v);
  3800. break;
  3801. }
  3802. }
  3803. }
  3804. public string llStringToBase64(string str)
  3805. {
  3806. m_host.AddScriptLPS(1);
  3807. try
  3808. {
  3809. byte[] encData_byte = new byte[str.Length];
  3810. encData_byte = Encoding.UTF8.GetBytes(str);
  3811. string encodedData = Convert.ToBase64String(encData_byte);
  3812. return encodedData;
  3813. }
  3814. catch (Exception e)
  3815. {
  3816. throw new Exception("Error in base64Encode" + e.Message);
  3817. }
  3818. }
  3819. public string llBase64ToString(string str)
  3820. {
  3821. m_host.AddScriptLPS(1);
  3822. UTF8Encoding encoder = new UTF8Encoding();
  3823. Decoder utf8Decode = encoder.GetDecoder();
  3824. try
  3825. {
  3826. byte[] todecode_byte = Convert.FromBase64String(str);
  3827. int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
  3828. char[] decoded_char = new char[charCount];
  3829. utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
  3830. string result = new String(decoded_char);
  3831. return result;
  3832. }
  3833. catch (Exception e)
  3834. {
  3835. throw new Exception("Error in base64Decode" + e.Message);
  3836. }
  3837. }
  3838. public void llXorBase64Strings()
  3839. {
  3840. m_host.AddScriptLPS(1);
  3841. Deprecated("llXorBase64Strings");
  3842. }
  3843. public void llRemoteDataSetRegion()
  3844. {
  3845. m_host.AddScriptLPS(1);
  3846. NotImplemented("llRemoteDataSetRegion");
  3847. }
  3848. public double llLog10(double val)
  3849. {
  3850. m_host.AddScriptLPS(1);
  3851. return (double)Math.Log10(val);
  3852. }
  3853. public double llLog(double val)
  3854. {
  3855. m_host.AddScriptLPS(1);
  3856. return (double)Math.Log(val);
  3857. }
  3858. public LSL_Types.list llGetAnimationList(string id)
  3859. {
  3860. m_host.AddScriptLPS(1);
  3861. NotImplemented("llGetAnimationList");
  3862. return new LSL_Types.list();
  3863. }
  3864. public void llSetParcelMusicURL(string url)
  3865. {
  3866. m_host.AddScriptLPS(1);
  3867. LLUUID landowner = World.GetLandOwner(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  3868. if (landowner == LLUUID.Zero)
  3869. {
  3870. return;
  3871. }
  3872. if (landowner != m_host.ObjectOwner)
  3873. {
  3874. return;
  3875. }
  3876. World.SetLandMusicURL(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, url);
  3877. }
  3878. public void osSetParcelMediaURL(string url)
  3879. {
  3880. m_host.AddScriptLPS(1);
  3881. LLUUID landowner = World.GetLandOwner(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  3882. if (landowner == LLUUID.Zero)
  3883. {
  3884. return;
  3885. }
  3886. if (landowner != m_host.ObjectOwner)
  3887. {
  3888. return;
  3889. }
  3890. World.SetLandMediaURL(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, url);
  3891. }
  3892. public LSL_Types.Vector3 llGetRootPosition()
  3893. {
  3894. m_host.AddScriptLPS(1);
  3895. return new LSL_Types.Vector3(m_host.ParentGroup.AbsolutePosition.X, m_host.ParentGroup.AbsolutePosition.Y, m_host.ParentGroup.AbsolutePosition.Z);
  3896. }
  3897. public LSL_Types.Quaternion llGetRootRotation()
  3898. {
  3899. m_host.AddScriptLPS(1);
  3900. return new LSL_Types.Quaternion(m_host.ParentGroup.GroupRotation.X, m_host.ParentGroup.GroupRotation.Y, m_host.ParentGroup.GroupRotation.Z, m_host.ParentGroup.GroupRotation.W);
  3901. }
  3902. public string llGetObjectDesc()
  3903. {
  3904. return m_host.Description!=null?m_host.Description:String.Empty;
  3905. }
  3906. public void llSetObjectDesc(string desc)
  3907. {
  3908. m_host.AddScriptLPS(1);
  3909. m_host.Description = desc!=null?desc:String.Empty;
  3910. }
  3911. public string llGetCreator()
  3912. {
  3913. m_host.AddScriptLPS(1);
  3914. return m_host.ObjectCreator.ToString();
  3915. }
  3916. public string llGetTimestamp()
  3917. {
  3918. m_host.AddScriptLPS(1);
  3919. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  3920. }
  3921. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  3922. {
  3923. m_host.AddScriptLPS(1);
  3924. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  3925. if (linknumber > -1)
  3926. {
  3927. LLObject.TextureEntry tex = part.Shape.Textures;
  3928. LLColor texcolor;
  3929. if (face > -1)
  3930. {
  3931. texcolor = tex.CreateFace((uint)face).RGBA;
  3932. texcolor.A = (float)Math.Abs(alpha - 1);
  3933. tex.FaceTextures[face].RGBA = texcolor;
  3934. part.UpdateTexture(tex);
  3935. return;
  3936. }
  3937. else if (face == -1)
  3938. {
  3939. texcolor = tex.DefaultTexture.RGBA;
  3940. texcolor.A = (float)Math.Abs(alpha - 1);
  3941. tex.DefaultTexture.RGBA = texcolor;
  3942. for (uint i = 0; i < 32; i++)
  3943. {
  3944. if (tex.FaceTextures[i] != null)
  3945. {
  3946. texcolor = tex.FaceTextures[i].RGBA;
  3947. texcolor.A = (float)Math.Abs(alpha - 1);
  3948. tex.FaceTextures[i].RGBA = texcolor;
  3949. }
  3950. }
  3951. texcolor = tex.DefaultTexture.RGBA;
  3952. texcolor.A = (float)Math.Abs(alpha - 1);
  3953. tex.DefaultTexture.RGBA = texcolor;
  3954. part.UpdateTexture(tex);
  3955. return;
  3956. }
  3957. return;
  3958. }
  3959. else if (linknumber == -1)
  3960. {
  3961. int num = m_host.ParentGroup.PrimCount;
  3962. for (int w = 0; w < num; w++)
  3963. {
  3964. linknumber = w;
  3965. part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  3966. LLObject.TextureEntry tex = part.Shape.Textures;
  3967. LLColor texcolor;
  3968. if (face > -1)
  3969. {
  3970. texcolor = tex.CreateFace((uint)face).RGBA;
  3971. texcolor.A = (float)Math.Abs(alpha - 1);
  3972. tex.FaceTextures[face].RGBA = texcolor;
  3973. part.UpdateTexture(tex);
  3974. }
  3975. else if (face == -1)
  3976. {
  3977. texcolor = tex.DefaultTexture.RGBA;
  3978. texcolor.A = (float)Math.Abs(alpha - 1);
  3979. tex.DefaultTexture.RGBA = texcolor;
  3980. for (uint i = 0; i < 32; i++)
  3981. {
  3982. if (tex.FaceTextures[i] != null)
  3983. {
  3984. texcolor = tex.FaceTextures[i].RGBA;
  3985. texcolor.A = (float)Math.Abs(alpha - 1);
  3986. tex.FaceTextures[i].RGBA = texcolor;
  3987. }
  3988. }
  3989. texcolor = tex.DefaultTexture.RGBA;
  3990. texcolor.A = (float)Math.Abs(alpha - 1);
  3991. tex.DefaultTexture.RGBA = texcolor;
  3992. part.UpdateTexture(tex);
  3993. }
  3994. }
  3995. return;
  3996. }
  3997. }
  3998. public LSL_Types.LSLInteger llGetNumberOfPrims()
  3999. {
  4000. m_host.AddScriptLPS(1);
  4001. return m_host.ParentGroup.PrimCount;
  4002. }
  4003. public LSL_Types.list llGetBoundingBox(string obj)
  4004. {
  4005. m_host.AddScriptLPS(1);
  4006. NotImplemented("llGetBoundingBox");
  4007. return new LSL_Types.list();
  4008. }
  4009. public LSL_Types.Vector3 llGetGeometricCenter()
  4010. {
  4011. return new LSL_Types.Vector3(m_host.GetGeometricCenter().X, m_host.GetGeometricCenter().Y, m_host.GetGeometricCenter().Z);
  4012. }
  4013. public LSL_Types.list llGetPrimitiveParams(LSL_Types.list rules)
  4014. {
  4015. m_host.AddScriptLPS(1);
  4016. LSL_Types.list res = new LSL_Types.list();
  4017. int idx=0;
  4018. while (idx < rules.Length)
  4019. {
  4020. int code=Convert.ToInt32(rules.Data[idx++]);
  4021. int remain=rules.Length-idx;
  4022. switch (code)
  4023. {
  4024. case 2: // PRIM_MATERIAL
  4025. res.Add(new LSL_Types.LSLInteger(m_host.Material));
  4026. break;
  4027. case 3: // PRIM_PHYSICS
  4028. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Physics) != 0)
  4029. res.Add(new LSL_Types.LSLInteger(1));
  4030. else
  4031. res.Add(new LSL_Types.LSLInteger(0));
  4032. break;
  4033. case 4: // PRIM_TEMP_ON_REZ
  4034. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.TemporaryOnRez) != 0)
  4035. res.Add(new LSL_Types.LSLInteger(1));
  4036. else
  4037. res.Add(new LSL_Types.LSLInteger(0));
  4038. break;
  4039. case 5: // PRIM_PHANTOM
  4040. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Phantom) != 0)
  4041. res.Add(new LSL_Types.LSLInteger(1));
  4042. else
  4043. res.Add(new LSL_Types.LSLInteger(0));
  4044. break;
  4045. case 6: // PRIM_POSITION
  4046. res.Add(new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  4047. m_host.AbsolutePosition.Y,
  4048. m_host.AbsolutePosition.Z));
  4049. break;
  4050. case 7: // PRIM_SIZE
  4051. res.Add(new LSL_Types.Vector3(m_host.Scale.X,
  4052. m_host.Scale.Y,
  4053. m_host.Scale.Z));
  4054. break;
  4055. case 8: // PRIM_ROTATION
  4056. res.Add(new LSL_Types.Quaternion(m_host.RotationOffset.X,
  4057. m_host.RotationOffset.Y,
  4058. m_host.RotationOffset.Z,
  4059. m_host.RotationOffset.W));
  4060. break;
  4061. case 9: // PRIM_TYPE
  4062. // TODO--------------
  4063. res.Add(new LSL_Types.LSLInteger(0));
  4064. break;
  4065. case 17: // PRIM_TEXTURE
  4066. if (remain < 1)
  4067. return res;
  4068. int face=Convert.ToInt32(rules.Data[idx++]);
  4069. if (face == -1)
  4070. face = 0;
  4071. LLObject.TextureEntry tex = m_host.Shape.Textures;
  4072. LLObject.TextureEntryFace texface = tex.GetFace((uint)face);
  4073. res.Add(new LSL_Types.LSLString(texface.TextureID.ToString()));
  4074. res.Add(new LSL_Types.Vector3(texface.RepeatU,
  4075. texface.RepeatV,
  4076. 0));
  4077. res.Add(new LSL_Types.Vector3(texface.OffsetU,
  4078. texface.OffsetV,
  4079. 0));
  4080. res.Add(new LSL_Types.LSLFloat(texface.Rotation));
  4081. break;
  4082. case 18: // PRIM_COLOR
  4083. if (remain < 1)
  4084. return res;
  4085. face=Convert.ToInt32(rules.Data[idx++]);
  4086. tex = m_host.Shape.Textures;
  4087. LLColor texcolor;
  4088. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  4089. texcolor = tex.DefaultTexture.RGBA;
  4090. else
  4091. texcolor = tex.GetFace((uint)face).RGBA;
  4092. res.Add(new LSL_Types.Vector3((255 - (texcolor.R * 255)) / 255,
  4093. (255 - (texcolor.G * 255)) / 255,
  4094. (255 - (texcolor.B * 255)) / 255));
  4095. res.Add(new LSL_Types.LSLFloat((texcolor.A * 255) / 255));
  4096. break;
  4097. case 19: // PRIM_BUMP_SHINY
  4098. // TODO--------------
  4099. if (remain < 1)
  4100. return res;
  4101. face=Convert.ToInt32(rules.Data[idx++]);
  4102. res.Add(new LSL_Types.LSLInteger(0));
  4103. res.Add(new LSL_Types.LSLInteger(0));
  4104. break;
  4105. case 20: // PRIM_FULLBRIGHT
  4106. // TODO--------------
  4107. if (remain < 1)
  4108. return res;
  4109. face=Convert.ToInt32(rules.Data[idx++]);
  4110. res.Add(new LSL_Types.LSLInteger(0));
  4111. break;
  4112. case 21: // PRIM_FLEXIBLE
  4113. PrimitiveBaseShape shape = m_host.Shape;
  4114. if (shape.FlexiEntry)
  4115. res.Add(new LSL_Types.LSLInteger(1)); // active
  4116. else
  4117. res.Add(new LSL_Types.LSLInteger(0));
  4118. res.Add(new LSL_Types.LSLInteger(shape.FlexiSoftness));// softness
  4119. res.Add(new LSL_Types.LSLFloat(shape.FlexiGravity)); // gravity
  4120. res.Add(new LSL_Types.LSLFloat(shape.FlexiDrag)); // friction
  4121. res.Add(new LSL_Types.LSLFloat(shape.FlexiWind)); // wind
  4122. res.Add(new LSL_Types.LSLFloat(shape.FlexiTension)); // tension
  4123. res.Add(new LSL_Types.Vector3(shape.FlexiForceX, // force
  4124. shape.FlexiForceY,
  4125. shape.FlexiForceZ));
  4126. break;
  4127. case 22: // PRIM_TEXGEN
  4128. // TODO--------------
  4129. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  4130. if (remain < 1)
  4131. return res;
  4132. face=Convert.ToInt32(rules.Data[idx++]);
  4133. res.Add(new LSL_Types.LSLInteger(0));
  4134. break;
  4135. case 23: // PRIM_POINT_LIGHT:
  4136. shape = m_host.Shape;
  4137. if (shape.LightEntry)
  4138. res.Add(new LSL_Types.LSLInteger(1)); // active
  4139. else
  4140. res.Add(new LSL_Types.LSLInteger(0));
  4141. res.Add(new LSL_Types.Vector3(shape.LightColorR, // color
  4142. shape.LightColorG,
  4143. shape.LightColorB));
  4144. res.Add(new LSL_Types.LSLFloat(shape.LightIntensity)); // intensity
  4145. res.Add(new LSL_Types.LSLFloat(shape.LightRadius)); // radius
  4146. res.Add(new LSL_Types.LSLFloat(shape.LightFalloff)); // falloff
  4147. break;
  4148. case 24: // PRIM_GLOW
  4149. // TODO--------------
  4150. if (remain < 1)
  4151. return res;
  4152. face=Convert.ToInt32(rules.Data[idx++]);
  4153. res.Add(new LSL_Types.LSLFloat(0));
  4154. break;
  4155. }
  4156. }
  4157. return res;
  4158. }
  4159. // <remarks>
  4160. // <para>
  4161. // The .NET definition of base 64 is:
  4162. // <list>
  4163. // <item>
  4164. // Significant: A-Z a-z 0-9 + -
  4165. // </item>
  4166. // <item>
  4167. // Whitespace: \t \n \r ' '
  4168. // </item>
  4169. // <item>
  4170. // Valueless: =
  4171. // </item>
  4172. // <item>
  4173. // End-of-string: \0 or '=='
  4174. // </item>
  4175. // </list>
  4176. // </para>
  4177. // <para>
  4178. // Each point in a base-64 string represents
  4179. // a 6 bit value. A 32-bit integer can be
  4180. // represented using 6 characters (with some
  4181. // redundancy).
  4182. // </para>
  4183. // <para>
  4184. // LSL requires a base64 string to be 8
  4185. // characters in length. LSL also uses '/'
  4186. // rather than '-' (MIME compliant).
  4187. // </para>
  4188. // <para>
  4189. // RFC 1341 used as a reference (as specified
  4190. // by the SecondLife Wiki).
  4191. // </para>
  4192. // <para>
  4193. // SL do not record any kind of exception for
  4194. // these functions, so the string to integer
  4195. // conversion returns '0' if an invalid
  4196. // character is encountered during conversion.
  4197. // </para>
  4198. // <para>
  4199. // References
  4200. // <list>
  4201. // <item>
  4202. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  4203. // </item>
  4204. // <item>
  4205. // </item>
  4206. // </list>
  4207. // </para>
  4208. // </remarks>
  4209. // <summary>
  4210. // Table for converting 6-bit integers into
  4211. // base-64 characters
  4212. // </summary>
  4213. private static readonly char[] i2ctable =
  4214. {
  4215. 'A','B','C','D','E','F','G','H',
  4216. 'I','J','K','L','M','N','O','P',
  4217. 'Q','R','S','T','U','V','W','X',
  4218. 'Y','Z',
  4219. 'a','b','c','d','e','f','g','h',
  4220. 'i','j','k','l','m','n','o','p',
  4221. 'q','r','s','t','u','v','w','x',
  4222. 'y','z',
  4223. '0','1','2','3','4','5','6','7',
  4224. '8','9',
  4225. '+','/'
  4226. };
  4227. // <summary>
  4228. // Table for converting base-64 characters
  4229. // into 6-bit integers.
  4230. // </summary>
  4231. private static readonly int[] c2itable =
  4232. {
  4233. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  4234. -1,-1,-1,-1,-1,-1,-1,-1,
  4235. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  4236. -1,-1,-1,-1,-1,-1,-1,-1,
  4237. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  4238. -1,-1,-1,63,-1,-1,-1,64,
  4239. 53,54,55,56,57,58,59,60, // 3x
  4240. 61,62,-1,-1,-1,0,-1,-1,
  4241. -1,1,2,3,4,5,6,7, // 4x
  4242. 8,9,10,11,12,13,14,15,
  4243. 16,17,18,19,20,21,22,23, // 5x
  4244. 24,25,26,-1,-1,-1,-1,-1,
  4245. -1,27,28,29,30,31,32,33, // 6x
  4246. 34,35,36,37,38,39,40,41,
  4247. 42,43,44,45,46,47,48,49, // 7x
  4248. 50,51,52,-1,-1,-1,-1,-1,
  4249. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  4250. -1,-1,-1,-1,-1,-1,-1,-1,
  4251. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  4252. -1,-1,-1,-1,-1,-1,-1,-1,
  4253. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  4254. -1,-1,-1,-1,-1,-1,-1,-1,
  4255. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  4256. -1,-1,-1,-1,-1,-1,-1,-1,
  4257. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  4258. -1,-1,-1,-1,-1,-1,-1,-1,
  4259. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  4260. -1,-1,-1,-1,-1,-1,-1,-1,
  4261. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  4262. -1,-1,-1,-1,-1,-1,-1,-1,
  4263. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  4264. -1,-1,-1,-1,-1,-1,-1,-1
  4265. };
  4266. // <summary>
  4267. // Converts a 32-bit integer into a Base64
  4268. // character string. Base64 character strings
  4269. // are always 8 characters long. All iinteger
  4270. // values are acceptable.
  4271. // </summary>
  4272. // <param name="number">
  4273. // 32-bit integer to be converted.
  4274. // </param>
  4275. // <returns>
  4276. // 8 character string. The 1st six characters
  4277. // contain the encoded number, the last two
  4278. // characters are padded with "=".
  4279. // </returns>
  4280. public string llIntegerToBase64(int number)
  4281. {
  4282. // uninitialized string
  4283. char[] imdt = new char[8];
  4284. m_host.AddScriptLPS(1);
  4285. // Manually unroll the loop
  4286. imdt[7] = '=';
  4287. imdt[6] = '=';
  4288. imdt[5] = i2ctable[number<<4 & 0x3F];
  4289. imdt[4] = i2ctable[number>>2 & 0x3F];
  4290. imdt[3] = i2ctable[number>>8 & 0x3F];
  4291. imdt[2] = i2ctable[number>>14 & 0x3F];
  4292. imdt[1] = i2ctable[number>>20 & 0x3F];
  4293. imdt[0] = i2ctable[number>>26 & 0x3F];
  4294. return new string(imdt);
  4295. }
  4296. // <summary>
  4297. // Converts an eight character base-64 string
  4298. // into a 32-bit integer.
  4299. // </summary>
  4300. // <param name="str">
  4301. // 8 characters string to be converted. Other
  4302. // length strings return zero.
  4303. // </param>
  4304. // <returns>
  4305. // Returns an integer representing the
  4306. // encoded value providedint he 1st 6
  4307. // characters of the string.
  4308. // </returns>
  4309. // <remarks>
  4310. // This is coded to behave like LSL's
  4311. // implementation (I think), based upon the
  4312. // information available at the Wiki.
  4313. // If more than 8 characters are supplied,
  4314. // zero is returned.
  4315. // If a NULL string is supplied, zero will
  4316. // be returned.
  4317. // If fewer than 6 characters are supplied, then
  4318. // the answer will reflect a partial
  4319. // accumulation.
  4320. // <para>
  4321. // The 6-bit segments are
  4322. // extracted left-to-right in big-endian mode,
  4323. // which means that segment 6 only contains the
  4324. // two low-order bits of the 32 bit integer as
  4325. // its high order 2 bits. A short string therefore
  4326. // means loss of low-order information. E.g.
  4327. //
  4328. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  4329. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  4330. // |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|
  4331. // |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|
  4332. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  4333. //
  4334. // </para>
  4335. // </remarks>
  4336. public LSL_Types.LSLInteger llBase64ToInteger(string str)
  4337. {
  4338. int number = 0;
  4339. int digit;
  4340. m_host.AddScriptLPS(1);
  4341. // Require a well-fromed base64 string
  4342. if (str.Length > 8)
  4343. return 0;
  4344. // The loop is unrolled in the interests
  4345. // of performance and simple necessity.
  4346. //
  4347. // MUST find 6 digits to be well formed
  4348. // -1 == invalid
  4349. // 0 == padding
  4350. if ((digit=c2itable[str[0]])<=0)
  4351. {
  4352. return digit<0?(int)0:number;
  4353. }
  4354. number += --digit<<26;
  4355. if ((digit=c2itable[str[1]])<=0)
  4356. {
  4357. return digit<0?(int)0:number;
  4358. }
  4359. number += --digit<<20;
  4360. if ((digit=c2itable[str[2]])<=0)
  4361. {
  4362. return digit<0?(int)0:number;
  4363. }
  4364. number += --digit<<14;
  4365. if ((digit=c2itable[str[3]])<=0)
  4366. {
  4367. return digit<0?(int)0:number;
  4368. }
  4369. number += --digit<<8;
  4370. if ((digit=c2itable[str[4]])<=0)
  4371. {
  4372. return digit<0?(int)0:number;
  4373. }
  4374. number += --digit<<2;
  4375. if ((digit=c2itable[str[5]])<=0)
  4376. {
  4377. return digit<0?(int)0:number;
  4378. }
  4379. number += --digit>>4;
  4380. // ignore trailing padding
  4381. return number;
  4382. }
  4383. public double llGetGMTclock()
  4384. {
  4385. m_host.AddScriptLPS(1);
  4386. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  4387. }
  4388. public string llGetSimulatorHostname()
  4389. {
  4390. m_host.AddScriptLPS(1);
  4391. return System.Environment.MachineName;
  4392. }
  4393. public void llSetLocalRot(LSL_Types.Quaternion rot)
  4394. {
  4395. m_host.AddScriptLPS(1);
  4396. m_host.RotationOffset = new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
  4397. }
  4398. // <summary>
  4399. // Scan the string supplied in 'src' and
  4400. // tokenize it based upon two sets of
  4401. // tokenizers provided in two lists,
  4402. // separators and spacers.
  4403. // </summary>
  4404. //
  4405. // <remarks>
  4406. // Separators demarcate tokens and are
  4407. // elided as they are encountered. Spacers
  4408. // also demarcate tokens, but are themselves
  4409. // retained as tokens.
  4410. //
  4411. // Both separators and spacers may be arbitrarily
  4412. // long strings. i.e. ":::".
  4413. //
  4414. // The function returns an ordered list
  4415. // representing the tokens found in the supplied
  4416. // sources string. If two successive tokenizers
  4417. // are encountered, then a NULL entry is added
  4418. // to the list.
  4419. //
  4420. // It is a precondition that the source and
  4421. // toekizer lisst are non-null. If they are null,
  4422. // then a null pointer exception will be thrown
  4423. // while their lengths are being determined.
  4424. //
  4425. // A small amount of working memoryis required
  4426. // of approximately 8*#tokenizers.
  4427. //
  4428. // There are many ways in which this function
  4429. // can be implemented, this implementation is
  4430. // fairly naive and assumes that when the
  4431. // function is invooked with a short source
  4432. // string and/or short lists of tokenizers, then
  4433. // performance will not be an issue.
  4434. //
  4435. // In order to minimize the perofrmance
  4436. // effects of long strings, or large numbers
  4437. // of tokeizers, the function skips as far as
  4438. // possible whenever a toekenizer is found,
  4439. // and eliminates redundant tokenizers as soon
  4440. // as is possible.
  4441. //
  4442. // The implementation tries to avoid any copying
  4443. // of arrays or other objects.
  4444. // </remarks>
  4445. public LSL_Types.list llParseStringKeepNulls(string src, LSL_Types.list separators, LSL_Types.list spacers)
  4446. {
  4447. int beginning = 0;
  4448. int srclen = src.Length;
  4449. int seplen = separators.Length;
  4450. object[] separray = separators.Data;
  4451. int spclen = spacers.Length;
  4452. object[] spcarray = spacers.Data;
  4453. int mlen = seplen+spclen;
  4454. int[] offset = new int[mlen+1];
  4455. bool[] active = new bool[mlen];
  4456. int best;
  4457. int j;
  4458. // Initial capacity reduces resize cost
  4459. LSL_Types.list tokens = new LSL_Types.list();
  4460. m_host.AddScriptLPS(1);
  4461. // All entries are initially valid
  4462. for (int i = 0; i < mlen; i++)
  4463. active[i] = true;
  4464. offset[mlen] = srclen;
  4465. while (beginning < srclen)
  4466. {
  4467. best = mlen; // as bad as it gets
  4468. // Scan for separators
  4469. for (j = 0; j < seplen; j++)
  4470. {
  4471. if (active[j])
  4472. {
  4473. // scan all of the markers
  4474. if ((offset[j] = src.IndexOf((string)separray[j],beginning)) == -1)
  4475. {
  4476. // not present at all
  4477. active[j] = false;
  4478. }
  4479. else
  4480. {
  4481. // present and correct
  4482. if (offset[j] < offset[best])
  4483. {
  4484. // closest so far
  4485. best = j;
  4486. if (offset[best] == beginning)
  4487. break;
  4488. }
  4489. }
  4490. }
  4491. }
  4492. // Scan for spacers
  4493. if (offset[best] != beginning)
  4494. {
  4495. for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
  4496. {
  4497. if (active[j])
  4498. {
  4499. // scan all of the markers
  4500. if ((offset[j] = src.IndexOf((string)spcarray[j-seplen],beginning)) == -1)
  4501. {
  4502. // not present at all
  4503. active[j] = false;
  4504. } else
  4505. {
  4506. // present and correct
  4507. if (offset[j] < offset[best])
  4508. {
  4509. // closest so far
  4510. best = j;
  4511. }
  4512. }
  4513. }
  4514. }
  4515. }
  4516. // This is the normal exit from the scanning loop
  4517. if (best == mlen)
  4518. {
  4519. // no markers were found on this pass
  4520. // so we're pretty much done
  4521. tokens.Add(src.Substring(beginning, srclen-beginning));
  4522. break;
  4523. }
  4524. // Otherwise we just add the newly delimited token
  4525. // and recalculate where the search should continue.
  4526. tokens.Add(src.Substring(beginning,offset[best]-beginning));
  4527. if (best<seplen)
  4528. {
  4529. beginning = offset[best]+((string)separray[best]).Length;
  4530. } else
  4531. {
  4532. beginning = offset[best]+((string)spcarray[best-seplen]).Length;
  4533. tokens.Add(spcarray[best-seplen]);
  4534. }
  4535. }
  4536. // This an awkward an not very intuitive boundary case. If the
  4537. // last substring is a tokenizer, then there is an implied trailing
  4538. // null list entry. Hopefully the single comparison will not be too
  4539. // arduous. Alternatively the 'break' could be replced with a return
  4540. // but that's shabby programming.
  4541. if (beginning == srclen)
  4542. {
  4543. if (srclen != 0)
  4544. tokens.Add("");
  4545. }
  4546. return tokens;
  4547. }
  4548. public void llRezAtRoot(string inventory, LSL_Types.Vector3 position, LSL_Types.Vector3 velocity,
  4549. LSL_Types.Quaternion rot, int param)
  4550. {
  4551. m_host.AddScriptLPS(1);
  4552. NotImplemented("llRezAtRoot");
  4553. }
  4554. public LSL_Types.LSLInteger llGetObjectPermMask(int mask)
  4555. {
  4556. m_host.AddScriptLPS(1);
  4557. int permmask = 0;
  4558. if (mask == BuiltIn_Commands_BaseClass.MASK_BASE)//0
  4559. {
  4560. permmask = (int)m_host.BaseMask;
  4561. }
  4562. else if (mask == BuiltIn_Commands_BaseClass.MASK_OWNER)//1
  4563. {
  4564. permmask = (int)m_host.OwnerMask;
  4565. }
  4566. else if (mask == BuiltIn_Commands_BaseClass.MASK_GROUP)//2
  4567. {
  4568. permmask = (int)m_host.GroupMask;
  4569. }
  4570. else if (mask == BuiltIn_Commands_BaseClass.MASK_EVERYONE)//3
  4571. {
  4572. permmask = (int)m_host.EveryoneMask;
  4573. }
  4574. else if (mask == BuiltIn_Commands_BaseClass.MASK_NEXT)//4
  4575. {
  4576. permmask = (int)m_host.NextOwnerMask;
  4577. }
  4578. return permmask;
  4579. }
  4580. public void llSetObjectPermMask(int mask, int value)
  4581. {
  4582. m_host.AddScriptLPS(1);
  4583. if (mask == BuiltIn_Commands_BaseClass.MASK_BASE)//0
  4584. {
  4585. m_host.BaseMask = (uint)value;
  4586. }
  4587. else if (mask == BuiltIn_Commands_BaseClass.MASK_OWNER)//1
  4588. {
  4589. m_host.OwnerMask = (uint)value;
  4590. }
  4591. else if (mask == BuiltIn_Commands_BaseClass.MASK_GROUP)//2
  4592. {
  4593. m_host.GroupMask = (uint)value;
  4594. }
  4595. else if (mask == BuiltIn_Commands_BaseClass.MASK_EVERYONE)//3
  4596. {
  4597. m_host.EveryoneMask = (uint)value;
  4598. }
  4599. else if (mask == BuiltIn_Commands_BaseClass.MASK_NEXT)//4
  4600. {
  4601. m_host.NextOwnerMask = (uint)value;
  4602. }
  4603. }
  4604. public LSL_Types.LSLInteger llGetInventoryPermMask(string item, int mask)
  4605. {
  4606. m_host.AddScriptLPS(1);
  4607. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4608. {
  4609. if (inv.Value.Name == item)
  4610. {
  4611. switch (mask)
  4612. {
  4613. case 0:
  4614. return (int)inv.Value.BaseMask;
  4615. case 1:
  4616. return (int)inv.Value.OwnerMask;
  4617. case 2:
  4618. return (int)inv.Value.GroupMask;
  4619. case 3:
  4620. return (int)inv.Value.EveryoneMask;
  4621. case 4:
  4622. return (int)inv.Value.NextOwnerMask;
  4623. }
  4624. }
  4625. }
  4626. return -1;
  4627. }
  4628. public void llSetInventoryPermMask(string item, int mask, int value)
  4629. {
  4630. m_host.AddScriptLPS(1);
  4631. NotImplemented("llSetInventoryPermMask");
  4632. }
  4633. public string llGetInventoryCreator(string item)
  4634. {
  4635. m_host.AddScriptLPS(1);
  4636. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4637. {
  4638. if (inv.Value.Name == item)
  4639. {
  4640. return inv.Value.CreatorID.ToString();
  4641. }
  4642. }
  4643. llSay(0, "No item name '" + item + "'");
  4644. return String.Empty;
  4645. }
  4646. public void llOwnerSay(string msg)
  4647. {
  4648. m_host.AddScriptLPS(1);
  4649. World.SimChatBroadcast(Helpers.StringToField(msg), ChatTypeEnum.Owner, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  4650. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  4651. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  4652. }
  4653. public string llRequestSimulatorData(string simulator, int data)
  4654. {
  4655. try
  4656. {
  4657. m_host.AddScriptLPS(1);
  4658. string reply = String.Empty;
  4659. RegionInfo info = m_ScriptEngine.World.RequestClosestRegion(simulator);
  4660. switch(data)
  4661. {
  4662. case 5: // DATA_SIM_POS
  4663. if(info == null)
  4664. return LLUUID.Zero.ToString();
  4665. reply = new LSL_Types.Vector3(
  4666. info.RegionLocX * Constants.RegionSize,
  4667. info.RegionLocY * Constants.RegionSize,
  4668. 0).ToString();
  4669. break;
  4670. case 6: // DATA_SIM_STATUS
  4671. if(info != null)
  4672. reply = "up"; // Duh!
  4673. else
  4674. reply = "unknown";
  4675. break;
  4676. case 7: // DATA_SIM_RATING
  4677. if(info == null)
  4678. return LLUUID.Zero.ToString();
  4679. int access = (int)info.EstateSettings.simAccess;
  4680. if(access == 21)
  4681. reply = "MATURE";
  4682. else if(access == 13)
  4683. reply = "MATURE";
  4684. else
  4685. reply = "UNKNOWN";
  4686. break;
  4687. default:
  4688. return LLUUID.Zero.ToString(); // Raise no event
  4689. }
  4690. LLUUID rq = LLUUID.Random();
  4691. LLUUID tid = m_ScriptEngine.m_ASYNCLSLCommandManager.
  4692. m_Dataserver.RegisterRequest(m_localID,
  4693. m_itemID, rq.ToString());
  4694. m_ScriptEngine.m_ASYNCLSLCommandManager.
  4695. m_Dataserver.DataserverReply(rq.ToString(), reply);
  4696. return tid.ToString();
  4697. }
  4698. catch(Exception e)
  4699. {
  4700. Console.WriteLine(e.ToString());
  4701. return LLUUID.Zero.ToString();
  4702. }
  4703. }
  4704. public void llForceMouselook(int mouselook)
  4705. {
  4706. m_host.AddScriptLPS(1);
  4707. NotImplemented("llForceMouselook");
  4708. }
  4709. public double llGetObjectMass(string id)
  4710. {
  4711. m_host.AddScriptLPS(1);
  4712. LLUUID key = new LLUUID();
  4713. if (LLUUID.TryParse(id,out key))
  4714. {
  4715. return (double)World.GetSceneObjectPart(World.Entities[key].LocalId).GetMass();
  4716. }
  4717. return 0;
  4718. }
  4719. /// <summary>
  4720. /// illListReplaceList removes the sub-list defined by the inclusive indices
  4721. /// start and end and inserts the src list in its place. The inclusive
  4722. /// nature of the indices means that at least one element must be deleted
  4723. /// if the indices are within the bounds of the existing list. I.e. 2,2
  4724. /// will remove the element at index 2 and replace it with the source
  4725. /// list. Both indices may be negative, with the usual interpretation. An
  4726. /// interesting case is where end is lower than start. As these indices
  4727. /// bound the list to be removed, then 0->end, and start->lim are removed
  4728. /// and the source list is added as a suffix.
  4729. /// </summary>
  4730. public LSL_Types.list llListReplaceList(LSL_Types.list dest, LSL_Types.list src, int start, int end)
  4731. {
  4732. LSL_Types.list pref = null;
  4733. m_host.AddScriptLPS(1);
  4734. // Note that although we have normalized, both
  4735. // indices could still be negative.
  4736. if (start < 0)
  4737. {
  4738. start = start+dest.Length;
  4739. }
  4740. if (end < 0)
  4741. {
  4742. end = end+dest.Length;
  4743. }
  4744. // The comventional case, remove a sequence starting with
  4745. // start and ending with end. And then insert the source
  4746. // list.
  4747. if (start <= end)
  4748. {
  4749. // If greater than zero, then there is going to be a
  4750. // surviving prefix. Otherwise the inclusive nature
  4751. // of the indices mean that we're going to add the
  4752. // source list as a prefix.
  4753. if (start > 0)
  4754. {
  4755. pref = dest.GetSublist(0,start-1);
  4756. // Only add a suffix if there is something
  4757. // beyond the end index (it's inclusive too).
  4758. if (end+1 < dest.Length)
  4759. {
  4760. return pref + src + dest.GetSublist(end+1,-1);
  4761. }
  4762. else
  4763. {
  4764. return pref + src;
  4765. }
  4766. }
  4767. // If start is less than or equal to zero, then
  4768. // the new list is simply a prefix. We still need to
  4769. // figure out any necessary surgery to the destination
  4770. // based upon end. Note that if end exceeds the upper
  4771. // bound in this case, the entire destination list
  4772. // is removed.
  4773. else
  4774. {
  4775. if (end+1 < dest.Length)
  4776. {
  4777. return src + dest.GetSublist(end+1,-1);
  4778. }
  4779. else
  4780. {
  4781. return src;
  4782. }
  4783. }
  4784. }
  4785. // Finally, if start > end, we strip away a prefix and
  4786. // a suffix, to leave the list that sits <between> ens
  4787. // and start, and then tag on the src list. AT least
  4788. // that's my interpretation. We can get sublist to do
  4789. // this for us. Note that one, or both of the indices
  4790. // might have been negative.
  4791. else
  4792. {
  4793. return dest.GetSublist(end+1,start-1)+src;
  4794. }
  4795. }
  4796. public void llLoadURL(string avatar_id, string message, string url)
  4797. {
  4798. m_host.AddScriptLPS(1);
  4799. LLUUID avatarId = new LLUUID(avatar_id);
  4800. m_ScriptEngine.World.SendUrlToUser(avatarId, m_host.Name, m_host.UUID, m_host.ObjectOwner, false, message,
  4801. url);
  4802. }
  4803. public void llParcelMediaCommandList(LSL_Types.list commandList)
  4804. {
  4805. m_host.AddScriptLPS(1);
  4806. NotImplemented("llParcelMediaCommandList");
  4807. }
  4808. public void llParcelMediaQuery()
  4809. {
  4810. m_host.AddScriptLPS(1);
  4811. NotImplemented("llParcelMediaQuery");
  4812. }
  4813. public LSL_Types.LSLInteger llModPow(int a, int b, int c)
  4814. {
  4815. m_host.AddScriptLPS(1);
  4816. Int64 tmp = 0;
  4817. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  4818. return Convert.ToInt32(tmp);
  4819. }
  4820. public LSL_Types.LSLInteger llGetInventoryType(string name)
  4821. {
  4822. m_host.AddScriptLPS(1);
  4823. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4824. {
  4825. if (inv.Value.Name == name)
  4826. {
  4827. return inv.Value.InvType;
  4828. }
  4829. }
  4830. return -1;
  4831. }
  4832. public void llSetPayPrice(int price, LSL_Types.list quick_pay_buttons)
  4833. {
  4834. m_host.AddScriptLPS(1);
  4835. if (quick_pay_buttons.Data.Length != 4)
  4836. {
  4837. LSLError("List must have 4 elements");
  4838. return;
  4839. }
  4840. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  4841. m_host.ParentGroup.RootPart.PayPrice[1]=(int)quick_pay_buttons.Data[0];
  4842. m_host.ParentGroup.RootPart.PayPrice[2]=(int)quick_pay_buttons.Data[1];
  4843. m_host.ParentGroup.RootPart.PayPrice[3]=(int)quick_pay_buttons.Data[2];
  4844. m_host.ParentGroup.RootPart.PayPrice[4]=(int)quick_pay_buttons.Data[3];
  4845. }
  4846. public LSL_Types.Vector3 llGetCameraPos()
  4847. {
  4848. m_host.AddScriptLPS(1);
  4849. NotImplemented("llGetCameraPos");
  4850. return new LSL_Types.Vector3();
  4851. }
  4852. public LSL_Types.Quaternion llGetCameraRot()
  4853. {
  4854. m_host.AddScriptLPS(1);
  4855. NotImplemented("llGetCameraRot");
  4856. return new LSL_Types.Quaternion();
  4857. }
  4858. public void llSetPrimURL()
  4859. {
  4860. m_host.AddScriptLPS(1);
  4861. NotImplemented("llSetPrimURL");
  4862. }
  4863. public void llRefreshPrimURL()
  4864. {
  4865. m_host.AddScriptLPS(1);
  4866. NotImplemented("llRefreshPrimURL");
  4867. }
  4868. public string llEscapeURL(string url)
  4869. {
  4870. m_host.AddScriptLPS(1);
  4871. try
  4872. {
  4873. return Uri.EscapeUriString(url);
  4874. }
  4875. catch (Exception ex)
  4876. {
  4877. return "llEscapeURL: " + ex.ToString();
  4878. }
  4879. }
  4880. public string llUnescapeURL(string url)
  4881. {
  4882. m_host.AddScriptLPS(1);
  4883. try
  4884. {
  4885. return Uri.UnescapeDataString(url);
  4886. }
  4887. catch (Exception ex)
  4888. {
  4889. return "llUnescapeURL: " + ex.ToString();
  4890. }
  4891. }
  4892. public void llMapDestination(string simname, LSL_Types.Vector3 pos, LSL_Types.Vector3 look_at)
  4893. {
  4894. m_host.AddScriptLPS(1);
  4895. NotImplemented("llMapDestination");
  4896. }
  4897. public void llAddToLandBanList(string avatar, double hours)
  4898. {
  4899. m_host.AddScriptLPS(1);
  4900. LLUUID key;
  4901. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4902. if (land.ownerID == m_host.OwnerID)
  4903. {
  4904. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  4905. if (LLUUID.TryParse(avatar, out key))
  4906. {
  4907. entry.AgentID = key;
  4908. entry.Flags = ParcelManager.AccessList.Ban;
  4909. entry.Time = DateTime.Now.AddHours(hours);
  4910. land.parcelAccessList.Add(entry);
  4911. }
  4912. }
  4913. }
  4914. public void llRemoveFromLandPassList(string avatar)
  4915. {
  4916. m_host.AddScriptLPS(1);
  4917. LLUUID key;
  4918. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4919. if (land.ownerID == m_host.OwnerID)
  4920. {
  4921. if (LLUUID.TryParse(avatar, out key))
  4922. {
  4923. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  4924. {
  4925. if (entry.AgentID == key && entry.Flags == ParcelManager.AccessList.Access)
  4926. {
  4927. land.parcelAccessList.Remove(entry);
  4928. break;
  4929. }
  4930. }
  4931. }
  4932. }
  4933. }
  4934. public void llRemoveFromLandBanList(string avatar)
  4935. {
  4936. m_host.AddScriptLPS(1);
  4937. LLUUID key;
  4938. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  4939. if (land.ownerID == m_host.OwnerID)
  4940. {
  4941. if (LLUUID.TryParse(avatar, out key))
  4942. {
  4943. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  4944. {
  4945. if (entry.AgentID == key && entry.Flags == ParcelManager.AccessList.Ban)
  4946. {
  4947. land.parcelAccessList.Remove(entry);
  4948. break;
  4949. }
  4950. }
  4951. }
  4952. }
  4953. }
  4954. public void llSetCameraParams(LSL_Types.list rules)
  4955. {
  4956. m_host.AddScriptLPS(1);
  4957. NotImplemented("llSetCameraParams");
  4958. }
  4959. public void llClearCameraParams()
  4960. {
  4961. m_host.AddScriptLPS(1);
  4962. NotImplemented("llClearCameraParams");
  4963. }
  4964. public double llListStatistics(int operation, LSL_Types.list src)
  4965. {
  4966. m_host.AddScriptLPS(1);
  4967. LSL_Types.list nums = LSL_Types.list.ToDoubleList(src);
  4968. switch (operation)
  4969. {
  4970. case BuiltIn_Commands_BaseClass.LIST_STAT_RANGE:
  4971. return nums.Range();
  4972. case BuiltIn_Commands_BaseClass.LIST_STAT_MIN:
  4973. return nums.Min();
  4974. case BuiltIn_Commands_BaseClass.LIST_STAT_MAX:
  4975. return nums.Max();
  4976. case BuiltIn_Commands_BaseClass.LIST_STAT_MEAN:
  4977. return nums.Mean();
  4978. case BuiltIn_Commands_BaseClass.LIST_STAT_MEDIAN:
  4979. return nums.Median();
  4980. case BuiltIn_Commands_BaseClass.LIST_STAT_NUM_COUNT:
  4981. return nums.NumericLength();
  4982. case BuiltIn_Commands_BaseClass.LIST_STAT_STD_DEV:
  4983. return nums.StdDev();
  4984. case BuiltIn_Commands_BaseClass.LIST_STAT_SUM:
  4985. return nums.Sum();
  4986. case BuiltIn_Commands_BaseClass.LIST_STAT_SUM_SQUARES:
  4987. return nums.SumSqrs();
  4988. case BuiltIn_Commands_BaseClass.LIST_STAT_GEOMETRIC_MEAN:
  4989. return nums.GeometricMean();
  4990. case BuiltIn_Commands_BaseClass.LIST_STAT_HARMONIC_MEAN:
  4991. return nums.HarmonicMean();
  4992. default:
  4993. return 0.0;
  4994. }
  4995. }
  4996. public LSL_Types.LSLInteger llGetUnixTime()
  4997. {
  4998. m_host.AddScriptLPS(1);
  4999. return Util.UnixTimeSinceEpoch();
  5000. }
  5001. public LSL_Types.LSLInteger llGetParcelFlags(LSL_Types.Vector3 pos)
  5002. {
  5003. m_host.AddScriptLPS(1);
  5004. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).landData.landFlags;
  5005. }
  5006. public LSL_Types.LSLInteger llGetRegionFlags()
  5007. {
  5008. m_host.AddScriptLPS(1);
  5009. return (int)World.RegionInfo.EstateSettings.regionFlags;
  5010. }
  5011. public string llXorBase64StringsCorrect(string str1, string str2)
  5012. {
  5013. m_host.AddScriptLPS(1);
  5014. string ret = String.Empty;
  5015. string src1 = llBase64ToString(str1);
  5016. string src2 = llBase64ToString(str2);
  5017. int c = 0;
  5018. for (int i = 0; i < src1.Length; i++)
  5019. {
  5020. ret += src1[i] ^ src2[c];
  5021. c++;
  5022. if (c > src2.Length)
  5023. c = 0;
  5024. }
  5025. return llStringToBase64(ret);
  5026. }
  5027. public string llHTTPRequest(string url, LSL_Types.list parameters, string body)
  5028. {
  5029. // Partial implementation: support for parameter flags needed
  5030. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  5031. // parameter flags support are implemented in ScriptsHttpRequests.cs
  5032. // in StartHttpRequest
  5033. m_host.AddScriptLPS(1);
  5034. IHttpRequests httpScriptMod =
  5035. m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
  5036. List<string> param = new List<string>();
  5037. foreach (object o in parameters.Data)
  5038. {
  5039. param.Add(o.ToString());
  5040. }
  5041. LLUUID reqID = httpScriptMod.
  5042. StartHttpRequest(m_localID, m_itemID, url, param, body);
  5043. if (reqID != LLUUID.Zero)
  5044. return reqID.ToString();
  5045. else
  5046. return null;
  5047. }
  5048. public void llResetLandBanList()
  5049. {
  5050. m_host.AddScriptLPS(1);
  5051. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  5052. if (land.ownerID == m_host.OwnerID)
  5053. {
  5054. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  5055. {
  5056. if (entry.Flags == ParcelManager.AccessList.Ban)
  5057. {
  5058. land.parcelAccessList.Remove(entry);
  5059. }
  5060. }
  5061. }
  5062. }
  5063. public void llResetLandPassList()
  5064. {
  5065. m_host.AddScriptLPS(1);
  5066. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  5067. if (land.ownerID == m_host.OwnerID)
  5068. {
  5069. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  5070. {
  5071. if (entry.Flags == ParcelManager.AccessList.Access)
  5072. {
  5073. land.parcelAccessList.Remove(entry);
  5074. }
  5075. }
  5076. }
  5077. }
  5078. public LSL_Types.LSLInteger llGetParcelPrimCount(LSL_Types.Vector3 pos, int category, int sim_wide)
  5079. {
  5080. m_host.AddScriptLPS(1);
  5081. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  5082. if (land == null)
  5083. {
  5084. return 0;
  5085. }
  5086. else
  5087. {
  5088. if (sim_wide == 1)
  5089. {
  5090. if (category == 0)
  5091. {
  5092. return land.simwidePrims;
  5093. }
  5094. else
  5095. {
  5096. //public int simwideArea = 0;
  5097. return 0;
  5098. }
  5099. }
  5100. else
  5101. {
  5102. if (category == 0)//Total Prims
  5103. {
  5104. return 0;//land.
  5105. }
  5106. else if (category == 1)//Owner Prims
  5107. {
  5108. return land.ownerPrims;
  5109. }
  5110. else if (category == 2)//Group Prims
  5111. {
  5112. return land.groupPrims;
  5113. }
  5114. else if (category == 3)//Other Prims
  5115. {
  5116. return land.otherPrims;
  5117. }
  5118. else if (category == 4)//Selected
  5119. {
  5120. return land.selectedPrims;
  5121. }
  5122. else if (category == 5)//Temp
  5123. {
  5124. return 0;//land.
  5125. }
  5126. }
  5127. }
  5128. return 0;
  5129. }
  5130. public LSL_Types.list llGetParcelPrimOwners(LSL_Types.Vector3 pos)
  5131. {
  5132. m_host.AddScriptLPS(1);
  5133. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5134. LSL_Types.list ret = new LSL_Types.list();
  5135. if (land != null)
  5136. {
  5137. foreach (KeyValuePair<LLUUID, int> d in land.getLandObjectOwners())
  5138. {
  5139. ret.Add(d.Key.ToString());
  5140. ret.Add(d.Value);
  5141. }
  5142. }
  5143. return ret;
  5144. }
  5145. public LSL_Types.LSLInteger llGetObjectPrimCount(string object_id)
  5146. {
  5147. m_host.AddScriptLPS(1);
  5148. SceneObjectPart part = World.GetSceneObjectPart(new LLUUID(object_id));
  5149. if (part == null)
  5150. {
  5151. return 0;
  5152. }
  5153. else
  5154. {
  5155. return part.ParentGroup.Children.Count;
  5156. }
  5157. }
  5158. public LSL_Types.LSLInteger llGetParcelMaxPrims(LSL_Types.Vector3 pos, int sim_wide)
  5159. {
  5160. m_host.AddScriptLPS(1);
  5161. // Alondria: This currently just is utilizing the normal grid's 0.22 prims/m2 calculation
  5162. // Which probably will be irrelevent in OpenSim....
  5163. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  5164. float bonusfactor = World.RegionInfo.EstateSettings.objectBonusFactor;
  5165. if (land == null)
  5166. {
  5167. return 0;
  5168. }
  5169. if (sim_wide == 1)
  5170. {
  5171. decimal v = land.simwideArea * (decimal)(0.22) * (decimal)bonusfactor;
  5172. return (int)v;
  5173. }
  5174. else
  5175. {
  5176. decimal v = land.area * (decimal)(0.22) * (decimal)bonusfactor;
  5177. return (int)v;
  5178. }
  5179. }
  5180. public LSL_Types.list llGetParcelDetails(LSL_Types.Vector3 pos, LSL_Types.list param)
  5181. {
  5182. m_host.AddScriptLPS(1);
  5183. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  5184. if (land == null)
  5185. {
  5186. return new LSL_Types.list(0);
  5187. }
  5188. LSL_Types.list ret = new LSL_Types.list();
  5189. foreach (object o in param.Data)
  5190. {
  5191. switch (o.ToString())
  5192. {
  5193. case "0":
  5194. ret = ret + new LSL_Types.list(land.landName);
  5195. break;
  5196. case "1":
  5197. ret = ret + new LSL_Types.list(land.landDesc);
  5198. break;
  5199. case "2":
  5200. ret = ret + new LSL_Types.list(land.ownerID.ToString());
  5201. break;
  5202. case "3":
  5203. ret = ret + new LSL_Types.list(land.groupID.ToString());
  5204. break;
  5205. case "4":
  5206. ret = ret + new LSL_Types.list(land.area);
  5207. break;
  5208. default:
  5209. ret = ret + new LSL_Types.list(0);
  5210. break;
  5211. }
  5212. }
  5213. return ret;
  5214. }
  5215. public void llSetLinkTexture(int linknumber, string texture, int face)
  5216. {
  5217. m_host.AddScriptLPS(1);
  5218. NotImplemented("llSetLinkTexture");
  5219. }
  5220. public string llStringTrim(string src, int type)
  5221. {
  5222. m_host.AddScriptLPS(1);
  5223. if (type == (int)BuiltIn_Commands_BaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  5224. if (type == (int)BuiltIn_Commands_BaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  5225. if (type == (int)BuiltIn_Commands_BaseClass.STRING_TRIM) { return src.Trim(); }
  5226. return src;
  5227. }
  5228. public LSL_Types.list llGetObjectDetails(string id, LSL_Types.list args)
  5229. {
  5230. m_host.AddScriptLPS(1);
  5231. LSL_Types.list ret = new LSL_Types.list();
  5232. LLUUID key = new LLUUID();
  5233. if (LLUUID.TryParse(id, out key))
  5234. {
  5235. ScenePresence av = World.GetScenePresence(key);
  5236. if (av != null)
  5237. {
  5238. foreach (object o in args.Data)
  5239. {
  5240. switch (o.ToString())
  5241. {
  5242. case "1":
  5243. ret.Add(av.Firstname + " " + av.Lastname);
  5244. break;
  5245. case "2":
  5246. ret.Add("");
  5247. break;
  5248. case "3":
  5249. ret.Add(new LSL_Types.Vector3((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  5250. break;
  5251. case "4":
  5252. ret.Add(new LSL_Types.Quaternion((double)av.Rotation.x, (double)av.Rotation.y, (double)av.Rotation.z, (double)av.Rotation.w));
  5253. break;
  5254. case "5":
  5255. ret.Add(new LSL_Types.Vector3(av.Velocity.X,av.Velocity.Y,av.Velocity.Z));
  5256. break;
  5257. case "6":
  5258. ret.Add(id);
  5259. break;
  5260. case "7":
  5261. ret.Add(LLUUID.Zero.ToString());
  5262. break;
  5263. case "8":
  5264. ret.Add(LLUUID.Zero.ToString());
  5265. break;
  5266. }
  5267. }
  5268. return ret;
  5269. }
  5270. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5271. if (obj != null)
  5272. {
  5273. foreach (object o in args.Data)
  5274. {
  5275. switch (o.ToString())
  5276. {
  5277. case "1":
  5278. ret.Add(obj.Name);
  5279. break;
  5280. case "2":
  5281. ret.Add(obj.Description);
  5282. break;
  5283. case "3":
  5284. ret.Add(new LSL_Types.Vector3(obj.AbsolutePosition.X,obj.AbsolutePosition.Y,obj.AbsolutePosition.Z));
  5285. break;
  5286. case "4":
  5287. ret.Add(new LSL_Types.Quaternion(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
  5288. break;
  5289. case "5":
  5290. ret.Add(new LSL_Types.Vector3(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
  5291. break;
  5292. case "6":
  5293. ret.Add(obj.OwnerID.ToString());
  5294. break;
  5295. case "7":
  5296. ret.Add(obj.GroupID.ToString());
  5297. break;
  5298. case "8":
  5299. ret.Add(obj.CreatorID.ToString());
  5300. break;
  5301. }
  5302. }
  5303. return ret;
  5304. }
  5305. }
  5306. return new LSL_Types.list();
  5307. }
  5308. internal LLUUID ScriptByName(string name)
  5309. {
  5310. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  5311. {
  5312. if (item.Type == 10 && item.Name == name)
  5313. return item.ItemID;
  5314. }
  5315. return LLUUID.Zero;
  5316. }
  5317. internal void ShoutError(string msg)
  5318. {
  5319. llShout(BuiltIn_Commands_BaseClass.DEBUG_CHANNEL, msg);
  5320. }
  5321. internal void NotImplemented(string command)
  5322. {
  5323. if (throwErrorOnNotImplemented)
  5324. throw new NotImplementedException("Command not implemented: " + command);
  5325. }
  5326. internal void Deprecated(string command)
  5327. {
  5328. throw new Exception("Command deprecated: " + command);
  5329. }
  5330. internal void LSLError(string msg)
  5331. {
  5332. throw new Exception("LSL Runtime Error: " + msg);
  5333. }
  5334. public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset);
  5335. private void WithNotecard(LLUUID assetID, AssetRequestCallback cb)
  5336. {
  5337. World.AssetCache.GetAsset(assetID, delegate(LLUUID i, AssetBase a) { cb(i, a); }, false);
  5338. }
  5339. public string llGetNumberOfNotecardLines(string name)
  5340. {
  5341. m_host.AddScriptLPS(1);
  5342. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  5343. {
  5344. if (item.Type == 7 && item.Name == name)
  5345. {
  5346. LLUUID tid = m_ScriptEngine.m_ASYNCLSLCommandManager.
  5347. m_Dataserver.RegisterRequest(m_localID,
  5348. m_itemID, item.AssetID.ToString());
  5349. if(NotecardCache.IsCached(item.AssetID))
  5350. {
  5351. m_ScriptEngine.m_ASYNCLSLCommandManager.
  5352. m_Dataserver.DataserverReply(item.AssetID.ToString(),
  5353. NotecardCache.GetLines(item.AssetID).ToString());
  5354. return tid.ToString();
  5355. }
  5356. WithNotecard(item.AssetID, delegate (LLUUID id, AssetBase a)
  5357. {
  5358. System.Text.ASCIIEncoding enc =
  5359. new System.Text.ASCIIEncoding();
  5360. string data = enc.GetString(a.Data);
  5361. Console.WriteLine(data);
  5362. NotecardCache.Cache(id, data);
  5363. m_ScriptEngine.m_ASYNCLSLCommandManager.
  5364. m_Dataserver.DataserverReply(id.ToString(),
  5365. NotecardCache.GetLines(id).ToString());
  5366. });
  5367. return tid.ToString();
  5368. }
  5369. }
  5370. return LLUUID.Zero.ToString();
  5371. }
  5372. public string llGetNotecardLine(string name, int line)
  5373. {
  5374. m_host.AddScriptLPS(1);
  5375. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  5376. {
  5377. if (item.Type == 7 && item.Name == name)
  5378. {
  5379. LLUUID tid = m_ScriptEngine.m_ASYNCLSLCommandManager.
  5380. m_Dataserver.RegisterRequest(m_localID,
  5381. m_itemID, item.AssetID.ToString());
  5382. if(NotecardCache.IsCached(item.AssetID))
  5383. {
  5384. m_ScriptEngine.m_ASYNCLSLCommandManager.
  5385. m_Dataserver.DataserverReply(item.AssetID.ToString(),
  5386. NotecardCache.GetLine(item.AssetID, line));
  5387. return tid.ToString();
  5388. }
  5389. WithNotecard(item.AssetID, delegate (LLUUID id, AssetBase a)
  5390. {
  5391. System.Text.ASCIIEncoding enc =
  5392. new System.Text.ASCIIEncoding();
  5393. string data = enc.GetString(a.Data);
  5394. Console.WriteLine(data);
  5395. NotecardCache.Cache(id, data);
  5396. m_ScriptEngine.m_ASYNCLSLCommandManager.
  5397. m_Dataserver.DataserverReply(id.ToString(),
  5398. NotecardCache.GetLine(id, line));
  5399. });
  5400. return tid.ToString();
  5401. }
  5402. }
  5403. return String.Empty;
  5404. }
  5405. }
  5406. public class NotecardCache
  5407. {
  5408. private class Notecard
  5409. {
  5410. public string[] text;
  5411. public DateTime lastRef;
  5412. }
  5413. private static Dictionary<LLUUID, Notecard> m_Notecards =
  5414. new Dictionary<LLUUID, Notecard>();
  5415. public static void Cache(LLUUID assetID, string text)
  5416. {
  5417. CacheCheck();
  5418. lock(m_Notecards)
  5419. {
  5420. if(m_Notecards.ContainsKey(assetID))
  5421. return;
  5422. Notecard nc = new Notecard();
  5423. nc.lastRef=DateTime.Now;
  5424. nc.text = ParseText(text.Replace("\r", "").Split('\n'));
  5425. m_Notecards[assetID] = nc;
  5426. }
  5427. }
  5428. private static string[] ParseText(string[] input)
  5429. {
  5430. int idx=0;
  5431. int level=0;
  5432. List<string> output = new List<string>();
  5433. string[] words;
  5434. while(idx < input.Length)
  5435. {
  5436. if(input[idx] == "{")
  5437. {
  5438. level++;
  5439. idx++;
  5440. continue;
  5441. }
  5442. if(input[idx]== "}")
  5443. {
  5444. level--;
  5445. idx++;
  5446. continue;
  5447. }
  5448. switch(level)
  5449. {
  5450. case 0:
  5451. words = input[idx].Split(' '); // Linden text ver
  5452. int version = int.Parse(words[3]);
  5453. if(version != 2)
  5454. return new String[0];
  5455. break;
  5456. case 1:
  5457. words = input[idx].Split(' ');
  5458. if(words[0] == "LLEmbeddedItems")
  5459. break;
  5460. if(words[0] == "Text")
  5461. {
  5462. int len = int.Parse(words[2]);
  5463. idx++;
  5464. int count=-1;
  5465. while(count < len)
  5466. {
  5467. int l = input[idx].Length;
  5468. string ln = input[idx];
  5469. int need = len-count-1;
  5470. if(ln.Length > need)
  5471. ln=ln.Substring(0, need);
  5472. output.Add(ln);
  5473. count+=ln.Length+1;
  5474. idx++;
  5475. }
  5476. return output.ToArray();
  5477. }
  5478. break;
  5479. case 2:
  5480. words = input[idx].Split(' '); // count
  5481. if(words[0] == "count")
  5482. {
  5483. int c = int.Parse(words[1]);
  5484. if(c > 0)
  5485. return new String[0];
  5486. break;
  5487. }
  5488. break;
  5489. }
  5490. idx++;
  5491. }
  5492. return output.ToArray();
  5493. }
  5494. public static bool IsCached(LLUUID assetID)
  5495. {
  5496. lock(m_Notecards)
  5497. {
  5498. return m_Notecards.ContainsKey(assetID);
  5499. }
  5500. }
  5501. public static int GetLines(LLUUID assetID)
  5502. {
  5503. if(!IsCached(assetID))
  5504. return -1;
  5505. lock(m_Notecards)
  5506. {
  5507. m_Notecards[assetID].lastRef = DateTime.Now;
  5508. return m_Notecards[assetID].text.Length;
  5509. }
  5510. }
  5511. public static string GetLine(LLUUID assetID, int line)
  5512. {
  5513. if(line < 0)
  5514. return "";
  5515. string data;
  5516. if(!IsCached(assetID))
  5517. return "";
  5518. lock(m_Notecards)
  5519. {
  5520. m_Notecards[assetID].lastRef = DateTime.Now;
  5521. if(line >= m_Notecards[assetID].text.Length)
  5522. return "\n\n\n";
  5523. data=m_Notecards[assetID].text[line];
  5524. if(data.Length > 255)
  5525. data = data.Substring(0, 255);
  5526. return data;
  5527. }
  5528. }
  5529. public static void CacheCheck()
  5530. {
  5531. foreach (LLUUID key in new List<LLUUID>(m_Notecards.Keys))
  5532. {
  5533. Notecard nc = m_Notecards[key];
  5534. if(nc.lastRef.AddSeconds(30) < DateTime.Now)
  5535. m_Notecards.Remove(key);
  5536. }
  5537. }
  5538. }
  5539. }