So if you end up using this, please be nice and tip me at least a quarter's worth of lindens ~75L.
It is basically your standard green/red online indicator prim. However, this updates a php script to copy an image in the same folder as your PHP script (online.gif or offline.gif) into a folder caled 'status' (might need to make this folder and chmod it 777) as well as writes a small status.txt file to the same folder with the word offline or online that can be included into your site/blog/forum posts using the information at this url:
http://www.boutell.com/newfaq/creating/include.html
All you have to do is...
- Save the php file to your server
- Create and save an online and offline image (.gif, .jpg, or . png)
- Upload it to the same folder as the php script
- make a subfolder in the same folder as the php script and name it 'status'
- Chmod it 777 is necesary
- save the lsl script onto a prim in-world you want to use as a status indicator
- copy the php file's URL to that prim's description
- reset the script
- Incporporate the status.txt into and status/status.gif into your site
Status.php file:
CODE
<?php
////// Simple PHP/LSL Status Updater///////////
// To Install:
// 0. Edit the following $Timer variable to match how oen in seconds you want your indicator to be updated.
// 1. Copy this script (status.php), a gif/jpg/png image named "online" and "offline" to your server.
// 2. In the same folder as the script create a folder named "status" and if applicable chmod it 777.
// 3. Copy and paste the URLof this script into the description of the online status indicator in-world.
$Timer = 300; //Five Minutes.
/////////////////////
if($_POST) {
$Input = $_POST;
} else {
$Input = $_GET;
}
if ($Input['status'] == "Online") {
$status = "Online";
} else {
$status = "Offline"; //We don't want to pass funky status.
}
if (is_dir("status") == FALSE) {
if (@mkdir("status", 0777) == FALSE) {
echo "Error-- could not create 'status' folder. Please create it in the same folder as status.php and chmod it 777.";
die;
}
}
$fp = @fopen("status/status.txt", "w"); //Open file, write
$fw = @fwrite( $fp, $status ); // Write the content on the file
@fclose( $fp ); // Close the file after writing
@chmod("status/status.txt", 0777);
if (!$fw)
echo "Failed to write status.txt...\n";
if ($status == "Online") {
if (is_file('online.gif')) {
$file = "online.gif";
$ext = ".gif";
}
if (is_file('online.jpg')) {
$file = "online.jpg";
$ext = ".jpg";
}
if (is_file('online.png')) {
$file = "online.png";
$ext = ".png";
}
else echo "Online image no found in same folder as status.php.";
} else {
if (is_file('offline.gif')){
$file = "offline.gif";
$ext = ".gif";
}
if (is_file('offline.jpg')){
$file = "offline.jpg";
$ext = ".jpg";
}
if (is_file('offline.png')){
$file = "offline.png";
$ext = ".png";
}
else echo "Offline image no found in same folder as status.php.";
}
$copy = copy($file, 'status/status'.$ext);
if (!$copy) {
echo "Failed to copy $file...\n";
}
if($fw && $copy) echo $Timer;
else echo "Error-- could not set status.";
?>
status.lsl:
CODE
integer gIsOnline = FALSE;
integer gLandOwner = FALSE;
key gKey = NULL_KEY;
string gName = "";
float UPDATE_INTERVAL = 30;
key requestid;
string owner;
updateStatus(string s){
key k = llGetLandOwnerAt(llGetPos());
if(s=="1"){
gIsOnline = TRUE;
}else{
gIsOnline = FALSE;
}
}
key getWhom(){
if(gKey == NULL_KEY){
if(gLandOwner){
return llGetLandOwnerAt(llGetPos());
}else{
return llGetOwner();
}
}else{
return gKey;
}
}
doUpdate(){
llRequestAgentData(getWhom(),DATA_ONLINE);
}
updateName(){
llRequestAgentData(getWhom(),DATA_NAME);
}
default
{
state_entry()
{
llSetTimerEvent(UPDATE_INTERVAL);
}
on_rez(integer n){
owner = llKey2Name( llGetOwner());
}
dataserver(key req, string data){
if(data == "1" || data == "0"){
updateStatus(data);
}else{
gName = data;
llSetText("Getting online status for " + gName,<1,1,1>,1);
llSetColor(<0,0,1>,ALL_SIDES);
llSetTimerEvent(UPDATE_INTERVAL);
}
}
timer(){
doUpdate();
if(gIsOnline){
llSetText(owner + "\nis Online",<1,1,1>,.25);
llSetColor(<0,1,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0, 1, 0>, 1.0, 3.0, 0.75]);
if (llGetObjectDesc() != "Paste URL of Status.php here!")
requestid = llHTTPRequest(llGetObjectDesc() + "?status=Online",[HTTP_METHOD,"GET"],"");
}else{
llSetText(owner + "\nis Offline",<1,1,1>,.25);
llSetColor(<1,0,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 0, 0>, 0.25, 3.0, 0.75]); if (llGetObjectDesc() != "Paste URL of Status.php here!")
requestid = llHTTPRequest(llGetObjectDesc() + "?status=Offline",[HTTP_METHOD,"GET"],"");
}
}
http_response(key request_id, integer status, list metadata, string body)
{
if (status == 404) {
llOwnerSay("The URL you entered into the description box appears to be incorrect. The server was found, but the script wasn't.");
}
UPDATE_INTERVAL = (float)body;
}
}
It wouldn't be that hard to expand this a bit and use the indicator as a in-world server for a HUD that gets your info (location, status, ect) if you're creative.
Its set up so the web server defines how often the status gets checked.