aboutsummaryrefslogtreecommitdiffstats
path: root/inc/mine.inc
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-10 22:21:31 +0200
committerpiernov <piernov@piernov.org>2016-05-10 22:21:31 +0200
commit58b1893e6c820ce8810c33f09bfcc16c3e59f4eb (patch)
tree8e893d4981f3d869cbe79b985570d66cf3c42175 /inc/mine.inc
parent204e838a7794bbce0d44fc35efb367abb052d02f (diff)
downloadcandybox-58b1893e6c820ce8810c33f09bfcc16c3e59f4eb.tar.gz
candybox-58b1893e6c820ce8810c33f09bfcc16c3e59f4eb.tar.bz2
candybox-58b1893e6c820ce8810c33f09bfcc16c3e59f4eb.tar.xz
candybox-58b1893e6c820ce8810c33f09bfcc16c3e59f4eb.zip
Various fixes
Diffstat (limited to 'inc/mine.inc')
-rw-r--r--inc/mine.inc14
1 files changed, 11 insertions, 3 deletions
diff --git a/inc/mine.inc b/inc/mine.inc
index 752fc69..76dfb50 100644
--- a/inc/mine.inc
+++ b/inc/mine.inc
@@ -1,18 +1,26 @@
<?php
-function initCraftMine() {
- $_SESSION["mine"] = array("gold" => 0, "miners" => 0);
+function initMineIfNeeded() {
+ if(empty($_SESSION["mine"]))
+ $_SESSION["mine"] = array("gold" => 0);
+ else if(!array_key_exists("gold", $_SESSION["mine"]))
+ $_SESSION["mine"]["gold"] = 0;
}
function withdrawMine() {
$amount = intval($_POST["amount"]);
+ if(!empty($_SESSION["dungeon"])) {
+ sendError("cant_withdraw_in_dungeon");
+ return;
+ }
if($amount == 0) return;
+ initMineIfNeeded();
$_SESSION["mine"]["gold"] += $amount;
echo json_encode($_SESSION["mine"]["gold"]);
}
function sendMine() {
- if(empty($_SESSION["mine"])) initCraftMine();
+ initMineIfNeeded();
$mine = $_SESSION["mine"];
return $mine["gold"];
}