Difference between revisions of "Display Names to Key"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL Header}}__NOTOC__ == DisplayName2Key == The new function for displaynames lacks an ability to do a reverse like llDisplayName2Key(key id) We now give you the possibility t…")
 
m
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header}}__NOTOC__
{{LSL Header}}__NOTOC__
== DisplayName2Key ==
The new function for displaynames lacks an ability to do a reverse like llDisplayName2Key(key id)
We now give you the possibility to do so. But you need to keep in mind DISPLAYNAMES ARE NOT UNIQUE.
<div id="box">


== Library ==
== Library ==


<lsl>
<source lang="lsl2">
string NAME;
string NAME;
string URL  = "http://cyber.caworks-sl.de/name2key/n2k.php";
string URL  = "http://cyber.caworks-sl.de/name2key/n2k.php";
string URL2 = "http://www.aga-sl.de/projekte/name2key/n2k.php"; // just in case the URL above should not be working
key reqid;
key reqid;
/// chat: /101 <displayname>


default
default
Line 48: Line 45:
         }
         }
     }
     }
}</lsl>
}
</div>
</source>
 


<div id="box">
<div id="box">


and here the PHP for use on your Server
and here the PHP for use on your Server. Name it n2k.php. It also integrates to websites. So you can use it to search from you page.


<php>
<source lang="php">
<div align="center"><font size="-1"><font color="#FFFFF0">
<div align="center"><font size="-1"><font color="#FFFFF0">
<?php
<?php
Line 110: Line 108:
}
}
?>
?>
</php></div>
</source>
[[User:Joran Yoshikawa|Joran Yoshikawa]]
 
{{LSLC|Library}}{{LSLC|Examples|DisplayName2Key}}
{{LSLC|Library}}{{LSLC|Examples|DisplayName2Key}}

Latest revision as of 20:02, 24 January 2015

Library

string NAME;
string URL   = "http://cyber.caworks-sl.de/name2key/n2k.php";
string URL2 = "http://www.aga-sl.de/projekte/name2key/n2k.php"; // just in case the URL above should not be working
key reqid;

/// chat: /101 <displayname>

default
{
    state_entry()
    {
        llListen(101,"","","");
    }
    listen(integer c, string n, key id, string message)
    {
        if(c == 101)
        {
            NAME = message;
            reqid = llHTTPRequest( URL + "?name=" + llEscapeURL(NAME), [], "" );
        }
    }
    http_response(key id, integer status, list meta, string body)
    {
        body = llDeleteSubString(body, 0 , llSubStringIndex(body, "<br>") + 3);
        if ( id != reqid )
        {
            return;
        }
        if ( status == 499 )
        {
            llOwnerSay("timed out");
        }
        else if ( status != 200 )
        {
            llOwnerSay("Server Offline");
        }
        else
        {
            llOwnerSay(NAME + "'s key is: " + body );
        }
    }
}


and here the PHP for use on your Server. Name it n2k.php. It also integrates to websites. So you can use it to search from you page.

<div align="center"><font size="-1"><font color="#FFFFF0">
<?php
$username = $_GET["name"];
if($username == "")
{
echo '<div align="center"><font size="-1">
<form action="n2k.php" method="GET">
<input type="text" size="18" maxlength="40" value="SL Name" name="name">
<br><input type="submit" value="lookup">
</form>';
}
else
{
$uuid = name2Key($username);
echo "<br>$uuid";
}
    function getPage($web)
	{
		$html = "";
		  $ch = curl_init($web);
		  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12");
		  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		  curl_setopt($ch, CURLOPT_HEADER, 0);
		  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		  curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
		  curl_setopt($ch, CURLOPT_TIMEOUT, 5);
		  $html = curl_exec($ch);
		  if(curl_errno($ch))
		  {
			  $html = "";
		  }
		  curl_close ($ch);
		return $html;
	}
    function getBetween($content,$start,$end)
	{
		$a1 = strpos($content,$start);
		$content = substr($content,$a1 + strlen($start));
		while($a2 = strrpos($content,$end))
		{
			$content = substr($content,0,$a2);
		}
		return $content;
	}
    function name2Key($name)
	{
		$SL_SEARCH = 'http://search.secondlife.com/client_search.php?s=People&t=N&q=';
		$sName = split(' ',$name);
		$data = getPage($SL_SEARCH.$sName[0].'%20'.$sName[1]);
		$uuid = getBetween($data,'http://world.secondlife.com/resident/','"');
                if(!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/",$uuid)) $uuid = '00000000-0000-0000-0000-000000000000';
		return $uuid;
	}
?>