Difference between revisions of "RLV Viewer Titler"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "With upcoming new third party viewer policy, displaying of viewer tags is no more allowed and was also deactivated. Before the TPV changes, with some viewers it was possible to s…")
 
m (<lsl> tag to <source>)
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
The comment block inside the script provides further info about features and usage of the script.
The comment block inside the script provides further info about features and usage of the script.


<lsl>
<source lang="lsl2">
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or
// This program is free software; you can redistribute it and/or
Line 65: Line 65:
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Author  Jenna Felton
// Author  Jenna Felton
// Version 1.0
// Version 1.0.1
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------


integer CHANNEL = 111;
integer CHANNEL = 111;


list   NAMES   = [
list NAMES = [
"WHITE", "GREY", "BLACK",
    "WHITE", "GREY", "BLACK",
"RED", "GREEN", "BLUE",
    "RED", "GREEN", "BLUE",
"YELLOW", "MAGENTA", "CYAN",
    "YELLOW", "MAGENTA", "CYAN",
"DEFAULT"];
    "DEFAULT"];
list   COLORS = [
 
<1.0, 1.0, 1.0>, <0.5, 0.5, 0.5>, <0.0, 0.0, 0.0>,
list COLORS = [
<1.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 1.0>,
    <1.0, 1.0, 1.0>, <0.5, 0.5, 0.5>, ZERO_VECTOR,
<1.0, 1.0, 0.0>, <1.0, 0.0, 1.0>, <0.0, 1.0, 1.0>,
    <1.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 1.0>,
<.98, .69, .36>];
    <1.0, 1.0, 0.0>, <1.0, 0.0, 1.0>, <0.0, 1.0, 1.0>,
    <0.98, 0.69, 0.36>];


integer hUserListen;
integer hUserListen;
Line 85: Line 86:
integer gRLVCChan;
integer gRLVCChan;


string sViewer = "";
string sViewer = "";
string sTitle = "";
string sTitle = "";
vector vColor = <.98, .69, .36>;
vector vColor = <0.98, 0.69, 0.36>;
 
key kOwner;
 
// Added by Kireji Haiku to reduce memory usage and improve readability
reset_listeners_and_timer()
{
    llListenRemove(hRLVCListen);
    gRLVCChan  = 1000000 + (integer)llFrand(100000.0);
    hRLVCListen = llListen(gRLVCChan, "", kOwner, "");


key     kOwner;
     llOwnerSay("detecting viewer...");
    llOwnerSay("@version=" + (string)gRLVCChan);


//--- ------------------------------------------------------------------------
    // set timer to go off every other minute
    llSetTimerEvent(60.0);
}


