Jump to content
You are about to reply to a thread that has been inactive for 4254 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Posted

Hi,

 

In Our system we are transferring fund from secondlife game to our website and visa versa.


Now, we have created one Object which have communicator script( this script is a mediator between debit prim script and php script) and debit prim script( this is a script where our code of debit prim is located like using llTransaferFnds we are transferring funds form game to site or site to game).

It's all working perfectly until the sim is reset.
When the sim is rest we are getting new url like http://sim9736.agni.lindenlab.com:12046/cap/1351c161-06ee-44cb-3113-f78a489dca43 using llResetURL() function. But, we are not able to Get Avatar Details and Owner Details.

 

Here, is the code to Get server url,owner and avatar details. And we have placed this code in changed() function

We have placed two files

 

1) Communicator script.

default
{
    // calling the function setup.
    state_entry() {      
        llRequestURL();
    }
 
    changed(integer c)
    {

    // Calling the function setup at the time of  "CHANGED_REGION" and "CHANGED_TELEPORT"

        if (c & (CHANGED_REGION | CHANGED_TELEPORT) )
        {
            llRequestURL();
        }
        
    //
    // sending the Request URL(http://sim8890.agni.lindenlab.com:12046/cap/0c885b4d-8c15-ba9b-657a-abb95ae86e33) to  Site.
    //
        if (c & (CHANGED_REGION_START)) {
            http_url_withdrawal = "http://" + http_host + http_path_withdrawal;
            llInstantMessage(llGetOwner(),"REGION RESTARTED AT "+(string)llGetTime()+" - at timestamp "+(string)llGetUnixTime());
            llInstantMessage(llGetOwner(),"MESSAGE1"+(string)http_url_withdrawal);
            llRequestURL();
            ok = TRUE;
              http_withdrawal_body += "&" + llEscapeURL("avatar_name") + "=" + llEscapeURL((string)llKey2Name(llGetOwner()));
              http_withdrawal_body += "&" + llEscapeURL("avatar_key") + "=" + llEscapeURL((string)llGetOwner());
              http_withdrawal_body += "&" + llEscapeURL("server_key") + "=" + llEscapeURL((string)llGetKey());
              http_withdrawal_body += "&" + llEscapeURL("server_url") + "=" + llEscapeURL(llRequestURL());
              http_request_withdrawal_id = llHTTPRequest(http_url_withdrawal, http_post_parameters, http_withdrawal_body);
        }
    }
 
    
    touch_start(integer n)
    {
        
    }
 
    // the script receives a link message that was sent by a call to llMessageLinked

    link_message(integer sender_number, integer number, string message, key id) {
        list terminal = llParseString2List(message, ["&"], [""]);
        list option = llParseString2List((string) llList2String(terminal, 7), ["="], [""]);
        http_url_withdrawal = "http://" + http_host + http_path_withdrawal;
        if (DEBUG)
            llSay(DEBUG_CHANNEL, (string) http_url_withdrawal);
        site_url = http_url_withdrawal;
     
        if (number == MY_ACCOUNT_RQ) {
            string text = (string) id + (string) llGetKey() + (string) llGetOwner() + (string) ((integer) message);
             
            reqId = llHTTPRequest(SERVER_URL + "?avkey=" + (string) id + "&amount=" + message + "&url=" + site_url + "&hash=" + (string) HASHKEY, [], "");
            
        }   
    }

    //
    // Checking the state i.e. URL_REQUEST_DENIED,URL_REQUEST_GRANTED .
    //
    http_request(key id, string method, string body)
    {
        if (method == URL_REQUEST_GRANTED)
        {
        llInstantMessage(llGetOwner(),"request body....."+body);
            url = body;
           ok = TRUE;
        }
        else if (method == URL_REQUEST_DENIED)
        {
            llSay(0, "Something went wrong, no url. " + body);
        }
        else
        {
            llHTTPResponse(id,405,"Method unsupported");
        }
    }        
        
   //
   // getting the response from the  site.
   //
    http_response(key request_id, integer status, list metadata, string body) {
     llSay(0,body);
     if (request_id == http_request_hashkey_id) {
            HASHKEY = (integer) body;
        }
        if (request_id == reqId){
            reqId = NULL_KEY;
            if (status == 200) {
                list Data = llParseStringKeepNulls(body, ["|"], []);
                if ((llList2Key(Data, 0) == llGetKey()) &&
                        (llMD5String((string) llGetOwner() + (string) llGetKey() + llList2String(Data, 1), HASHKEY) == llList2String(Data, 2)))
                    llMessageLinked(LINK_SET, MY_ACCOUNT_ANS, llList2String(Data, 1), NULL_KEY);
                else
                    llMessageLinked(LINK_SET, MY_ACCOUNT_ANS, llList2String(Data, 1), NULL_KEY);
            }
            else if (status != 200) {
                llMessageLinked(LINK_SET, MY_ACCOUNT_ANS, body, NULL_KEY);
            }
        }
    }

 

2) Debit Prim Script

