LSL_Api.cs 389 KB

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