withdraw money, to sa-mp game
#1

Hi,

Код:
var withdrawMoneyCheckInterval = null;
var withdrawMoneyUid = 0;
var blockWithdraw = false;
function withdrawMoneyCheck()
{
    $.post("http://anywebsitebla.lt/app/get_withdraw.php", {name: userName, uid: withdrawMoneyUid, code: "0ay3j5as1Zua55f9T9s2upo"}, function( data )
    {
        var newUserData = parseINIString(data);
        if(newUserData["success"] == "0")
            return;
        clearInterval(withdrawMoneyCheckInterval);
        withdrawMoneyCheckInterval = null;
        withdrawMoneyUid = 0;
        if(newUserData["success"] == "1")
        {
            showMsg("You have money in your pocket!");
            userData["money"] = newUserData["money"];
            userData["money_bank"] = newUserData["money_bank"];
        }
        else if(newUserData["success"] == "-1")
        {
            showWarningMsg("You need play in server!");
        }
        else if (newUserData["success"] == "-2")
        {
            blockWithdraw = true;
            showWarningMsg("An authorization error!");
        }
    });
}
function withdrawMoney()
{
    if(blockWithdraw)
    {
        showWarningMsg("Do not!");
        return;
    }
    if(withdrawMoneyCheckInterval != null)
    {
        showWarningMsg("Please wait!");
        return;
    }
    var amount = parseInt(document.getElementById("withdrawAmount").value);
    if(amount > userData["money_bank"])
    {
        showWarningMsg("You don't have enought money! In bank you have: " + userData["money_bank"] + " EUR");
        return;
    }
    if(amount > 100000000)
    {
        showWarningMsg("Too big ammount!");
        return;
    }
    if(amount < 1000)
    {
        showWarningMsg("Minimum ammount 1.000 EUR!");
        return;
    }
    var PIN = document.getElementById("bankPIN").value;
    if(PIN < 1000)
        PIN = 0;
    document.getElementById("withdrawAmount").value = '';
    document.getElementById("bankPIN").value = '';
    $("#leftpanelMoneyWithdraw").panel("close");
    $.post("http://anywebsitebla.lt/app/withdraw.php", {name: userName, token: userData["token"], PIN: PIN, amount: amount, code: "0ay3j5as1Zua55f9T9s2upo"}, function( data )
    {
        if (data == "0")
        {
            showWarningMsg("Server unavailable!");
            return;
        }
        else if (data == "-1")
        {
            blockWithdraw = true;
            showWarningMsg("An authorization error!");
            return;
        }
        else
        {
            withdrawMoneyUid = data;
            showMsg("order is sent successfully!");
            withdrawMoneyCheckInterval = setInterval (withdrawMoneyCheck, 11000);
        }
    });
}
This code is using to withdraw money and get them in game. So i need understand how to create php scripts?

withdrawMoneyUid = data;

What id i need to assign here? i mean in php file withdraw.php what i have to return? i don't ask to create all php script, just tell my what principe it works, how to give in game player money?
Reply
#2

First you have to understand how all of this works and what is frontend and backend term used for. Once you understand the basic structure of it you can create these types of systems very easily.

This will help you understand things :

My paint skills are not the best :/

To interact from frontend -> backend:
It is generally done by passing the info through GET or POST method using javascript(generally done by using ajax method provided in jQuery lib of javascript).

Backend -> Frontend:
When frontend makes a request to backend the backend returns info by printing it in output(example by echo'ing in php). Now generally we use JSON object to pass the info like this. How to use this? Its simple like this :
PHP код:
<?php
//backend part
$info = array('userid' => 1'name' => "username"'cash' => 5000);
echo 
json_encode($info);
?>
Now when you receive it in frontend(in javascript) you can use $.parseJSON() method to again convert it into array from and use it as you desire.

Backend does changes in db and same changes are reflected in server as they share same db.
Reply
#3

I know how to get parameters sending post method, but i ask i don't understand

withdrawMoneyUid = data;

What data should i generate in php file to put here?

And using socket, how to send from php file to sa-mp server request?
Reply
#4

Read the Backend -> Frontend: part i wrote, echo encoded string and decode in javascript.
Since you don't know how what to put in php that means the code you gave is not yours. So write your own code its better this way you won't learn it.

And for socket question, see this : http://forum.sa-mp.com/showthread.ph...70#post1800970
Reply
#5

But there example send from sa-mp server to PHP, how to from PHP to sa-mp server?
Reply
#6

Quote:
Originally Posted by MerryDeer
Посмотреть сообщение
But there example send from sa-mp server to PHP, how to from PHP to sa-mp server?
In the example drawing, you'd be going front-end (Browser), to backend (PHP), to database...

You'd do nothing to the server as they shouldn't be on when you use this. If they are on when you use this then you need the SAMP server to check for a flag variable on the database to update the money on the players stats.


Which in this scenario that's been painted, you could use socket to do the flag variable to trigger the update, removing the need for a timer checking the database for the update.


With this "feature" though of being able to withdraw things on PHP, it's highly likely that if you withdrew from the webpage, and spent cash ingame, at the same moment, that you'd get free cash, unless it threw the account into "overdraft".
Reply
#7

So can show my how using socket from php file call to sa-mp server?
Reply
#8

Quote:
Originally Posted by MerryDeer
Посмотреть сообщение
So can show my how using socket from php file call to sa-mp server?
The link I gave you has both way communication, did you even read the script?
The socket_write() function being used in php in that code is sending the info to sa-mp server.
Reply
#9

But it mean every can call scripts in my server if use socket_write it's not safe? i use socket_bind writing my server IP and port but i always get it's invalid and can't by binded.. So i ask how to write all socket send right
Reply
#10

UP TOPIC
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)