Jump to content
Ruthven Willenov

Retrieve Group Name - With HTML Cleanup

Recommended Posts

Posted (edited)

This a simple, proof of concept script for retrieving the name of a group that an object is assigned to. To get an avatar's group, you can first grab a uuid of one of their attachments with llGetAttachedList, then pass that too llGetObjectDetails in place of llGetKey()

 

this script retreives the uuid of the object's group, then sends an http request to get the group's info on the SecondLife website. Once it receives the response, it parses out <title> and </title> to get the groups name. some groups use special characters in their name, such as less than and greater than. the html formats those into HTML entities, and llUnescapeURL doesn't know how to convert those. The loop will parse out the entitie names and replace them with the correct character from the list. it's a short list. perhaps someone has a full list of characters that will/will not convert in this case?

 

default
{
    state_entry()
    {
        list dets = llGetObjectDetails(llGetKey(),[OBJECT_GROUP]);
        key uuid = llList2Key(dets,0);
        llHTTPRequest("http://world.secondlife.com/group/"+(string)uuid,[],"");
   }

    http_response(key id, integer status, list data, string body)
    {
        list parsed = llParseString2List(body,["<title>","</title>"],[]);
        string groupname = llList2String(parsed,1);
        list parsedname = llParseString2List(groupname,[],["&lt;","&rt;","&quote;","&amp;","&cent;","&pound;","&yen;","&euro;","&copy;","&reg;"]);
        integer len = llGetListLength(parsedname);
        integer i;
        list replace = ["&lt;","<","&rt;",">","&quote;","\"","&amp;","&","&cent;","¢","&pound;","£","&yen;","¥","&euro;","€","&copy;","©","&reg;","®"];
        for(i = 0;i < len;i++)
        {
            string substring = llList2String(parsedname,i);
            integer idx = llListFindList(replace,[substring]);
            if(~idx && !(idx%2))
            {
                parsedname = llListReplaceList(parsedname,llList2List(replace,idx+1,idx+1),i,i);
            }
        }
        groupname = llDumpList2String(parsedname,"");
        llSetText(groupname,<1,0,1>,1.0);
    }
}

 

 

Edited by Ruthven Willenov
  • Like 2

Share this post


Link to post
Share on other sites
Posted (edited)

I know, it could be an endless list on the parsing, but more characters from ISO-8859-1 in code range 160-191( for example &acute ), would catch most Western letters and display text correct in SL.

Edited by Rachel1206

Share this post


Link to post
Share on other sites
Posted (edited)

There's a simpler approach if you just need to print the name.

But it doesn't get you the name as a string, because the "secondlife" URL is expanded in the viewer for display in the chat window. It's not expanded on the LSL side. Demonstration:

string Who(key id)
{
    return "secondlife:///app/agent/" + (string)id + "/inspect";
}
 
default
{
    touch_start(integer num)
    {
        llSay(0, "Touched by " + Who(llDetectedKey(0)) + "." ); // this works

        string s = Who(llDetectedKey(0)); // this doesn't work
        integer len = llStringLength(s);
        integer i;
        for (i=0; i<len; i++)
        {   string ch = llGetSubString(s,i,i);
            llOwnerSay(ch);
        }
    }
}

This will print the name of the avatar touching the object with llSay. But if we print the string letter by letter, it's not interpreted as a special "secondlife" URL.

Also "llHttpRequest" won't accept "secondlife" URLs; you get a script error. So that won't work either.

Edited by animats
Comment the code

Share this post


Link to post
Share on other sites

This isn't for the avatar name. This is the name of the group assigned to whichever object you're checking it on.

And not to print in chat necessarily, but just to retrieve it as a string for use where ever needed.

The script I have above works, but I extended the list of characters that are escaped in the php code but forgot to keep the 8 entry limit in mind

Share this post


Link to post
Share on other sites

That expression will work for the name of a group, too. I've tried it on parcel info.

Share this post


Link to post
Share on other sites
2 hours ago, animats said:

That expression will work for the name of a group, too. I've tried it on parcel info.

Right, but my point is that it only works to print it out in chat. Try using it in llSetText, use llEmail to send an email to yourself, anything other than printing in chat, it will show up as the link, not the name, and it will print the secondlife:///.....string, which isn't usefull for what i made the above script for. 

Share this post


Link to post
Share on other sites
Posted (edited)

Fixed it here. It now runs a loop to check for individual special characters that get changed in webcode. Tested with several different groups by manually over-riding the UUID it inserted. Found a couple of other characters that get changed and added them to the list

Added in a test for when the object isn't set to a group so it doesn't run the http request on an empty or null key

 

string pref = "http://world.secondlife.com/group/";
default
{
    state_entry()
    {
        list dets = llGetObjectDetails(llGetKey(),[OBJECT_GROUP]);
        key uuid = llList2Key(dets,0);
        if(uuid)
        {
            llHTTPRequest(pref+(string)uuid,[],"");
        }
        else
        {
            llSetText("No Group",<1,0,0>,1.0);
        }
   }

    http_response(key id, integer status, list data, string body)
    {
        list parsed = llParseString2List(body,["<title>","</title>"],[]);
        string groupname = llList2String(parsed,1);
        string groupnameold = groupname;
        list replace = ["&lt;","<","&gt;",">","&rt;",">","&quote;","\"","&quot;","\"","&amp;","&","&cent;","¢","&pound;","£","&yen;","¥","&euro;","€","&copy;","©","&reg;","®","&#39;","'"];
        integer len = llGetListLength(replace);
        integer i;
        for(i = 0;i < len;i += 2)
        {
            string seq = llList2String(replace,i);
            integer seqlen = llStringLength(seq);
            integer idx = llSubStringIndex(groupname,seq);
            while(~idx)
            {
                groupname = llDeleteSubString(groupname,idx,idx+(seqlen-1));
                groupname = llInsertString(groupname,idx,llList2String(replace,i+1));
                idx = llSubStringIndex(groupname,seq);
            }
        }
        llSetText(groupname+"\n"+groupnameold,<1,0,1>,1.0);
    }
}

 

Edited by Ruthven Willenov
  • Like 1

Share this post


Link to post
Share on other sites
26 minutes ago, Ruthven Willenov said:

Found a couple of other characters that get changed and added them to the list

There are over 2000 named entities not to mention the dec and hex numbered equivalents.

There are many cases of a number value having 2 to 6 different named entities as well.

We really need an LSL entities support function the same as php's encode and decode functions.

The scripted alternative requires at least two "library" scripts to house all the named entities and number values.

  • Like 1

Share this post


Link to post
Share on other sites

I also wonder what characters are/aren't usable in group names. But that's only 1 part of it. I noticed in my random group searches to find names with special characters, that some had their name I  plain letters, but them started the group description with their name in/with special characters. And just to test, the description characters also get converted

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×