[slscripters] Regarding transfer money when sim is reset.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[slscripters] Regarding transfer money when sim is reset.

snc-3

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.


_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters
Reply | Threaded
Open this post in threaded view
|

Re: [slscripters] Regarding transfer money when sim is reset.

Darien Caldwell-2

you're not requesting a new URL during changed_region_start in the changed() event.

Doing it during changed_region and changed_teleport is not enough.


_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters
Reply | Threaded
Open this post in threaded view
|

Re: [slscripters] Regarding transfer money when sim is reset.

Stickman-2
> you're not requesting a new URL during changed_region_start in the changed()
> event.
>
> Doing it during changed_region and changed_teleport is not enough.

This advice is for the bank script, yes. You do this in the comm
script. Make sure, in the bank script, you do it in the "banker"
state, not the default state.

One thing I notice is that you're using llRequestURL() and using the
URL it gives you raw. Even if you want to use a one-time disposable
URL, you would need to assign it to a variable and clear it on a
timer, or after you get a reply.

Read up on the wiki page for how it is intended to be used.

http://wiki.secondlife.com/wiki/LlRequestURL
"The number of available URLs is a limited resource, that is to say, a
script can only have so many open URLs."
"When abandoning a URL, always release it with llReleaseURL, otherwise
it will leak."

The example function shows how it's assigned to a global variable
(string url) and is always released before a new one is called, in
request_url().

Stickman
_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters
Reply | Threaded
Open this post in threaded view
|

Re: [slscripters] Regarding transfer money when sim is reset.

Dale Innis
> But, we are not able to Get Avatar Details and Owner Details.

By "details", do you mean the name, or something else (also)?  Note that llKey2Name(), and for that matter llGetObjectDetails(), only works reliably if the person is currently in the sim.  So I would suggest that you get that information at the time that you know the person is around, and then rather than resetting the script entirely on the changed events (which loses the name information), just have the changed events re-do the things that need to be re-done.  Or you could do something awful like storing the names in a prim description or something, but ick.  :)



On Thu, Apr 18, 2013 at 11:08 AM, Stickman <[hidden email]> wrote:
> you're not requesting a new URL during changed_region_start in the changed()
> event.
>
> Doing it during changed_region and changed_teleport is not enough.

This advice is for the bank script, yes. You do this in the comm
script. Make sure, in the bank script, you do it in the "banker"
state, not the default state.

One thing I notice is that you're using llRequestURL() and using the
URL it gives you raw. Even if you want to use a one-time disposable
URL, you would need to assign it to a variable and clear it on a
timer, or after you get a reply.

Read up on the wiki page for how it is intended to be used.

http://wiki.secondlife.com/wiki/LlRequestURL
"The number of available URLs is a limited resource, that is to say, a
script can only have so many open URLs."
"When abandoning a URL, always release it with llReleaseURL, otherwise
it will leak."

The example function shows how it's assigned to a global variable
(string url) and is always released before a new one is called, in
request_url().

Stickman
_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters


_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters