Key Name Reconciliation
on Wednesday, July 12th, 2006 at 10:00 pmAs some of you know, neighbours has had an issue where (waiting) was displayed in place of peoples names. Basically, what was happening is that I use the new llHTTPRequest function, and just pull info from the headers, as oppossed to sending it in my request itself. Turns out, when the owner name is not readily available, SL just sends (waiting) rather than hold the request back (thanks Zarf).
So I am posting the two pieces of this reconciler [sanitized], which someone may find useful.
The LSL
//Key Name Reconcile
//By Max Case.
//Every 60 seconds, this script calls home, and if there is a (waiting) name in DB, it will look up name/Key and return those results
//
string REQUEST_URL = "http://LOCATION/TO/YOUR/RECONCILE.php?"; //leave in the ? mark...
key gk_httpreq;
key gk_client_key;
string gs_client_name;
fn_command_out( string command ) //
{
gk_httpreq =llHTTPRequest(REQUEST_URL+"COMMAND="+command,[HTTP_METHOD,"GET"],"");
}
//fn_command - parses any incoming command string, : delimeter
fn_command_in( string incoming )
{
list delim = [":"];
list cmd_arg = llParseString2List(incoming, delim, []);
if(llList2String(cmd_arg, 0) == "KEY")
{
gk_client_key = llList2Key(cmd_arg, 1);
llRequestAgentData(gk_client_key, DATA_NAME);
}
else if(llStringLength(incoming) > 1 )
{
llOwnerSay(incoming);
}
}
default
{
state_entry()
{
llSetTimerEvent(60);
}
dataserver(key queryid, string data)
{
llOwnerSay(data);
gs_client_name = data;
fn_command_out("NAMERESULT&avkey="+(string)gk_client_key+"&avname="+llEscapeURL(gs_client_name));
}
http_response(key request_id, integer status, list metadata, string body)
{
if(gk_httpreq == request_id)
{
fn_command_in(body);
}
}
timer()
{
fn_command_out("KEYPLEASE");
}
touch_start(integer num_detected)
{
if(llDetectedKey(0) == llGetOwner())
{
fn_command_out("KEYPLEASE");
s }
}
}
The PHP
//Public Version of Reconciler Script
//You will need DB connection - how you do is up to you, but I use PEAR::DB
//This is fairly basic, but I didn't have much time to waste making it elegant and robust :) It does exactly what it needs to do - no more, no less.
$db = DB::connect( "mysql://".DB_USER.":".DB_PASS."@".DB_SERVER."/".DB_NAME );
//Gets any (waiting) from DB
function GetWaiting( $db )
{
////////////////////////
//Select Key from AV where name == waiting
$sql = "SELECT av_key FROM ".TBL_AVATARS." WHERE av_name='(waiting)' LIMIT 1"; //Select just the av id of the incoming key
if ( DB::isError( $results = $db->query( $sql ) ) )
{
echo DB::errorMessage($results);
}
else
{
$result = $results->fetchRow();
return $result[0];
}
}
function UpdateName($db, $avkey, $avname)
{
$updatesql = “UPDATE “.TBL_AVATARS.” SET av_name=’”.$avname.”‘ WHERE av_key = ‘”.$avkey.”‘”;
if ( DB::isError( $results = $db->query( $updatesql ) ) )
{
echo DB::errorMessage($results);
}
else
{
echo “success”;
}
}
/////////////////
//PROCESS COMAND
if (array_key_exists(’COMMAND’,$_GET))
{
if($_GET[’COMMAND’] == “KEYPLEASE”)
{
if(GetWaiting($db))
{
echo ‘KEY:’.GetWaiting($db);
}
}
else if($_GET[’COMMAND’] == “NAMERESULT”)
{
UpdateName($db, $_GET[’avkey’], $_GET[’avname’] );
}
}
?>
my del.icio.us
July 20th, 2006 at 1:32 am
I checked out the service tonight. Very interesting. One suggestion would be to have a chache of the last 10 sims in the object that the avatar wears. This way, you don’t make redundant requests home if the avatar backtracks accross sims. It would also be nice to know if I “discovered” a sim not yet in your database.
July 20th, 2006 at 5:05 am
Thanks Dedric.
Thanks for the suggestion - Maybe I will do a cache - trying to keep it simple - let headache for me :)
But I think I can do the discovery bit pretty easy.