aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-02 15:59:16 +0200
committerpiernov <piernov@piernov.org>2016-05-02 15:59:16 +0200
commit0b72114561a685b247922a93c576edabd4d3b09e (patch)
tree3eed636fe5c9f8a2b660cc92fa569d7a28869cbe
parentc6e05fbec675d1f60e6adb2b29d6fed4f888fb1d (diff)
downloadcandybox-0b72114561a685b247922a93c576edabd4d3b09e.tar.gz
candybox-0b72114561a685b247922a93c576edabd4d3b09e.tar.bz2
candybox-0b72114561a685b247922a93c576edabd4d3b09e.tar.xz
candybox-0b72114561a685b247922a93c576edabd4d3b09e.zip
Add ability to delete a save
Doesn't work because idk which method to use and I don't have the PHP doc right now
-rw-r--r--craftmine.php1
-rw-r--r--inc/messages.inc2
-rw-r--r--inc/savegame.inc7
-rw-r--r--js/savegame.js3
4 files changed, 13 insertions, 0 deletions
diff --git a/craftmine.php b/craftmine.php
index 28bb49d..9a5d3d7 100644
--- a/craftmine.php
+++ b/craftmine.php
@@ -51,6 +51,7 @@ switch($op) {
case "downSave": downSave(); break;
case "listSaves": listSaves(); break;
case "loadSave": loadSave(); break;
+ case "deleteSave": deleteSave(); break;
default: reportBadRequest();
}
diff --git a/inc/messages.inc b/inc/messages.inc
index 955c0a0..5574bcf 100644
--- a/inc/messages.inc
+++ b/inc/messages.inc
@@ -10,6 +10,8 @@ $messages = array(
"gamesave_ok" => "Game saved.",
"gamesave_error" => "An error occured when trying to save the game.",
"gamesave_not_found" => "Couldn't find the specified save file.",
+ "gamesave_delete_error" => "Couldn't delete the specified save file.",
+ "gamesave_delete_success" => "Game save successfully removed from server",
);
function sendMessage($type, $msg) {
diff --git a/inc/savegame.inc b/inc/savegame.inc
index 79b1dae..eb4134f 100644
--- a/inc/savegame.inc
+++ b/inc/savegame.inc
@@ -71,6 +71,13 @@ function parseSave($xml, &$table) { // Passing $table by reference
}
}
+function deleteSave() {
+ if(empty($_POST["filename"])) return;
+ $filename = $_POST["filename"];
+ if(rm_file(SAVEDIR + "/" + $filename)) sendError("gamesave_delete_failed"); // TODO: find the correct method for removing a fileā€¦
+ else sendInfo("gamesave_delete_success");
+}
+
function loadSave() {
if(empty($_POST["filename"])) return;
$xml = simplexml_load_file(SAVEDIR . "/" . $_POST["filename"]);
diff --git a/js/savegame.js b/js/savegame.js
index 438be0a..4a08f91 100644
--- a/js/savegame.js
+++ b/js/savegame.js
@@ -28,6 +28,9 @@ function downloadSave() {
}
function deleteSave() {
+ sendRequest("craftmine.php", "op=deleteSave&filename="+getCheckedSave(), function(ret) {
+ listSaves();
+ });
}
function saveGame() {