Difference between revisions of "User:Void Singer/Red Tea"
Void Singer (talk | contribs) m (~pretty-fied with html highlighting) |
Void Singer (talk | contribs) m (~technical error corrected) |
||
Line 160: | Line 160: | ||
* Save in a notecard named "index.tsp" | * Save in a notecard named "index.tsp" | ||
<html4strict><h1>This is a sample Index Page</h1> | <html4strict><h1>This is a sample Index Page</h1> | ||
<p>would you like to <a href="page1.tsp">go to page 1</a>?</html4strict> | <p>would you like to <a href="page1.tsp">go to page 1</a>?</p></html4strict> | ||
^ [[User:Void Singer/Teacup#Return_to_Void_Singers_user_page|Return to top]] | ^ [[User:Void Singer/Teacup#Return_to_Void_Singers_user_page|Return to top]] | ||
Line 167: | Line 167: | ||
* Save in a notecard named "page1.tsp" | * Save in a notecard named "page1.tsp" | ||
<html4strict><h1>This is a sample linked page</h1> | <html4strict><h1>This is a sample linked page</h1> | ||
<p>would you like to <a href="index.tsp">go to the index</a>?</html4strict> | <p>would you like to <a href="index.tsp">go to the index</a>?</p></html4strict> | ||
:[[User:Void Singer/Teacup#Return_to_Void_Singers_user_page|Return to top]] | :[[User:Void Singer/Teacup#Return_to_Void_Singers_user_page|Return to top]] | ||
}} | }} |
Revision as of 14:51, 19 April 2011
Red Tea
What is it?
Red Tea is an open source File Service custom built for Teacup/Saucer
How does it work?
When Red Tea starts, it looks for any notecards in the prim, reads them, converting and wrapping any notecards with names ending with ".tsp", then storing them in memory, waiting for a request from the Teacup server. If the number of notecards changes it waits 3 seconds then restarts.
Format Requirments?
Red Tea reads a modified html page from a notecard
- For html content, the notecard name should end with ".tsp"
- For html content, the notecard contents are limited to what's valid inside a normal html "body" tag.
- no more than 255 bytes per line in the notecard (this is an LSL limitation)
Quick Start
So you don't want to read a bunch of tech babble, you just want to make a website in a prim right? Well I can sympathize so here are some (mostly) easy steps to get you up and running fast...
- Rez a box and name it something creative, like "My website"#Sample_Index.tsp
- Copy the text in the grey box below Code: teacup.js into a notecard named "teacup.js", save it, and drop it in your rezzed box
- You May want to Edit this file to your liking first... You can add most valid javascript functions that do not rely on body onload behavior.
- Copy the text in the grey box below Code: teacup.css into a notecard named "teacup.css", save it, and drop it in your rezzed box
- You May want to Edit this file to your liking first... You can use any valid css.
- Copy the text in the grey box below Code: Sample Index.tsp into a notecard named "index.tsp", save it, and drop it in your rezzed box
- You May want to Edit this file to your liking first... You can use any html that is valid inside of a body tag.
- Copy the text in the grey box below Code: Sample Page1.js into a notecard named "page1.tsp", save it, and drop it in your rezzed box
- You May want to Edit this file to your liking first... You can use any html that is valid inside of a body tag.
- Copy the text in the grey box below Code: Red Tea into a script named "Red Tea v0.3", save it, and drop it in your rezzed box
- Go here and start at step 2...
Code
Red Tea
- Save in a script named "Red Tea v0.3"
<lsl>/*( Red Tea v0.3 )*/
//-- Master Handling lists list gLstNom; list gLstTxt;
//-- These track memory while loading integer gIntCap; integer gIntBfr;
//-- these handle the notecard loading key gKeyQry; string gStrNcd; integer gIntNcd; string gStrTmp;
default{
state_entry(){ //-- grab all possible notecard names if (gIntCap = llGetInventoryNumber( INVENTORY_NOTECARD )){ llWhisper( 0, "Attempting to load " + (string)gIntCap + " notecards" ); do{ gLstNom += [llGetInventoryName( INVENTORY_NOTECARD, gIntNcd )]; }while (++gIntNcd < gIntCap); //-- work on the firs one. gKeyQry = llGetNotecardLine( gStrNcd = llList2String( gLstNom, 0 ), gIntNcd = 0 ); gIntCap = llGetFreeMemory(); }else{ llWhisper( 0, "No content to load" ); } } changed( integer vBitChg ){ if (CHANGED_INVENTORY & vBitChg){ //-- when inventory changes, only restart if the notecard count changed if (llGetInventoryNumber( INVENTORY_NOTECARD ) != (gLstNom != [])){ llSetTimerEvent( 3.0 ); } } } timer(){ llResetScript(); } dataserver( key vKeyQID, string vStrDta ){ if (gKeyQry == vKeyQID){ //-- is this our dataserver event? if (EOF == vStrDta){ //-- did we finish the notecard? if (~llSubStringIndex( gStrNcd, ".tsp" )){ //-- is this a html page? gStrTmp = "vTea='" + gStrTmp + "';"; //-- wrap it } gLstTxt += [(gStrTmp = "") + gStrTmp]; //-- save it llWhisper( 0, gStrNcd + " successfully loaded"); llMessageLinked( LINK_SET, 22, gStrNcd, NULL_KEY ); if ((integer)(vStrDta = (string)(gIntCap - llGetFreeMemory())) > gIntBfr){ gIntBfr = (integer)vStrDta; //-- adjust buffer if needed } //-- test if we have more cards to read and room to spare if ((gIntNcd = -~llListFindList( gLstNom, [gStrNcd] )) < (gLstNom != []) && (gIntCap = llGetFreeMemory()) > gIntBfr){ gKeyQry = llGetNotecardLine( gStrNcd = llList2String( gLstNom, gIntNcd ), gIntNcd = 0 ); //-- get next card }else{ //-- out of cards or space gStrTmp = gKeyQry = ""; //-- clear vars //-- save totals and set conditional failure message if ((gIntCap = (gLstNom != [])) > (gIntNcd = (gLstTxt != []))){ gStrNcd = "\nFailed to read " + gStrNcd; }else{ gStrNcd = gStrTmp; }//-- report load llWhisper( 0, "Loaded " + (string)gIntNcd + " of " + (string)gIntCap + " pages" + (gStrNcd = "") + gStrNcd + "\n~" + (string)(llGetFreeMemory() - gIntBfr) + " bytes free" ); } }else{ //-- notecard read if (~llSubStringIndex( gStrNcd, ".tsp" )){ //-- is this a html page? //-- tweak for javascript wrapper compatibility vStrDta = llDumpList2String( llParseStringKeepNulls( vStrDta, ["\\"], [] ), "\\\\" ); vStrDta = llDumpList2String( llParseStringKeepNulls( vStrDta, ["'"], [] ), "\\'" ) + "\\n"; }else{ vStrDta += "\n"; } gStrTmp += vStrDta; //-- accumulate to variable if ((integer)(vStrDta = (string)(gIntCap - llGetFreeMemory())) > gIntBfr){ gIntBfr = (integer)vStrDta; //-- adjust buffer if needed } if ((gIntCap >> 1) > gIntBfr){ //-- test free space against buffer gKeyQry = llGetNotecardLine( gStrNcd, ++gIntNcd ); //-- get next line }else{ //-- our saftey cap was exceeded, stop and report what we have gLstNom = llDeleteSubList( gLstNom, gIntNcd, -1 ); gIntCap = (gLstNom != []); gIntNcd = (gLstTxt != []); gStrTmp = gKeyQry = ""; llWhisper( 0, "Loaded " + (string)gIntNcd + " of " + (string)gIntCap + " page(s)\nFailed while reading " + gStrNcd + "\n~" + (string)(llGetFreeMemory() - gIntBfr) + " bytes free" ); } } } } link_message( integer vIntSrc, integer vIntDta, string vStrDta, key vKeyDta ){ if (vKeyDta){ //-- valid key? if (418 == vIntDta){ //-- server request? if (~vIntDta = llListFindList( gLstNom, [vStrDta] )){ //-- do we have that? llMessageLinked( vIntSrc, 200, llList2String( gLstTxt, vIntDta ), vKeyDta ); } } }//-- we serve pages fast, so we don't report loaded pages on server startup message and instead rely on lazy detection }
} /*//-- License Text --//*/ /*// Free to copy, use, modify, distribute, or sell, with attribution. //*/ /*// (C)2011 (CC-BY) [ http://creativecommons.org/licenses/by/3.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*// All usages must contain a plain text copy of the previous 2 lines. //*/ /*//-- --//*/</lsl> ^ Return to top
Sample Index.tsp
- Save in a notecard named "index.tsp"
This is a sample Index Page
would you like to <a href="page1.tsp">go to page 1</a>?
</html4strict>Sample Page1.tsp
- Save in a notecard named "page1.tsp"
This is a sample linked page
would you like to <a href="index.tsp">go to the index</a>?
</html4strict>Notes
Compatible Servers and Extensions
Teacup/Saucer - Server front end
Known Bugs
- Extra line break inserted at the end of every ".tsp" or text file
- If the server request a file that has a notecard, before that notecard is finished loading, a 200 "Success" response will be generated and an empty file will be served.
- Loading large files before small ones may lock them out if the buffer limit is reached. Try to read small files first. (they are read in alphabetic order)
Planned Upgrades
- None really, the intent is to be an example. other "flavors" can use different methods. but it may get minor updates as time passes
"Red Tea" is going to be transitioned to "Saucer", once saucer is complete, the name "Red Tea" will be release for other developers to use.- Originally this made sense, but upon further consideration, there still needs to be a simple basic File Service system until others are developed.
ChangeLog / Old Versions
- v0.3
- No longer sends 404 messages of it's own
- No longer restarts on every inventory change, only if the notecard count changes from what it has already read.
- v0.2
- Initial Public Release
NOTE TO WIKI EDITORS
I have kept this page as a sub page of my user page to denote that it should NOT be edited except to correct errors, add confirmed bugs, or add related resources.
The intent is to ensure executive control is in one person's hands to retain a cohesive vision of it's development.
If you have an improvement suggestion, or request, please use the discussion page.