Difference between revisions of "Get Profile Picture"
Jump to navigation
Jump to search
m (*fixed a few errors after compiling in-world*) |
m (Replaced <source> with <syntaxhighlight>, and http with https) |
||
(12 intermediate revisions by 6 users not shown) | |||
Line 2: | Line 2: | ||
Get Profile Picture by Valentine Foxdale | Get Profile Picture by Valentine Foxdale | ||
<syntaxhighlight lang="lsl2"> | |||
< | |||
// Snippets and HTTPRequest bits were taken from: | // Snippets and HTTPRequest bits were taken from: | ||
//~ RANDOM PROFILE PROJECTOR v5.4.5 by Debbie Trilling ~ | //~ RANDOM PROFILE PROJECTOR v5.4.5 by Debbie Trilling ~ | ||
// Get Profile Picture by Valentine Foxdale | // Get Profile Picture by Valentine Foxdale | ||
// optmisation by SignpostMarv Martin | |||
// workaround for WEB-1384 by Viktoria Dovgal: | |||
// try meta tag instead of img first, try img as backup in case meta breaks | |||
list sides; | list sides; | ||
list deftextures; | list deftextures; | ||
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_key_prefix in state_entry() | |||
GetProfilePic(key id) //Run the HTTP Request then set the texture | GetProfilePic(key id) //Run the HTTP Request then set the texture | ||
{ | { | ||
//key id=llDetectedKey(0); This breaks the function, better off not used | //key id=llDetectedKey(0); This breaks the function, better off not used | ||
string URL_RESIDENT = "https://world.secondlife.com/resident/"; | |||
llHTTPRequest( URL_RESIDENT + (string)id,[HTTP_METHOD,"GET"],""); | llHTTPRequest( URL_RESIDENT + (string)id,[HTTP_METHOD,"GET"],""); | ||
} | } | ||
Line 41: | Line 48: | ||
state_entry() | state_entry() | ||
{ | { | ||
llSetText("Touch for this object to display your profile picture!",<0.8,0,1>,1); //Note: Usage of another person's profile picture without their permission may be viewed as copyright infringement. | profile_key_prefix_length = llStringLength(profile_key_prefix); | ||
profile_img_prefix_length = llStringLength(profile_img_prefix); | |||
llSetText("Touch for this object to display your profile picture!",<0.8,0,1>,1); | |||
//Note: Usage of another person's profile picture without their permission may be viewed as copyright infringement. | |||
GetDefaultTextures(); | GetDefaultTextures(); | ||
} | } | ||
Line 50: | Line 60: | ||
http_response(key req,integer stat, list met, string body) | http_response(key req,integer stat, list met, string body) | ||
{ | { | ||
integer s1 = llSubStringIndex(body, | integer s1 = llSubStringIndex(body, profile_key_prefix); | ||
integer s1l = | integer s1l = profile_key_prefix_length; | ||
if(s1 == -1) | |||
{ // second try | |||
if(s1 == -1){SetDefaultTextures();} | s1 = llSubStringIndex(body, profile_img_prefix); | ||
s1l = profile_img_prefix_length; | |||
} | |||
if(s1 == -1) | |||
{ // still no match? | |||
SetDefaultTextures(); | |||
} | |||
else | else | ||
{ | { | ||
key UUID=llGetSubString(body,s1+ | s1 += s1l; | ||
llSetTexture(UUID,ALL_SIDES); | key UUID=llGetSubString(body, s1, s1 + 35); | ||
if (UUID == NULL_KEY) { | |||
SetDefaultTextures(); | |||
} | |||
else { | |||
llSetTexture(UUID,ALL_SIDES); | |||
} | |||
} | } | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> |
Latest revision as of 10:26, 26 February 2024
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Get Profile Picture by Valentine Foxdale
// Snippets and HTTPRequest bits were taken from:
//~ RANDOM PROFILE PROJECTOR v5.4.5 by Debbie Trilling ~
// Get Profile Picture by Valentine Foxdale
// optmisation by SignpostMarv Martin
// workaround for WEB-1384 by Viktoria Dovgal:
// try meta tag instead of img first, try img as backup in case meta breaks
list sides;
list deftextures;
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_key_prefix in state_entry()
GetProfilePic(key id) //Run the HTTP Request then set the texture
{
//key id=llDetectedKey(0); This breaks the function, better off not used
string URL_RESIDENT = "https://world.secondlife.com/resident/";
llHTTPRequest( URL_RESIDENT + (string)id,[HTTP_METHOD,"GET"],"");
}
GetDefaultTextures() //Get the default textures from each side
{
integer i;
integer faces = llGetNumberOfSides();
for (i = 0; i < faces; i++)
{
sides+=i;
deftextures+=llGetTexture(i);
}
}
SetDefaultTextures() //Set the sides to their default textures
{
integer i;
integer faces;
faces = llGetNumberOfSides();
for (i = 0; i < faces; i++)
{
llSetTexture(llList2String(deftextures,i),i);
}
}
default
{
state_entry()
{
profile_key_prefix_length = llStringLength(profile_key_prefix);
profile_img_prefix_length = llStringLength(profile_img_prefix);
llSetText("Touch for this object to display your profile picture!",<0.8,0,1>,1);
//Note: Usage of another person's profile picture without their permission may be viewed as copyright infringement.
GetDefaultTextures();
}
touch_start(integer total_number)
{
GetProfilePic(llDetectedKey(0));
}
http_response(key req,integer stat, list met, string body)
{
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?
SetDefaultTextures();
}
else
{
s1 += s1l;
key UUID=llGetSubString(body, s1, s1 + 35);
if (UUID == NULL_KEY) {
SetDefaultTextures();
}
else {
llSetTexture(UUID,ALL_SIDES);
}
}
}
}