LSL_Api.cs 359 KB

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