From 446ac1001ec02bd55cd73cf6906d2681bd9e7b79 Mon Sep 17 00:00:00 2001
From: piernov <piernov@piernov.org>
Date: Sat, 23 Apr 2016 17:01:12 +0200
Subject: Spelling mistake: datas→data
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 js/craftmine.js | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

(limited to 'js')

diff --git a/js/craftmine.js b/js/craftmine.js
index 50d3a47..6cd2065 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -1,4 +1,4 @@
-datas = {
+data = {
 	gold: 0,
 	mine: 0,
 	miners: 1,
@@ -18,31 +18,31 @@ function sendRequest(url, params, callback) {
 }
 
 
-function updateDatas(t) {
-	document.getElementById(t).innerHTML = datas[t];
+function updateData(t) {
+	document.getElementById(t).innerHTML = data[t];
 }
 
 function withdrawMine() {
 	sendRequest("craftmine.php", "op=withdrawMine", function() {
-		datas.gold += parseInt(datas.mine);
-		datas.mine = 0;
-		updateDatas("gold");
-		updateDatas("mine");
+		data.gold += parseInt(data.mine);
+		data.mine = 0;
+		updateData("gold");
+		updateData("mine");
 	})
 }
 
 function initCraftMine() {
 	sendRequest("craftmine.php", "op=getCraftMine", function(xhr) {
 		var ret = xhr.responseText;
-		datas.gold = ret;
-		updateDatas("gold");
+		data.gold = ret;
+		updateData("gold");
 	})
 }
 
 
 function updateMine() {
-	datas.mine += (datas.miners+1);
-	updateDatas("mine");
+	data.mine += (data.miners+1);
+	updateData("mine");
 }
 
 function init() {
-- 
cgit v1.2.3-70-g09d2


From 198eaff1fb3469e27318592c4b592e2f099f41a1 Mon Sep 17 00:00:00 2001
From: piernov <piernov@piernov.org>
Date: Sat, 23 Apr 2016 17:16:42 +0200
Subject: Fix Mine setup/update

---
 inc/mine.inc    |  9 +++++----
 js/craftmine.js | 17 ++++++++++-------
 2 files changed, 15 insertions(+), 11 deletions(-)

(limited to 'js')

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");
 	})
 }
-- 
cgit v1.2.3-70-g09d2