Difference between revisions of "Online Indicator"

From Second Life Wiki
Jump to: navigation, search
(New page: {{LSL Header}} This script will show if the user is online or offline - will create hover text. Will show user profile picture on the object and when touched, then toucher can send IM to...)
 
m (<lsl> tag to <source>)
 
(24 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{LSL Header}}
+
{{LSL Header}}__TOC__
  
This script will show if the user is online or offline - will create hover text.
+
{{World.secondlife.com changes}}
  
Will show user profile picture on the object and when touched, then toucher can send IM to user.
+
{{box|Copying Permission|
 +
Copyright © 2008 by Kristy Fanshaw
  
<lsl>key owner_key = "00000000-0000-0000-0000-000000000000";     // must be agent UUID whose status it will indicate
+
This program is free software: you can redistribute it and/or modify<br>
integer time = 30;                                     // time within the message should be written.
+
it under the terms of the GNU General Public License as published by<br>
string RESIDENT_URL = "http://world.secondlife.com/resident/";
+
the Free Software Foundation, either version 3 of the License, or<br>
key WHITE_DEFAULT_TEXTURE = "5748decc-f629-461c-9a36-a35a221fe21f";
+
(at your option) any later version.<br>
 +
 
 +
This program is distributed in the hope that it will be useful,<br>
 +
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
 +
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
 +
GNU General Public License for more details.<br>
 +
 
 +
To get a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.}}
 +
{{box|Online Indicator|
 +
Place this script in a box you've created.<br><br>
 +
What it does:
 +
# This script will create hover text with resident name and online status.
 +
# Will show resident profile picture on the object if it's avaliable in search
 +
# On touch the toucher can send IM to the resident by typing the message into main chat.
 +
# Offers a link in main chat to open resident profile.
 +
# finding a user key visit http://search.secondlife.com/search.php. Type the name in search and press "go". In results you see either only "Resident profile: name" or "Resident profile: name" and other results.<br>
 +
click on the result and you'll find the UUID in the URL of the page. ("secondlife:/app/agent/User_key/about" or "http://world.secondlife.com/resident/User_key")
 +
 
 +
<source lang="lsl2">
 +
////////////////////////////////////////////////////////////////////////////////////////////////
 +
//    Copyright (c) 2008 by Kristy Fanshaw                                                    //
 +
////////////////////////////////////////////////////////////////////////////////////////////////
 +
//  This program is free software: you can redistribute it and/or modify                    //
 +
//    it under the terms of the GNU General Public License as published by                    //
 +
//    the Free Software Foundation, either version 3 of the License, or                      //
 +
//    (at your option) any later version.                                                    //
 +
//                                                                                            //
 +
//    Online Indicator is distributed in the hope that it will be useful,                    //
 +
//    but WITHOUT ANY WARRANTY; without even the implied warranty of                          //
 +
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                          //
 +
//    GNU General Public License for more details.                                            //
 +
//                                                                                            //
 +
//    To get a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.    //
 +
////////////////////////////////////////////////////////////////////////////////////////////////
 +
 +
key user_key = "00000000-0000-0000-0000-000000000000";       // must be agent UUID whose status it will indicate
 +
integer time = 30;                                           // time within the message should be written.
 +
string url = "http://world.secondlife.com/resident/";
 +
key blank = TEXTURE_BLANK;
 
string name;
 
string name;
 
key toucher;
 
key toucher;
 
string status;
 
string status;
 +
 +
// VD 2009-11-24 workaround for WEB-1383, use <meta> instead of <img>
 +
// VD 2009-11-25 try <img> if meta tag gets removed in the future
 +
string profile_key_prefix = "<meta name=\"imageid\" content=\"";
 +
string profile_img_prefix = "<img alt=\"profile image\" src=\"http://secondlife.com/app/image/";
 +
integer profile_key_prefix_length; // calculated from profile_key_prefix in state_entry()
 +
integer profile_img_prefix_length; // calculated from profile_img_prefix in state_entry()
  
 +
//string profile_key_prefix = "<meta name=\"imageid\" content=\"";
 +
//integer s1l;
 +
 
default
 
default
 
{
 
{
 
     state_entry()
 
     state_entry()
 
     {
 
     {
 +
        profile_key_prefix_length = llStringLength(profile_key_prefix);
 +
        profile_img_prefix_length = llStringLength(profile_img_prefix);
 
         llSetText("", <1,0,0>, 1.0);
 
         llSetText("", <1,0,0>, 1.0);
         llSetTexture(WHITE_DEFAULT_TEXTURE, ALL_SIDES);
+
         llSetTexture(blank, ALL_SIDES);
         llRequestAgentData( owner_key, DATA_NAME);   
+
         llRequestAgentData( user_key, DATA_NAME);   
 
     }
 
     }
 
     dataserver(key queryid, string data)
 
     dataserver(key queryid, string data)
 
     {
 
     {
 
         name = data;
 
         name = data;
 +
        llSetObjectName(name + "'s Online Detector");
 
         state show;
 
         state show;
 
     }
 
     }
Line 35: Line 87:
 
     timer()
 
     timer()
 
     {
 
     {
         llHTTPRequest( RESIDENT_URL + (string)owner_key,[HTTP_METHOD,"GET"],"");
+
         llHTTPRequest( url + (string)user_key,[HTTP_METHOD,"GET"],"");
         llRequestAgentData( owner_key, DATA_ONLINE);   
+
         llRequestAgentData( user_key, DATA_ONLINE);   
     }
+
     }  
   
+
 
     on_rez(integer start_param)
 
     on_rez(integer start_param)
 
     {
 
     {
 
         llSetText("", <1,0,0>, 1.0);
 
         llSetText("", <1,0,0>, 1.0);
         llSetTexture(WHITE_DEFAULT_TEXTURE, ALL_SIDES);
+
         llSetTexture(blank, ALL_SIDES);
     }
+
     }  
   
+
 
     http_response(key request_id,integer status, list metadata, string body)
 
     http_response(key request_id,integer status, list metadata, string body)
 
     {
 
     {
         // If the profile has no picture the image name will be
+
         string profile_pic;
         // http://world.secondlife.com/images/blank.jpg
+
         integer s1 = llSubStringIndex(body, profile_key_prefix);
        if (llSubStringIndex(body, "blank.jpg") == -1) // If a profile picture exists
+
        integer s1l = profile_key_prefix_length;
         {
+
        if(s1 == -1)
             integer start_of_UUID = llSubStringIndex(body,"<img alt=\"profile image\" src=\"http://secondlife.com/app/image/") + llStringLength("<img alt=\"profile image\" src=\"http://secondlife.com/app/image/");
+
         { // second try
             integer end_of_UUID = llSubStringIndex(body,"\" class=\"parcelimg\" />") - 3;
+
             s1 = llSubStringIndex(body, profile_img_prefix);
             string profile_pic = llGetSubString(body, start_of_UUID, end_of_UUID);
+
             s1l = profile_img_prefix_length;
            llSetTexture((key)profile_pic, ALL_SIDES);
+
        }
 +
 
 +
        if (s1 == -1)
 +
        { // still no match?
 +
             profile_pic = blank;
 
         }
 
         }
 
         else
 
         else
 
         {
 
         {
             llSetTexture(WHITE_DEFAULT_TEXTURE, ALL_SIDES);
+
             profile_pic = llGetSubString(body,s1 + s1l, s1 + s1l + 35);
 +
            if (profile_pic == (string)NULL_KEY)
 +
            {
 +
                profile_pic = blank;
 +
            }
 
         }
 
         }
 +
        llSetTexture(profile_pic, ALL_SIDES);
 
     }
 
     }
 
     dataserver(key queryid, string data)
 
     dataserver(key queryid, string data)
Line 66: Line 125:
 
         {
 
         {
 
             status = " is online";
 
             status = " is online";
   
+
 
             llSetText(name + status, <0,1,0>, 1.0);
 
             llSetText(name + status, <0,1,0>, 1.0);
 
         }
 
         }
Line 72: Line 131:
 
         {
 
         {
 
             status = " is offline";
 
             status = " is offline";
           
+
 
             llSetText(name + status, <1,0,0>, 1.0);
 
             llSetText(name + status, <1,0,0>, 1.0);
 
         }
 
         }
       
+
 
     }
 
     }
 
     touch_start(integer num_detected)
 
     touch_start(integer num_detected)
Line 85: Line 144:
 
state msg
 
state msg
 
{
 
{
    state_entry()
+
    state_entry()
 
     {
 
     {
 
         llListen(0,"",toucher,"");
 
         llListen(0,"",toucher,"");
 
         llInstantMessage(toucher, "write your message to " + name +" - you have " +(string)time + " seconds");
 
         llInstantMessage(toucher, "write your message to " + name +" - you have " +(string)time + " seconds");
 +
        llInstantMessage(toucher, "to see " + name +"'s profile, click this link here: secondlife:///app/agent/" + (string)user_key + "/about");
 
         llSetTimerEvent(time);   
 
         llSetTimerEvent(time);   
 
     }
 
     }
 
     listen(integer ch, string name, key id, string msg)
 
     listen(integer ch, string name, key id, string msg)
 
     {
 
     {
         llInstantMessage(owner_key, msg);
+
         llInstantMessage(user_key, llKey2Name(toucher) + " sent you a message from " + llGetRegionName() + ": " + msg);
         llInstantMessage(toucher, "message is sent");
+
         llInstantMessage(toucher, "message is sent.");
 
         llListenRemove(0);
 
         llListenRemove(0);
 
         state show;
 
         state show;
Line 105: Line 165:
 
     }
 
     }
 
}
 
}
 
+
</source>}}
 
