just a quick uncomment cause some just run and wonder why it dose nothing
[travianx.git] / rewards.php
blobfd3b83b50366ec716035946d63371374651f6ab7
1 <?php
2 // +---------------------------------------------+
3 // | TravianX Super redwards Callback script |
4 // +---------------------------------------------+
5 // | |
6 // +---------------------------------------------+
7 // | Copyright Advocaite 2011-2015 |
8 // +---------------------------------------------+
9 include("GameEngine/config.php");
12 $con = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error());
13 mysql_select_db(SQL_DB, $con) or die(mysql_error());
15 $SECRET = "aa5b4f13522971f9ebd52e32f6d2f40d"; ///this is you apps secret key get this from app info
16 $snuid = $_REQUEST['uid']; // this grabs the snuid from the url
17 $currency = $_REQUEST['new']; // this grabs amount of points to award user
18 $total= $_REQUEST['total']; // this grabs total points super rewards has ever sent user
19 $offerwallID = $_REQUEST['oid'];// this grabs the offer walls offer ID
20 $transactionID = $_REQUEST['id'];//this grabs the taransaction id from super rewards
21 $sidverify = $_REQUEST['sig']; // this grabs the hashed info for you to authenticate with
23 // make a hash of our own to verify authenicc transaction
24 $sig = md5($_REQUEST['id'] . ':' . $_REQUEST['new'] . ':' . $_REQUEST['uid'] . ':' . $SECRET);
26 //here we are gonna count the total points loged each time user has recived points
27 $sql = "SELECT SUM(`points`) as `DeadWeight` FROM `".TB_PREFIX."sr_log` WHERE `userID`='$snuid'";
29 if( !($result = mysql_query($sql)) )
31 die('Failed to query database. srlogs.');
34 $row = mysql_fetch_array($result);
35 $DeadWeight = $row['DeadWeight'];
39 // You may want to add other checks to ensure that the user exists in your system
41 //Check if hashed info is same as hashed info from superrewards if not do nothing.
42 if ($sidverify == $sig)
44 //Insert Super Rewards transaction info into your database
45 mysql_query("INSERT INTO ".TB_PREFIX."sr_log SET points=$currency,total=$total,oid=$offerwallID,userID=$snuid, transID=$transactionID");
46 //Check if the total amount of points awarded to users is less then or the same as total from super rewards
47 //This will make sure you dont give more then you should.
48 if ($DeadWeight <= $total)
50 //If all is good Update the user with there points from the url request.
51 mysql_query("UPDATE ".TB_PREFIX."users SET gold=gold+$currency WHERE id=$snuid");
53 echo "1";
54 }else{
55 echo "0";