Difference between revisions of "User:Joran Yoshikawa"

From Second Life Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
{{LSL Header}}__NOTOC__
{{LSL Header}}__NOTOC__
== Library ==
<lsl>
string NAME;
string URL  = "http://cyber.caworks-sl.de/name2key/n2k.php";
key reqid;
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 );
        }
    }
}</lsl>
</div>
<div id="box">
and here the PHP for use on your Server
<php>
<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;
}
?>
</php></div>
[[User:Joran Yoshikawa|Joran Yoshikawa]]
{{LSLC|Library}}{{LSLC|Examples|DisplayName2Key}}

Latest revision as of 08:13, 21 February 2011