Difference between revisions of "User:Kuraiko Yoshikawa/LSL/contact from outside"
Jump to navigation
Jump to search
Email
(Created page with '__NOTOC__ <div style="width: 200px; padding: 2px; border: solid 1px lightgray; margin-bottom: 10px; background: #F4F8FB;"> '''Content:''' *Email **[[#PHP Script|PHP Sc...') |
m (Improve syntax highlighting (removing old, obsolete tags); drastically removed all extraneous <div> and other attempts at non-standard formatting which would mostly be ignored anyway) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
**[[#cURL PHP Script|cURL PHP Script]] | **[[#cURL PHP Script|cURL PHP Script]] | ||
**[[#Limits|Limits]] | **[[#Limits|Limits]] | ||
</div> | </div> | ||
== Email == | == Email == | ||
If you can send mails via PHP from your webspace/server then sending emails to a script is a simple but not the fastest way. | |||
If you can send mails via PHP from your webspace/server then | |||
{{tooltip|Mailaddy|E-mail address}} from a prim is '''uuid@lsl.secondlife.com''' | |||
Mailaddy from a prim is '''uuid@lsl.secondlife.com''' | |||
== PHP Script == | == PHP Script == | ||
< | <syntaxhighlight lang="php"> | ||
<?php | <?php | ||
Line 38: | Line 32: | ||
?> | ?> | ||
</ | </syntaxhighlight> | ||
== LSL Script == | == LSL Script == | ||
< | <syntaxhighlight lang="lsl2"> | ||
default | default | ||
{ | { | ||
Line 62: | Line 53: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
== Limits == | == Limits == | ||
* The email queue is limited to 100 emails, any email after that is bounced. | * The email queue is limited to 100 emails, any email after that is bounced. | ||
* The message field may have a maximum of 1000 characters. This count includes the header information (address, subject, etc). | * The message field may have a maximum of 1000 characters. This count includes the header information (address, subject, etc). | ||
== GET Request over http-in == | |||
Sending variables/text to an [[LSL]] script via GET request is an easy way to use the 'new' http-in feature. | |||
However it isn't a way to send lots of data to the script. | |||
However it isn't a way to send | |||
== PHP Script == | == PHP Script == | ||
< | <syntaxhighlight lang="php"> | ||
<?php | <?php | ||
$script_url = "http://sim5363.agni.lindenlab.com:12046/cap/<your url cap here>/"; // Don't forget slash at the end | $script_url = "http://sim5363.agni.lindenlab.com:12046/cap/<your url cap here>/"; // Don't forget slash at the end | ||
Line 99: | Line 80: | ||
?> | ?> | ||
</ | </syntaxhighlight> | ||
== LSL Script == | == LSL Script == | ||
< | <syntaxhighlight lang="lsl2"> | ||
default | default | ||
{ | { | ||
Line 150: | Line 128: | ||
} | } | ||
} | } | ||
</syntaxhighlight> | |||
== Limits == | == Limits == | ||
* headers (accessed with [[llGetHTTPHeader]]) are limited to 255 bytes. With the script above you can send 255 bytes raw data (include the <nowiki><var></nowiki>=). | |||
* headers (accessed with llGetHTTPHeader) are limited to 255 bytes. With the script above you can send | * There is a limit of 64 pending [[http_request]]s | ||
* There is a limit of 64 pending http_request | |||
== POST Request over http-in == | == POST Request over http-in == | ||
Post request is the best way to send lots of data to an LSL Script however it isn't so a short/simple code to use it within PHP. | |||
Post request is the best way to send | Besides not all ISPs allow {{mono|fsockopen()}} or {{mono|cURL}} or connection on another port beyond the default (80 and 443). | ||
Besides not all ISPs allow fsockopen or cURL or connection on | |||
== fsockopen PHP Script == | == fsockopen PHP Script == | ||
This example is from Simba Fuhr: [[LSL_http_server/examples#Simple_script_for_sending_data_to_an_LSL_via_PHP|Simple Script for seding data...]] | This example is from Simba Fuhr: [[LSL_http_server/examples#Simple_script_for_sending_data_to_an_LSL_via_PHP|Simple Script for seding data...]] | ||
< | <syntaxhighlight lang="php"> | ||
<?php | <?php | ||
$Data = CallLSLScript("http://sim3015.aditi.lindenlab.com:12046/cap/<your script url cap>", "This is a post request test message via Sockets"); | $Data = CallLSLScript("http://sim3015.aditi.lindenlab.com:12046/cap/<your script url cap>", "This is a post request test message via Sockets"); | ||
Line 217: | Line 183: | ||
} | } | ||
?> | ?> | ||
</syntaxhighlight> | |||
</ | |||
== cURL PHP Script == | == cURL PHP Script == | ||
< | <syntaxhighlight lang="php"> | ||
<?php | <?php | ||
header("Content-Type: text/plain"); | header("Content-Type: text/plain"); | ||
Line 241: | Line 202: | ||
echo $respone; | echo $respone; | ||
?> | ?> | ||
</ | </syntaxhighlight> | ||
== Limits == | == Limits == | ||
* body is limited to 2048 bytes; anything longer will be truncated to 2048 bytes. (post request is inside the body) | |||
* body is limited to 2048 bytes; anything longer will be truncated to 2048 bytes. (post request | * There is a limit of 64 pending [[http_request]]s | ||
* There is a limit of 64 pending http_request | |||
[[Category:LSL Examples]] |
Latest revision as of 11:39, 30 November 2023
Content:
If you can send mails via PHP from your webspace/server then sending emails to a script is a simple but not the fastest way.
Mailaddy from a prim is uuid@lsl.secondlife.com
PHP Script
<?php
$uuid = "add your prim uuid";
$subject = "Test";
$msg = "Simple Test Mail";
mail($uuid."@lsl.secondlife.com", $subject, $msg);
?>
LSL Script
default
{
state_entry()
{
llOwnerSay("My UUID is: " + (string)llGetKey());
llSetTimerEvent(2.0);
}
timer() {
llGetNextEmail("", ""); // Check for emails
}
email (string time, string address, string subj, string msg, integer num_left)
{
llOwnerSay("\nI got an email:\nFrom:" + address + "\nSubject: " + subj + "\nMessage:\n" + msg);
}
}
Limits
- The email queue is limited to 100 emails, any email after that is bounced.
- The message field may have a maximum of 1000 characters. This count includes the header information (address, subject, etc).
GET Request over http-in
Sending variables/text to an LSL script via GET request is an easy way to use the 'new' http-in feature.
However it isn't a way to send lots of data to the script.
PHP Script
<?php
$script_url = "http://sim5363.agni.lindenlab.com:12046/cap/<your url cap here>/"; // Don't forget slash at the end
$get_vars = "foo=bar&hello=world";
// Remember, if you intend to send vars with whitespaces or special chars you must encode the string → urlencode($get_vars);
// However urlencoded whitespaces/special chars need more space (e.g. comma = %2C) the active available bytes fall!
// Need allow_url_fopen = true in your php.ini (most free webspace has this deactivated)
// If you got an Error ask your ISP about url_fopen
$response = file_get_contents($script_url . "?" . $get_vars);
echo $response;
?>
LSL Script
default
{
state_entry()
{
// Request URL
llRequestURL();
}
http_request(key id, string method, string body)
{
if (method == URL_REQUEST_GRANTED)
{
llOwnerSay("My URL: " + body);
}
else if (method == URL_REQUEST_DENIED)
{
llSay(0, "Something went wrong, no url. " + body);
}
else if (method == "GET")
{
// Get [GET] vars from header
string get = llGetHTTPHeader(id, "x-query-string");
// Split
list get_parsed = llParseString2List(get, ["&"], [""]);
integer i;
integer pos = llGetListLength(get_parsed);
llOwnerSay("\nReceived GET Request:");
for(i = 0; i < pos;i++)
{
llOwnerSay(llList2String(get_parsed, i));
}
//Respone (what you see in your browser)
llHTTPResponse(id,200,"success");
}
else
{
llHTTPResponse(id,405,"Unsupported Method");
}
}
}
Limits
- headers (accessed with llGetHTTPHeader) are limited to 255 bytes. With the script above you can send 255 bytes raw data (include the <var>=).
- There is a limit of 64 pending http_requests
POST Request over http-in
Post request is the best way to send lots of data to an LSL Script however it isn't so a short/simple code to use it within PHP. Besides not all ISPs allow fsockopen() or cURL or connection on another port beyond the default (80 and 443).
fsockopen PHP Script
This example is from Simba Fuhr: Simple Script for seding data...
<?php
$Data = CallLSLScript("http://sim3015.aditi.lindenlab.com:12046/cap/<your script url cap>", "This is a post request test message via Sockets");
die($Data);
//Function by Simba Fuhr
//Use under the GPL License
function CallLSLScript($URL, $Data, $Timeout = 10)
{
//Parse the URL into Server, Path and Port
$Host = str_ireplace("http://", "", $URL);
$Path = explode("/", $Host, 2);
$Host = $Path[0];
$Path = $Path[1];
$PrtSplit = explode(":", $Host);
$Host = $PrtSplit[0];
$Port = $PrtSplit[1];
//Open Connection
$Socket = fsockopen($Host, $Port, $Dummy1, $Dummy2, $Timeout);
if ($Socket)
{
//Send Header and Data
fputs($Socket, "POST /$Path HTTP/1.1\r\n");
fputs($Socket, "Host: $Host\r\n");
fputs($Socket, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($Socket, "User-Agent: Opera/9.01 (Windows NT 5.1; U; en)\r\n");
fputs($Socket, "Accept-Language: de-DE,de;q=0.9,en;q=0.8\r\n");
fputs($Socket, "Content-length: ".strlen($Data)."\r\n");
fputs($Socket, "Connection: close\r\n\r\n");
fputs($Socket, $Data);
//Receive Data
while(!feof($Socket))
{$res .= fgets($Socket, 128);}
fclose($Socket);
}
//ParseData and return it
$res = explode("\r\n\r\n", $res);
return $res[1];
}
?>
cURL PHP Script
<?php
header("Content-Type: text/plain");
$msg = "This is a post request test message via cURL";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"http://sim4631.agni.lindenlab.com:12046/cap/<your script url cap>");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $msg);
$respone = curl_exec ($curl);
curl_close ($curl);
echo $respone;
?>
Limits
- body is limited to 2048 bytes; anything longer will be truncated to 2048 bytes. (post request is inside the body)
- There is a limit of 64 pending http_requests