default {
default {
// init::UsedMem = 12312
    // init::UsedMem = 12312
state_entry() {
    state_entry() {
llSetAlpha(0.0, ALL_SIDES);
        // set transparent
sViewer     = "";
        llSetAlpha(.0, ALL_SIDES);
sTitle     = "";
 
kOwner      = llGetOwner();
        kOwner  = llGetOwner();
        sViewer = "";
hUserListen = llListen(CHANNEL, "", kOwner, "");
        sTitle = "";
 
        hUserListen = llListen(CHANNEL, "", kOwner, "");
 
        reset_listeners_and_timer();
 
        // Checks the memory usage and reduces by setting less
        llOwnerSay("init::UsedMem = "+(string)llGetUsedMemory());
        llSetMemoryLimit(24000);
    }


llListenRemove(hRLVCListen);
    // onrez::UsedMem = 12410
gRLVCChan  = 1000000 + (integer)llFrand(100000.0);
    on_rez(integer start_param) {
hRLVCListen = llListen(gRLVCChan, "", kOwner, "");
        // Memory test
        llScriptProfiler(PROFILE_SCRIPT_MEMORY);
llOwnerSay("detecting viewer...");


// Request the viewer version and starts a
        if (kOwner != llGetOwner()) llResetScript();
// timeout of one minute.
llOwnerSay("@version="+(string)gRLVCChan);
llSetTimerEvent(60.0);


// Checks the memory usage and reduces by setting less
        reset_listeners_and_timer();
llOwnerSay("init::UsedMem = "+(string)llGetUsedMemory());
llSetMemoryLimit(24000);
}


// onrez::UsedMem = 12410
        // Memory test
on_rez(integer start_param) {
        llScriptProfiler(PROFILE_NONE);
// Memory test
        llOwnerSay("onrez::UsedMem = " + (string)llGetSPMaxMemory());
llScriptProfiler(PROFILE_SCRIPT_MEMORY);
    }


if (kOwner != llGetOwner()) llResetScript();
    // listen::UsedMem = 12378 (rougly min)
    // listen::UsedMem = 13490 (rougly max)
    listen(integer chan, string name, key id, string message) {
        // Memory test
        llScriptProfiler(PROFILE_SCRIPT_MEMORY);


llListenRemove(hRLVCListen);
        // User control
gRLVCChan  = 1000000 + (integer)llFrand(100000.0);
        if (chan == CHANNEL) {
hRLVCListen = llListen(gRLVCChan, "", kOwner, "");
            llSetTimerEvent(.0);
            llListenRemove(hRLVCListen);
llOwnerSay("detecting viewer...");
llOwnerSay("@version="+(string)gRLVCChan);
llSetTimerEvent(60.0);


// Memory test
            name = llToUpper(message);
llScriptProfiler(PROFILE_NONE);
           
llOwnerSay("onrez::UsedMem = " + (string)llGetSPMaxMemory());
            if (name == "HIDE") {
}
                llSetText("", vColor, .0);
            }
           
            else if (name == "SHOW") {
                llSetText(sViewer+sTitle, vColor, 1.0);
            }
           
            else if (name == "VERSION") {
                reset_listeners_and_timer();
            }
           
            else if (name == "STOP") {
                llOwnerSay("/me is frozen. To unfreeze, please reattach");
                llListenRemove(hUserListen);
            }
           
            else if (llGetSubString(name, 0, 5) == "COLOR ") {
                name = llGetSubString(name, 6, -1);
                name = llStringTrim(name, STRING_TRIM_HEAD);


// Viewer Check Teimeout
                // Look for color names. If found - use color value
// timer::UsedMem = 12224
                chan = llListFindList(NAMES, [name]);
timer() {
                if (chan > -1) {
// Memory test
                    vColor = llList2Vector(COLORS, chan);
llScriptProfiler(PROFILE_SCRIPT_MEMORY);
                }


llSetTimerEvent(.0);
                // Not found - parse the given vector to color value
llListenRemove(hRLVCListen);
                else {
                    list tmp = llParseString2List(name, ["<", ",", " ", ">"], []);
sViewer = "";
                    vColor  = <llList2Float(tmp, 0), llList2Float(tmp, 1), llList2Float(tmp, 2)>;
llSetText(sTitle, vColor, 1.0);
                }
llOwnerSay(
"No RLV-capable viewer detected (or RLV is off).\n"+
"To repeat the ckeck, please reattach or chat this:\n"+
"/"+(string)CHANNEL+" VERSION");


// Memory test
                llSetText(sViewer+sTitle, vColor, 1.0);
llScriptProfiler(PROFILE_NONE);
            }
llOwnerSay("timer::UsedMem = " + (string)llGetSPMaxMemory());
           
}
            else if (name == "CLEAR") {
                sTitle = "";
                llSetText(sViewer, vColor, 1.0);
            }
           
            // Unknown command. Fine, the user gets a title.
            else {
                sTitle = message;
                llSetText(sViewer+sTitle, vColor, 1.0);
            }
        }


// listen::UsedMem = 12378 (rougly min)
        // Viewer version response. Example answers:
// listen::UsedMem = 13490 (rougly max)
        // message = "RestrainedLife viewer v1.17 (CV 1.22.11.0)"
listen(integer chan, string name, key id, string message) {
        //          "RestrainedLife viewer v1.18 (SL 1.23.4)"
// Memory test
        //           "RestrainedLife viewer v1.22.0 (Emerald Viewer - RLVa 1.0.5)"
llScriptProfiler(PROFILE_SCRIPT_MEMORY);
        //          "RestrainedLife viewer v1.22.1 (1.22.12.0)
        //          "RestrainedLove viewer v2.2.0 (Phoenix Viewer 1.5.2.908 - RLVa 1.1.3)"
        //          "RestrainedLife viewer v2.7.0 (Firestorm 3.3.0.24880 - RLVa 1.4.3)"
        else if (chan == gRLVCChan) {
            llSetTimerEvent(0.0);
            llListenRemove(hRLVCListen);


// User control
            // Separate the name:
if (chan == CHANNEL) {
            // message = "RLV version (viewer signature)"
llSetTimerEvent(.0);
            //  -> tmp = ["RLV version", "viewer signature"]
llListenRemove(hRLVCListen);
            list tmp = llParseString2List(message, [" (", ")"], []);
            message  = llList2String(tmp, 1);
name = llToUpper(message);
if      (name == "HIDE")    llSetText("", vColor, .0);
else if (name == "SHOW")    llSetText(sViewer+sTitle, vColor, 1.0);
else if (name == "VERSION") {
llListenRemove(hRLVCListen);
gRLVCChan  = 1000000 + (integer)llFrand(100000.0);
hRLVCListen = llListen(gRLVCChan, "", kOwner, "");
llOwnerSay("detecting viewer...");
llOwnerSay("@version="+(string)gRLVCChan);
llSetTimerEvent(60.0);
}
else if (name == "STOP") {
llOwnerSay("/me is frozen. To unfreeze, please reattach");
llListenRemove(hUserListen);
}
else if (llGetSubString(name, 0, 5) == "COLOR ") {
name = llGetSubString(name, 6, -1);
name = llStringTrim(name, STRING_TRIM_HEAD);


// Look for color names. If found - use color value
            // If no viewer name set, "(1.22.12.0)", use RLV version
chan = llListFindList(NAMES, [name]);
            name = llGetSubString(message, 0, 0);
if (chan > -1) vColor = llList2Vector(COLORS, chan);
            if (name == "" || name == "0" || (integer)name != 0) {
                sViewer = llList2String(tmp, 0) + "\n";
            }
            else {
                sViewer = message + "\n";
            }


// Not found - parse the given vector to color value
            // Use extracted data
else {
            llSetText(sViewer+sTitle, vColor, 1.0);
list tmp = llParseString2List(name, ["<", ",", " ", ">"], []);
        }
vColor  = <llList2Float(tmp, 0), llList2Float(tmp, 1), llList2Float(tmp, 2)>;
}
llSetText(sViewer+sTitle, vColor, 1.0);
}
else if (name == "CLEAR") {
sTitle = "";
llSetText(sViewer, vColor, 1.0);
}


// Unknown command. Fine, the user gets a title.
        // Memory test
else {
        llScriptProfiler(PROFILE_NONE);
sTitle = message;
        llOwnerSay("listen::UsedMem = " + (string)llGetSPMaxMemory());
llSetText(sViewer+sTitle, vColor, 1.0);
    }
}
}


// Viewer version response. Example answers:
    // Viewer Check Timeout
// message = "RestrainedLife viewer v1.17 (CV 1.22.11.0)"
    // timer::UsedMem = 12224
//          "RestrainedLife viewer v1.18 (SL 1.23.4)"
    timer() {
//          "RestrainedLife viewer v1.22.0 (Emerald Viewer - RLVa 1.0.5)"
        // Memory test
//          "RestrainedLife viewer v1.22.1 (1.22.12.0)
        llScriptProfiler(PROFILE_SCRIPT_MEMORY);
//           "RestrainedLove viewer v2.2.0 (Phoenix Viewer 1.5.2.908 - RLVa 1.1.3)"
//          "RestrainedLife viewer v2.7.0 (Firestorm 3.3.0.24880 - RLVa 1.4.3)"
else if (chan == gRLVCChan) {
llSetTimerEvent(.0);
llListenRemove(hRLVCListen);


// Separate the name:
        llSetTimerEvent(.0);
// message = "RLV version (viewer signature)"
        llListenRemove(hRLVCListen);
//  -> tmp = ["RLV version", "viewer signature"]
list tmp = llParseString2List(message, [" (", ")"], []);
message  = llList2String(tmp, 1);


// If no viewer name set, "(1.22.12.0)", use RLV version
        sViewer = "";
name = llGetSubString(message, 0, 0);
        llSetText(sTitle, vColor, 1.0);
if (name == "" || name == "0" || (integer)name != 0) {
sViewer = llList2String(tmp, 0) + "\n";
}
else {
sViewer = message + "\n";
}


// Use extracted data
        llOwnerSay(
llSetText(sViewer+sTitle, vColor, 1.0);
            "No RLV-capable viewer detected (or RLV is off).\n"+
}
            "To repeat the ckeck, please reattach or chat this:\n"+
            "/"+(string)CHANNEL+" VERSION");


// Memory test
        // Memory test
llScriptProfiler(PROFILE_NONE);
        llScriptProfiler(PROFILE_NONE);
llOwnerSay("listen::UsedMem = " + (string)llGetSPMaxMemory());
        llOwnerSay("timer::UsedMem = " + (string)llGetSPMaxMemory());
}
    }
}
}
</lsl>
</source>

