From 1219f2570894b9fe402004bcf09d0701eda8cc48 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 2 Dec 2015 21:15:35 -0800 Subject: [PATCH] Add option to create a world from a server-side file --- minecraft/edit_world.cgi | 2 ++ minecraft/lang/en | 3 +++ minecraft/save_world.cgi | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/minecraft/edit_world.cgi b/minecraft/edit_world.cgi index bed9f12c4..bb3e37156 100755 --- a/minecraft/edit_world.cgi +++ b/minecraft/edit_world.cgi @@ -40,6 +40,8 @@ if ($in{'new'}) { } push(@opts, [ 2, $text{'world_src2'}, &ui_upload("upload") ]); + push(@opts, [ 3, $text{'world_src3'}, + &ui_filebox("file", undef, 40) ]); print &ui_table_row($text{'world_src'}, &ui_radio_table("src", 0, \@opts)); } diff --git a/minecraft/lang/en b/minecraft/lang/en index 495b5cb64..3d936f6f2 100644 --- a/minecraft/lang/en +++ b/minecraft/lang/en @@ -194,6 +194,7 @@ world_src=Source for new world world_src0=Create empty world world_src1=Clone existing world world_src2=Use uploaded ZIP file +world_src3=Use ZIP file on server world_delete=Delete World Forever world_players=Players who have connected world_err1=Failed to create world @@ -206,6 +207,8 @@ world_rusure=Are you sure you want to delete the Minecraft world $1? All map, pl world_confirm=Yes, Delete This World world_einuse=The currently active world cannot be deleted. world_eupload=No world data to upload selected +world_efile=No world data filename entered +world_efile2=World data file does not exist world_ezip=Uploaded world data does not appear to be in ZIP format world_eunzip=Failed to unzip world data : $1 world_edat=ZIP file does not contain a level.dat file diff --git a/minecraft/save_world.cgi b/minecraft/save_world.cgi index f9cc1cc10..127ca5982 100755 --- a/minecraft/save_world.cgi +++ b/minecraft/save_world.cgi @@ -52,14 +52,21 @@ if ($in{'new'}) { &execute_minecraft_command("save-on"); } } - elsif ($in{'src'} == 2) { - # From uploaded file - $in{'upload'} || &error($text{'world_eupload'}); + elsif ($in{'src'} == 2 || $in{'src'} == 3) { + # From uploaded or local file my $temp = &transname(); - my $fh = "ZIP"; - &open_tempfile($fh, ">$temp", 0, 1); - &print_tempfile($fh, $in{'upload'}); - &close_tempfile($fh); + if ($in{'src'} == 2) { + $in{'upload'} || &error($text{'world_eupload'}); + my $fh = "ZIP"; + &open_tempfile($fh, ">$temp", 0, 1); + &print_tempfile($fh, $in{'upload'}); + &close_tempfile($fh); + } + else { + $in{'file'} || &error($text{'world_efile'}); + -r $in{'file'} || &error($text{'world_efile2'}); + ©_source_dest($in{'file'}, $temp); + } my $out = &backquote_command("file ".$temp); $out =~ /Zip\s+archive/i || &error($text{'world_ezip'}); my $tempdir = &transname();