LSL_Api.cs 346 KB

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