Latest revision as of 19:08, 24 January 2015

With upcoming new third party viewer policy, displaying of viewer tags is no more allowed and was also deactivated. Before the TPV changes, with some viewers it was possible to see what viewer other residents are using, which is seen as injuring of privacy on the other side, but on the other side an improvement in giving viewer-dependant residental support. This advantage of viewer tags is taken by the TPV changes.

The Viewer Titler tries to help here. It works with RLV technology and requests the viewer version by using its RLV interface. After viewer response, the type and version of the viewer is shown as hover text.

The comment block inside the script provides further info about features and usage of the script.

//----------------------------------------------------------------------------
// 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.
//
// You may ONLY redistribute this program with copy, mod and transfer
// permissions and ONLY if this preamble is not removed.
//
// 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.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//
// Script: RLVVersionTitler
//
// Features
//
//   1. Displays the viewr version and additional message as hover text.
//   2. Requests Viewer and version by using it's RLV interface.
//      This works only by using on a RLV-capable viewer.
//   3. Hides, shows the title and allows setting a color.
//   4. Freezing reduces lag by releasing listeners.
//
// RLV API (version checking part)
//
//   http://wiki.secondlife.com/wiki/LSL_Protocol/RestrainedLifeAPI
//
// Usage
//
//   1. Rezz a prim (any shape and size) and rename it nicelly.
//   2. Put the script inside, the prim turns invisible.
//   3. Pick up the prim (highlight transparency.)
//   4. To use finally, just wear on HUD or avatar.
//
// User control
//
//   /111 VERSION     - Checks the RLV version (if startup check failed.)
//   /111 HIDE        - Hides the titler.
//   /111 SHOW        - Shows the titler.
//   /111 STOP        - Removes listen. To reactivate, simply reattach. 
//   /111 COLOR Name  - Sets titler color. Name is a LSL vector or one of
//                      White, Grey Black, Red, Green, Blue, Yellow, Magenta,
//                      Cyan, Default.
//   /111 Text        - Sets an additional titler text.
//   /111 CLEAR       - Removes the additional text, shows title.
//
// Note
//
// After script modifications and calculation of the memory usage, you may
// comment out the test code - this reduces script spam and script code.
//
//----------------------------------------------------------------------------
// Author  Jenna Felton
// Version 1.0.1
//----------------------------------------------------------------------------