//
// sending the Transaction Result to  Site.
//

withdraw_transaction_result(key id, integer success, string message) {
    http_url_transaction_result = "http://abc.com/xyz/components/com_terminal/transaction_result.php";
    http_transaction_result_body+= "&" + llEscapeURL("avatar_name") + "=" + llEscapeURL(llKey2Name(id));
    http_transaction_result_body+= "&" + llEscapeURL("avatar_key") + "=" + llEscapeURL((string) id);
    http_transaction_result_body+= "&" + llEscapeURL("terminal_key") + "=" + llEscapeURL((string) llGetKey());
    http_transaction_result_body+= "&" + llEscapeURL("message") + "=" + llEscapeURL(message);
    http_transaction_result_body+= "&" + llEscapeURL("amount") + "=" + llEscapeURL((string) Amount);
    http_transaction_result_body+= "&" + llEscapeURL("success") + "=" + llEscapeURL((string) success);
    http_transaction_result_body+= "&" + llEscapeURL("option") + "=" + llEscapeURL("transaction_result");
    http_request_transaction_result_id = llHTTPRequest(http_url_transaction_result, http_post_parameters, http_transaction_result_body);
}



//
// Function is used to send Request to site for withdrawing money.  
//

debit_prime(string url){
owner_name = llEscapeURL((string) llKey2Name(llGetOwner()));
http_withdrawal_body += "&" + llEscapeURL("module_name") + "=" + llEscapeURL(module_name);
http_withdrawal_body += "&" + llEscapeURL("avatar_name") + "=" + owner_name;
http_withdrawal_body += "&" + llEscapeURL("avatar_key") + "=" + llEscapeURL((string) llGetOwner());
http_withdrawal_body += "&" + llEscapeURL("server_key") + "=" + llEscapeURL((string) llGetKey());
http_withdrawal_body += "&" + llEscapeURL("server_url") + "=" + llEscapeURL((string) url);
http_withdrawal_body += "&" + llEscapeURL("owner_name") + "=" + llEscapeURL(llKey2Name(llGetOwner()));
http_withdrawal_body += "&" + llEscapeURL("owner_key") + "=" + llEscapeURL(llGetOwner());
http_withdrawal_body += "&" + llEscapeURL("creator_name") + "=" + llEscapeURL(llKey2Name(llGetCreator()));
http_withdrawal_body += "&" + llEscapeURL("creator_key") + "=" + llEscapeURL(llGetCreator());
http_withdrawal_body += "&" + llEscapeURL("option") + "=" + llEscapeURL("debit_prime");
llMessageLinked(LINK_SET, MY_ACCOUNT_RQ, http_withdrawal_body, id);
}


default {
    //
    // Rest the Script When Object is Rezzed
    //    

   on_rez(integer start_param){
        llResetScript();       
    }
     
    
    state_entry() {
       state banker;
    }

    //
    // Resetting the Secript at the time of CHANGED_REGION or CHANGED_TELEPORT
    //

    changed(integer change) {  
        if (change & (CHANGED_REGION | CHANGED_TELEPORT)) {
            llResetScript();
        }
    }

}