+
</lsl>
+
  
 
{{LSLC|Examples}}
 
{{LSLC|Examples}}
 
{{LSLC|Library}}
 
{{LSLC|Library}}

Latest revision as of 17:33, 24 January 2015

KBcaution.png Important: This script relies on data scraped from world.secondlife.com. That site, and the page format it currently serves, will probably be replaced by my.secondlife.com pages in the coming months. The new pages use a different format and have different access controls, so expect this script to stop working if and when the change is made. See WEB-3510 for details.

Copying Permission

Copyright © 2008 by Kristy Fanshaw

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

To get a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.

Online Indicator

Place this script in a box you've created.

What it does:

  1. This script will create hover text with resident name and online status.
  2. Will show resident profile picture on the object if it's avaliable in search
  3. On touch the toucher can send IM to the resident by typing the message into main chat.
  4. Offers a link in main chat to open resident profile.
  5. finding a user key visit http://search.secondlife.com/search.php. Type the name in search and press "go". In results you see either only "Resident profile: name" or "Resident profile: name" and other results.

click on the result and you'll find the UUID in the URL of the page. ("secondlife:/app/agent/User_key/about" or "http://world.secondlife.com/resident/User_key")

////////////////////////////////////////////////////////////////////////////////////////////////
//    Copyright (c) 2008 by Kristy Fanshaw                                                    //
////////////////////////////////////////////////////////////////////////////////////////////////
//   This program is free software: you can redistribute it and/or modify                     //
//    it under the terms of the GNU General Public License as published by                    //
//    the Free Software Foundation, either version 3 of the License, or                       //
//    (at your option) any later version.                                                     //
//                                                                                            //
//    Online Indicator is distributed in the hope that it will be useful,                     //
//    but WITHOUT ANY WARRANTY; without even the implied warranty of                          //
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                           //
//    GNU General Public License for more details.                                            //
//                                                                                            //
//    To get a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.    //
////////////////////////////////////////////////////////////////////////////////////////////////
 