integer CHANNEL = 111;

list NAMES = [
    "WHITE", "GREY", "BLACK",
    "RED", "GREEN", "BLUE",
    "YELLOW", "MAGENTA", "CYAN",
    "DEFAULT"];

list COLORS = [
    <1.0, 1.0, 1.0>, <0.5, 0.5, 0.5>, ZERO_VECTOR,
    <1.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 1.0>,
    <1.0, 1.0, 0.0>, <1.0, 0.0, 1.0>, <0.0, 1.0, 1.0>,
    <0.98, 0.69, 0.36>];

integer hUserListen;
integer hRLVCListen;
integer gRLVCChan;

string sViewer = "";
string sTitle = "";
vector vColor = <0.98, 0.69, 0.36>;

key kOwner;

// Added by Kireji Haiku to reduce memory usage and improve readability
reset_listeners_and_timer() 
{
    llListenRemove(hRLVCListen);
    gRLVCChan   = 1000000 + (integer)llFrand(100000.0);
    hRLVCListen = llListen(gRLVCChan, "", kOwner, "");

    llOwnerSay("detecting viewer...");
    llOwnerSay("@version=" + (string)gRLVCChan);

    // set timer to go off every other minute
    llSetTimerEvent(60.0);
}

default {
    // init::UsedMem = 12312
    state_entry() {
        // set transparent
        llSetAlpha(.0, ALL_SIDES);

        kOwner  = llGetOwner();
        sViewer = "";
        sTitle  = "";

        hUserListen = llListen(CHANNEL, "", kOwner, "");

        reset_listeners_and_timer();

        // Checks the memory usage and reduces by setting less
        llOwnerSay("init::UsedMem = "+(string)llGetUsedMemory());
        llSetMemoryLimit(24000);
    }

    // onrez::UsedMem = 12410
    on_rez(integer start_param) {
        // Memory test
        llScriptProfiler(PROFILE_SCRIPT_MEMORY);

        if (kOwner != llGetOwner()) llResetScript();

        reset_listeners_and_timer();

        // Memory test
        llScriptProfiler(PROFILE_NONE);
        llOwnerSay("onrez::UsedMem = " + (string)llGetSPMaxMemory());
    }

    // listen::UsedMem = 12378 (rougly min)
    // listen::UsedMem = 13490 (rougly max)
    listen(integer chan, string name, key id, string message) {
        // Memory test
        llScriptProfiler(PROFILE_SCRIPT_MEMORY);

        // User control
        if (chan == CHANNEL) {
            llSetTimerEvent(.0);
            llListenRemove(hRLVCListen);

            name = llToUpper(message);
            
            if (name == "HIDE") {
                llSetText("", vColor, .0);
            }
            
            else if (name == "SHOW") {
                llSetText(sViewer+sTitle, vColor, 1.0);
            }
            
            else if (name == "VERSION") {
                reset_listeners_and_timer();
            }
            
            else if (name == "STOP") {
                llOwnerSay("/me is frozen. To unfreeze, please reattach");
                llListenRemove(hUserListen);
            }
            
            else if (llGetSubString(name, 0, 5) == "COLOR ") {
                name = llGetSubString(name, 6, -1);
                name = llStringTrim(name, STRING_TRIM_HEAD);

                // Look for color names. If found - use color value
                chan = llListFindList(NAMES, [name]);
                if (chan > -1) {
                    vColor = llList2Vector(COLORS, chan);
                }

                // Not found - parse the given vector to color value
                else {
                    list tmp = llParseString2List(name, ["<", ",", " ", ">"], []);
                    vColor   = <llList2Float(tmp, 0), llList2Float(tmp, 1), llList2Float(tmp, 2)>;
                }

                llSetText(sViewer+sTitle, vColor, 1.0);
            }
            
            else if (name == "CLEAR") {
                sTitle = "";
                llSetText(sViewer, vColor, 1.0);
            }
            
            // Unknown command. Fine, the user gets a title.
            else {
                sTitle = message;
                llSetText(sViewer+sTitle, vColor, 1.0);
            }
        }

        // Viewer version response. Example answers:
        // message = "RestrainedLife viewer v1.17 (CV 1.22.11.0)"
        //           "RestrainedLife viewer v1.18 (SL 1.23.4)"
        //           "RestrainedLife viewer v1.22.0 (Emerald Viewer - RLVa 1.0.5)"
        //           "RestrainedLife viewer v1.22.1 (1.22.12.0)
        //           "RestrainedLove viewer v2.2.0 (Phoenix Viewer 1.5.2.908 - RLVa 1.1.3)"
        //           "RestrainedLife viewer v2.7.0 (Firestorm 3.3.0.24880 - RLVa 1.4.3)"
        else if (chan == gRLVCChan) {
            llSetTimerEvent(0.0);
            llListenRemove(hRLVCListen);

            // Separate the name:
            // message = "RLV version (viewer signature)"
            //  -> tmp = ["RLV version", "viewer signature"]
            list tmp = llParseString2List(message, [" (", ")"], []);
            message  = llList2String(tmp, 1);

            // If no viewer name set, "(1.22.12.0)", use RLV version
            name = llGetSubString(message, 0, 0);
            if (name == "" || name == "0" || (integer)name != 0) {
                sViewer = llList2String(tmp, 0) + "\n";
            }
            else {
                sViewer = message + "\n";
            }

            // Use extracted data
            llSetText(sViewer+sTitle, vColor, 1.0);
        }

        // Memory test
        llScriptProfiler(PROFILE_NONE);
        llOwnerSay("listen::UsedMem = " + (string)llGetSPMaxMemory());
    }

    // Viewer Check Timeout
    // timer::UsedMem = 12224
    timer() {
        // Memory test
        llScriptProfiler(PROFILE_SCRIPT_MEMORY);

        llSetTimerEvent(.0);
        llListenRemove(hRLVCListen);

        sViewer = "";
        llSetText(sTitle, vColor, 1.0);

        llOwnerSay(
            "No RLV-capable viewer detected (or RLV is off).\n"+
            "To repeat the ckeck, please reattach or chat this:\n"+
            "/"+(string)CHANNEL+" VERSION");

        // Memory test
        llScriptProfiler(PROFILE_NONE);
        llOwnerSay("timer::UsedMem = " + (string)llGetSPMaxMemory());
    }
}