aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-04-23 17:16:42 +0200
committerpiernov <piernov@piernov.org>2016-04-23 17:16:42 +0200
commit198eaff1fb3469e27318592c4b592e2f099f41a1 (patch)
treee3a8eb740d03ea32ab70648af6f69a692d61aa0e
parent446ac1001ec02bd55cd73cf6906d2681bd9e7b79 (diff)
downloadcandybox-198eaff1fb3469e27318592c4b592e2f099f41a1.tar.gz
candybox-198eaff1fb3469e27318592c4b592e2f099f41a1.tar.bz2
candybox-198eaff1fb3469e27318592c4b592e2f099f41a1.tar.xz
candybox-198eaff1fb3469e27318592c4b592e2f099f41a1.zip
Fix Mine setup/update
-rw-r--r--inc/mine.inc9
-rw-r--r--js/craftmine.js17
2 files changed, 15 insertions, 11 deletions
diff --git a/inc/mine.inc b/inc/mine.inc
index 76c0055..aea04ad 100644
--- a/inc/mine.inc
+++ b/inc/mine.inc
@@ -5,13 +5,14 @@ function initCraftMine() {
}
function withdrawMine() {
- $mine = $_SESSION["mine"];
- $_SESSION["mine"]["gold"] += $mine["mine"];
- $_SESSION["mine"]["mine"] = 0;
+ $amount = intval($_POST["amount"]);
+ if($amount == 0) return;
+ $_SESSION["mine"]["gold"] += $amount;
+ echo $_SESSION["mine"]["gold"];
}
function sendMine() {
- if(empty($_SESSION["mine"])) initMine();
+ if(empty($_SESSION["mine"])) initCraftMine();
$mine = $_SESSION["mine"];
echo $mine["gold"];
}
diff --git a/js/craftmine.js b/js/craftmine.js
index 6cd2065..bbb1074 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -18,23 +18,26 @@ function sendRequest(url, params, callback) {
}
-function updateData(t) {
- document.getElementById(t).innerHTML = data[t];
+function updateData() {
+ for (var i = 0; i < arguments.length; i++) {
+ document.getElementById(arguments[i]).innerHTML = data[arguments[i]];
+ }
}
function withdrawMine() {
- sendRequest("craftmine.php", "op=withdrawMine", function() {
- data.gold += parseInt(data.mine);
+ sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) {
+ var gold = parseInt(xhr.responseText); // Server's response is a string
+ if(isNaN(gold)) return;
+ data.gold = gold;
data.mine = 0;
- updateData("gold");
- updateData("mine");
+ updateData("gold", "mine");
})
}
function initCraftMine() {
sendRequest("craftmine.php", "op=getCraftMine", function(xhr) {
var ret = xhr.responseText;
- data.gold = ret;
+ data.gold = parseInt(ret); // Server's response is a string
updateData("gold");
})
}