LSL_Api.cs 372 KB

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