key user_key = "00000000-0000-0000-0000-000000000000";       // must be agent UUID whose status it will indicate
integer time = 30;                                           // time within the message should be written.
string url = "http://world.secondlife.com/resident/";
key blank = TEXTURE_BLANK;
string name;
key toucher;
string status;
 
// VD 2009-11-24 workaround for WEB-1383, use <meta> instead of <img>
// VD 2009-11-25 try <img> if meta tag gets removed in the future
string profile_key_prefix = "<meta name=\"imageid\" content=\"";
string profile_img_prefix = "<img alt=\"profile image\" src=\"http://secondlife.com/app/image/";
integer profile_key_prefix_length; // calculated from profile_key_prefix in state_entry()
integer profile_img_prefix_length; // calculated from profile_img_prefix in state_entry()
 
//string profile_key_prefix = "<meta name=\"imageid\" content=\"";
//integer s1l;
 
default
{
    state_entry()
    {
        profile_key_prefix_length = llStringLength(profile_key_prefix);
        profile_img_prefix_length = llStringLength(profile_img_prefix);
        llSetText("", <1,0,0>, 1.0);
        llSetTexture(blank, ALL_SIDES);
        llRequestAgentData( user_key, DATA_NAME);   
    }
    dataserver(key queryid, string data)
    {
        name = data;
        llSetObjectName(name + "'s Online Detector");
        state show;
    }
}
state show
{   
    state_entry()
    {
        llSetTimerEvent(10);
    } 
    timer()
    {
        llHTTPRequest( url + (string)user_key,[HTTP_METHOD,"GET"],"");
        llRequestAgentData( user_key, DATA_ONLINE);   
    } 
    on_rez(integer start_param)
    {
        llSetText("", <1,0,0>, 1.0);
        llSetTexture(blank, ALL_SIDES);
    } 
    http_response(key request_id,integer status, list metadata, string body)
    {
        string profile_pic;
        integer s1 = llSubStringIndex(body, profile_key_prefix);
        integer s1l = profile_key_prefix_length;
        if(s1 == -1)
        { // second try
            s1 = llSubStringIndex(body, profile_img_prefix);
            s1l = profile_img_prefix_length;
        }
 
        if (s1 == -1)
        { // still no match?
            profile_pic = blank;
        }
        else
        {
            profile_pic = llGetSubString(body,s1 + s1l, s1 + s1l + 35);
            if (profile_pic == (string)NULL_KEY)
            {
                profile_pic = blank;
            }
        }
        llSetTexture(profile_pic, ALL_SIDES);
    }
    dataserver(key queryid, string data)
    {
        if ( data == "1" ) 
        {
            status = " is online";
 
            llSetText(name + status, <0,1,0>, 1.0);
        }
        else if (data == "0")
        {
            status = " is offline";
 
            llSetText(name + status, <1,0,0>, 1.0);
        }
 
    }
    touch_start(integer num_detected)
    {
        toucher = llDetectedKey(0);
        state msg;
    }
}
state msg
{
    state_entry()
    {
        llListen(0,"",toucher,"");
        llInstantMessage(toucher, "write your message to " + name +" - you have " +(string)time + " seconds");
        llInstantMessage(toucher, "to see " + name +"'s profile, click this link here: secondlife:///app/agent/" + (string)user_key + "/about");
        llSetTimerEvent(time);   
    }
    listen(integer ch, string name, key id, string msg)
    {
        llInstantMessage(user_key, llKey2Name(toucher) + " sent you a message from " + llGetRegionName() + ": " + msg);
        llInstantMessage(toucher, "message is sent.");
        llListenRemove(0);
        state show;
    }
    timer()
    {
        llInstantMessage(toucher, "time is up - touch again to write a message");
        llListenRemove(0); 
        state show;
    }
}