Difference between revisions of "Display Names to Key"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
== 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";
Line 46: Line 46:
     }
     }
}
}
</lsl>
</source>
</div>
 


<div id="box">
<div id="box">
Line 53: Line 53:
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.
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 108: Line 108:
}
}
?>
?>
</php></div>
</source>
{{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;
	}
?>