state banker {

    //
    // Allowing the Permission  Debit .
    //

    state_entry() {
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);

        stopped = FALSE;

        if (curuser == NULL_KEY) {
            llMessageLinked(LINK_THIS, 5, "", NULL_KEY);
            state default;
        }
    
        listenhandle = llListen(40, "", curuser, "");

        if (creator_uuid == "") creator_uuid = llGetCreator();

        check_timeout = llGetUnixTime() + llFloor(check_time);

        llSetTimerEvent(timer_rate);
        llSetTimerEvent(15.0);
        llRequestURL();
    }

    //
    //Set the Run time permission.
    //

    run_time_permissions (integer perm) {
        if (perm & PERMISSION_DEBIT)
            DebitPerms = TRUE;
    }

    //
    //    Setting the avatar name,Recipient,avtar id etc. When Object touched.
    //

    touch_start(integer start) {
        avatar_name = llDetectedName(0);
        Recipient = avatar_name;
        avatar_id = llDetectedKey(0);
        debit_prime(server_url);
        llRequestURL();
    }

    //
    //    listening the response from  server.
    //
    listen( integer channel, string name, key id, string message ) {
       debit_prime(server_url);
        llMessageLinked(LINK_THIS, 5, "", NULL_KEY);
        state banker;
    }

    http_response(key request_id, integer status, list metadata, string body) {
        if (request_id == http_request_transaction_result_id) {
            
        }
    }
    
    //
    // Function used to get the transaction result.
    //

    transaction_result(key id, integer success, string data) {
        if (id != TransactionID)
            return;       
        if (success) {
            t_result = data;
            llOwnerSay("Transfer of L$ to " + Recipient + " was successful");
            llSleep(1.0);
        } else {
            t_result = data;
            llOwnerSay("Transfer of L$ failed");
        }
        withdraw_transaction_result(id, success, data);
    }


    //
    // sending the request for llTransferLindenDollars.
    //    
 
    http_request(key id, string method, string body) {

        list withdrawal = llParseString2List(body, [","], []);
        if ((method == URL_REQUEST_GRANTED)) {
            server_url = body;
        } else if (method == "POST") {
            if (!DebitPerms)
                return;  // Cannot proceed - debit permissions not granted
            Amount = llList2Integer(withdrawal, 1);
            TransactionID = llTransferLindenDollars(llList2Key(withdrawal, 0), llList2Integer(withdrawal, 1));
            body+=t_result;
            llHTTPResponse(id, status_code, body);
        }
    }
    
    //
    //set timer event. (old script code)
    //
    
    timer() {
        llGetNextEmail("", "");
    }

    //
    // set the email function (old script code)
    //

    email( string time, string address, string subject, string message, integer num_left ) {
        if (subject == withdrawal_subject) {
            list Inventory = llParseString2List(llStringTrim(message, STRING_TRIM), [","], []);
            llGiveMoney(llList2Key(Inventory, 0), llList2Integer(Inventory, 1));
            if (DEBUG)
                llSay(DEBUG_CHANNEL, (string) llList2Key(Inventory, 0));
            if (DEBUG)
                llSay(DEBUG_CHANNEL, llList2String(Inventory, 1));
        }

        if (num_left)
            llGetNextEmail("", "");
    }

      //
     // linking the result with script When site sending response.
     //

    link_message(integer sender_num, integer num, string str, key id) {
        if (num == 99) {
            state default;
        }
        if (num == MY_ACCOUNT_ANS) {
            if (str == "")
                llOwnerSay("There was an error");
            else {
                llSay(0, str);
            }
        }
    }
}

 

We are updating the details( server url, owner name,owner key,avatar name and avatar key) in database after  sim is reset.

so, user will able to transfer money after sim is rest. with reseting debit prim object by owner manually.

because owner will not know When sim is reset and When he/she need to reset demit prim.

 

Is there any way to get complete details ( server url, owner name,owner key,avatar name and avatar key) at the time of sim rest please help us. and is there any changes in above script please correct us.

 

Thanks.

 

Posted

Niral,

Asking your question in the Scripting Forum is your best bet as Amethyst suggested.

BTW you are running across the fact that Owner Avatar names are NOT stored with the object. The Owner Avatar UUID is. The basic LLfunction to retrieve the Avatar Name from the UUID supplied as an argument depends on the name being in the Region Memory. Of course immediately after a region has been restarted this is NOT the case. This is why many products and scripters keep a external database of UUID to Avatar name lookups for the rezzed objects within a particular product line. You'll see methods to deal with this in the Scripters Forum and LSL Example Library..

Additionally, the Debit Prim Object does not lose it's permission to debit as a result of a region restart. Now if it is selected by the owner and has a script reset done against it, then the current Script State is completely reset [cleared] and the Authorization for Debit permission will be null.

Now please be a good scripter and move these requests to the Scripters Forum.

http://community.secondlife.com/t5/LSL-Scripting/bd-p/LSLScripting

 

 

You are about to reply to a thread that has been inactive for 4254 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...