LSL_BuiltIn_Commands.cs 258 KB

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