LSL HTTP server/examples: Difference between revisions
Jump to navigation
Jump to search
Kelly Linden (talk | contribs) New page: === Hello World! === Classic example. <lsl> default { state_entry() { llRequestPublicURL(); } http_request(key id, string method, string body) { if (me... |
Kelly Linden (talk | contribs) |
||
| Line 23: | Line 23: | ||
llHTTPResponse(id,200,"Hello World!"); | llHTTPResponse(id,200,"Hello World!"); | ||
} | } | ||
} | |||
} | |||
</lsl> | |||
== Visitor List == | |||
A list of residents within sensor range of the server: | |||
<lsl> | |||
key request_id = NULL_KEY; | |||
default | |||
{ | |||
state_entry() | |||
{ | |||
llRequestPublicURL(); | |||
} | |||
http_request(key id, string method, string body) | |||
{ | |||
llSay(0,method); | |||
integer handled = FALSE; | |||
if (method == URL_REQUEST_GRANTED) | |||
{ | |||
llSay(0,"URL: " + body); | |||
handled = TRUE; | |||
} | |||
else if (method == URL_REQUEST_DENIED) | |||
{ | |||
llSay(0, "Something went wrong, no url. " + body); | |||
handled = TRUE; | |||
} | |||
else if (method == "GET") | |||
{ | |||
if (request_id != NULL_KEY) | |||
{ | |||
// This is cheesy. | |||
// Handling multiple requests means list management though. | |||
llHTTPResponse(id,200,"Sorry, busy right now.\n\tTry again soon."); | |||
} | |||
else | |||
{ | |||
request_id = id; | |||
llSensor("",NULL_KEY,AGENT,96,PI); | |||
} | |||
handled = TRUE; | |||
} | |||
if (!handled) | |||
{ | |||
llHTTPResponse(id,500,"Unsupported method."); | |||
} | |||
} | |||
no_sensor() | |||
{ | |||
llHTTPResponse(request_id, 200, "There is no one here."); | |||
request_id = NULL_KEY; | |||
} | |||
sensor(integer n) | |||
{ | |||
string output = "There are " + (string)n + " avatars nearby:"; | |||
integer i; | |||
for (i = 0;i<n;++i) | |||
{ | |||
output += "\n\t" + llDetectedName(i); | |||
} | |||
llHTTPResponse(request_id,200,output); | |||
request_id = NULL_KEY; | |||
} | } | ||
} | } | ||
</lsl> | </lsl> | ||
Revision as of 16:02, 18 July 2008
Hello World!
Classic example. <lsl> default {
state_entry()
{
llRequestPublicURL();
}
http_request(key id, string method, string body)
{
if (method == URL_REQUEST_GRANTED)
{
llSay(0,"URL: " + body);
}
else if (method == URL_REQUEST_DENIED)
{
llSay(0, "Something went wrong, no url. " + body);
}
else if (method == "GET")
{
llHTTPResponse(id,200,"Hello World!");
}
}
} </lsl>
Visitor List
A list of residents within sensor range of the server: <lsl> key request_id = NULL_KEY;
default {
state_entry()
{
llRequestPublicURL();
}
http_request(key id, string method, string body)
{
llSay(0,method);
integer handled = FALSE;
if (method == URL_REQUEST_GRANTED)
{
llSay(0,"URL: " + body);
handled = TRUE;
}
else if (method == URL_REQUEST_DENIED)
{
llSay(0, "Something went wrong, no url. " + body);
handled = TRUE;
}
else if (method == "GET")
{
if (request_id != NULL_KEY)
{
// This is cheesy.
// Handling multiple requests means list management though.
llHTTPResponse(id,200,"Sorry, busy right now.\n\tTry again soon.");
}
else
{
request_id = id;
llSensor("",NULL_KEY,AGENT,96,PI);
}
handled = TRUE;
}
if (!handled)
{
llHTTPResponse(id,500,"Unsupported method.");
}
}
no_sensor()
{
llHTTPResponse(request_id, 200, "There is no one here.");
request_id = NULL_KEY;
}
sensor(integer n)
{
string output = "There are " + (string)n + " avatars nearby:";
integer i;
for (i = 0;i<n;++i)
{
output += "\n\t" + llDetectedName(i);
}
llHTTPResponse(request_id,200,output);
request_id = NULL_KEY;
}
} </lsl>