My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
                
Search
for
Updated Jan 01, 2010 by lordgreggreg
Labels: Phase-Deploy
LSLClientBridge  
Information about Emerald lsl to client object

What it does

Why do I want that?

How can I turn this power on?

How exactly does this work though?

More Information


integer channel(key id)
{
    //llOwnerSay(llMD5String((string)id,1));
    return (integer)("0x"+llGetSubString(llMD5String((string)id,1),0,6));
}
integer recieve_channel;// = channel(key id)
integer tid;
integer altListenHandler;
integer listenReq;
integer startTime;
vector  moveToTarget;

integer tid2;
integer l2c;
connect()
{
    llListenRemove(tid);
    tid = llListen(recieve_channel,"",llGetOwner(),"");
    if(l2c != 0)
    {
        llListenRemove(tid2);
        tid2 = llListen(l2c,"",llGetOwner(),"");
    }
    if(llGetAttached() != 0)llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA | PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
}
send(string data)
{
    if(llStringLength(data) > (1023 - 5))llOwnerSay("ERR: string too long");
    llOwnerSay("#@#@#"+data);
  //llOwnerSay("Sending"+data);
}

integer max_rand_integer()
{ 
    return (integer)(((llFrand(0.999998) + 0.000001) + ((llFrand(0.899) + 0.1) * 1000)) * 1000000);
}
recieve(string data)
{
    list instruction = llParseString2List(data,["|"],[]);
    integer id = (integer)llList2String(instruction,0);
    string cmd = llList2String(instruction,1);
    if(cmd == "online_status")
    {
        onlinereqs += [id, llRequestAgentData((key)llList2String(instruction,2), DATA_ONLINE)];
        //llOwnerSay("processing online request");
    }if(cmd == "http_req")
    {
        list m;
        if(llList2String(instruction,3) == "POST")m = [HTTP_METHOD, "POST"];
        httpreqs += [id, llHTTPRequest(llList2String(instruction,2),m,llList2String(instruction,4))];
        //llOwnerSay("processing online request");
    }else if(cmd == "pos")
    {
        list positions = [id];
        integer inc = 2;
        for(;inc<(instruction!=[]);inc++)
        {
            //send in the same order we recieved.
            positions += [(string)llGetObjectDetails((key)llList2String(instruction,inc),[OBJECT_POS])];
        }
        send(llDumpList2String(positions,"|"));
    }else if(cmd == "listen")//for client listening on channels, 0 to stop
    {
        listenReq = id;
        llListenRemove(altListenHandler);
        integer channelToListenOn = (integer)llList2String(instruction,2);
        if(channelToListenOn)
            altListenHandler = llListen(channelToListenOn,"",NULL_KEY,"");
    }else if (cmd == "move")//for client to use llmovetotarget
    {
        moveToTarget=(vector)llList2String(instruction,2);
        startTime=llGetUnixTime();
        llSetTimerEvent(.05);
    }else if(cmd == "l2c")
    {
        l2c = max_rand_integer();
        connect();
        llOwnerSay("l2c"+(string)l2c);
    }
}

list onlinereqs;
list httpreqs;
default
{
    state_entry()
    {
        recieve_channel = channel(llGetOwner());
        //llOwnerSay((string) recieve_channel);
        connect();
    }

    listen(integer channel, string name, key id, string message)
    {
        if(channel == recieve_channel || channel == l2c)
        {
            recieve(message);
            return;
        }
        send(llDumpList2String([listenReq,channel,name,id,message],"|"));
    }
    
    run_time_permissions(integer p)
    {
        if(p)llTakeControls(1024,1,1);
    }
    
    dataserver(key id, string data) 
    {
        integer i = llListFindList(onlinereqs,[id]);
        if(i != -1)
        {
            //llOwnerSay("returning online request");
            send((string)llList2Integer(onlinereqs,i-1)+"|"+data);
            onlinereqs = llDeleteSubList(onlinereqs,i-1,i);
        }
    }
    
    http_response(key id, integer status, list meta, string body)
    {
        integer i= llListFindList(httpreqs,[id]);
        if(i != -1)
        {
            send((string)llList2Integer(httpreqs,i-1)+"|"+(string)status+"|"+llList2CSV(meta)+"|"+body);
            httpreqs = llDeleteSubList(httpreqs,i-1,i);
        }
    }
    
    timer()
    {
        llSetTimerEvent(0.0);
        if(llGetUnixTime() - 10 > startTime){llStopMoveToTarget();return;}
        vector us = llGetPos();
        vector dist = moveToTarget - us;
        float mag = llVecMag(dist);
        if(mag < 1.0){llStopMoveToTarget();return;}
        if(mag>45) llMoveToTarget(us+llVecNorm(dist)*45,.05);
        else llMoveToTarget(moveToTarget,.05);
        llSetTimerEvent(.05);
    }
}

Security


Comment by AtticusVulpes, Jan 15, 2010

Just a stupid little note for run time efficiancy:

use i+=1 instead of i++. It actually does run and compile faster.

Also curious if there is an easy way that this could be turned into a running API for the client to effectively program your own tools without opening the client source itself. I'll have to post more on the forums.


Sign in to add a comment
Hosted by Google Code