02-18-2013, 03:40 AM
PHP Code:
// Cross-region intercom: MESSAGE RELAY
//////////////////////////////////////////////////////////
//--------------------- INTERNALS ----------------------//
//////////////////////////////////////////////////////////
list beaconQueue;
list messageQueue;
integer isValidURL(string URL)
{
if(~llSubStringIndex(URL, "http://") &&
~llSubStringIndex(URL, "lindenlab.com") &&
~llSubStringIndex(URL, "cap"))
{
return TRUE;
}
return FALSE;
}
default
{
state_entry()
{
llSetTimerEvent(1.0);
}
link_message(integer sender_num, integer num, string str, key id)
{
list msg = llParseString2List(id, ["="], [""]);
if(llList2String(msg, 0) != "@send_message")
{
return;
}
list broadcastBeacons = llCSV2List(str);
if(!llGetListLength(broadcastBeacons))
{
return;
}
integer itra;
for(itra = 0; itra < llGetListLength(broadcastBeacons); ++itra)
{
if(~llListFindList(beaconQueue, llList2List(broadcastBeacons, itra, itra)))
{
jump continue;
}
if(!isValidURL(llList2String(broadcastBeacons, itra)))
{
jump continue;
}
beaconQueue += llList2List(broadcastBeacons, itra, itra);
@continue;
}
messageQueue += llList2List(msg, 1, 1);
}
timer()
{
if(!llGetListLength(messageQueue))
{
jump reschedule;
}
if(isValidURL(llList2String(beaconQueue, 0)) && isValidURL(llList2String(beaconQueue, 0)))
{
llHTTPRequest(llList2String(beaconQueue, 0), [HTTP_METHOD, "PUT"], llList2String(messageQueue, 0));
}
beaconQueue = llDeleteSubList(beaconQueue, 0, 0);
if(!llGetListLength(beaconQueue))
{
messageQueue = llDeleteSubList(messageQueue, 0, 0);
}
@reschedule;
llSetTimerEvent(1.0);
}
}