diff --git a/chunkymap-cronjob b/chunkymap-cronjob index 5399860..12d62ec 100644 --- a/chunkymap-cronjob +++ b/chunkymap-cronjob @@ -1,4 +1,4 @@ #!/bin/sh # NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root -#python /home/owner/minetest/utils/chunkymap-regen.py +#python /home/owner/minetest/util/chunkymap-regen.py flock -n /var/run/chunkymap-regen.lockfile -c /home/owner/minetest/util/chunkymap-regen.sh \ No newline at end of file diff --git a/chunkymap-regen.py b/chunkymap-regen.py index 27ec4cc..7f10e03 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -114,8 +114,26 @@ def get_dict_from_conf_file(path,assignment_operator="="): ins.close() return results -if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): +def deny_http_access(dir_path): + htaccess_name = ".htaccess" + htaccess_path = os.path.join(dir_path, htaccess_name) + outs = open(htaccess_path) + outs.write("IndexIgnore *"+"\n") + outs.write(""+"\n") + outs.write("order allow,deny"+"\n") + outs.write("deny from all"+"\n") + outs.write(""+"\n") + outs.write(""+"\n") + outs.write("order allow,deny"+"\n") + outs.write("deny from all"+"\n") + outs.write(""+"\n") + outs.close() + + +if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): + + chunkymap_data_path=os.path.join(website_root,"chunkymapdata") yaml_name = "generated.yml" yaml_path = os.path.join(chunkymap_data_path, yaml_name) @@ -123,6 +141,14 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): os.mkdir(chunkymap_data_path) chunkymap_players_name = "players" chunkymap_players_path = os.path.join(chunkymap_data_path, chunkymap_players_name) + + htaccess_path = os.path.join(chunkymap_data_path,".htaccess") + if not os.path.isfile(htaccess_path): + deny_http_access(chunkymap_data_path) + htaccess_path = os.path.join(chunkymap_players_path,".htaccess") + if not os.path.isfile(htaccess_path): + deny_http_access(chunkymap_players_path) + if not os.path.isdir(chunkymap_players_path): os.mkdir(chunkymap_players_path) players_path = os.path.join(world_path, "players") @@ -263,6 +289,7 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): print "Could not finish deleting '"+dest_png_path+"'" try: os.rename(png_path, dest_png_path) + print("(moved to '"+dest_png_path+"')") except: print "Could not finish moving '"+png_path+"' to '"+dest_png_path+"'" try: @@ -270,6 +297,7 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): os.remove(dest_mapper_out_path) if is_save_output_ok: os.rename(mapper_out_path, dest_mapper_out_path) + print("(moved to '"+dest_mapper_out_path+"')") else: if os.path.isfile(mapper_out_path): os.remove(mapper_out_path) @@ -305,6 +333,5 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): outs.write("total_generated_count:"+str(total_generated_count) + "\n") outs.close() - else: print "failed since this folder must contain colors.txt and minetestmapper-numpy.py" diff --git a/chunkymap-regen.sh b/chunkymap-regen.sh index 3cd0727..142a138 100644 --- a/chunkymap-regen.sh +++ b/chunkymap-regen.sh @@ -1,3 +1,3 @@ #!/bin/sh # NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root -python /home/owner/minetest/utils/chunkymap-regen.py \ No newline at end of file +python /home/owner/minetest/util/chunkymap-regen.py \ No newline at end of file diff --git a/chunkymap.php b/chunkymap.php index 7d2c7cf..3ac5967 100644 --- a/chunkymap.php +++ b/chunkymap.php @@ -50,6 +50,19 @@ function endsWith($haystack, $needle) { return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false); } +function is_int($val) { + $result = true; + $int_chars="0123456789-"; + for ($i=0; $i$chunkx_max) { + $chunkx_max=(int)$x; + } + if ($z<$chunkz_min) { + $chunkz_min=(int)$z; + } + if ($z>$chunkz_max) { + $chunkz_max=(int)$z; + } + } + else { + echo "misnamed chunk tile image '$file' had coordinates ".$x.",".$z." for x,z."; + } + } + } + } + } + } + } + $x = $chunkx_min; + $z = $chunkz_min; + $x_count = $chunkx_max - $chunkx_min; + $z_count = $chunkz_max - $chunkz_min; echo ""; - while ($z <= $map_dict["chunkz_max"]) { + while ($z <= $chunkz_max) { echo " "; - while ($x <= $map_dict["chunkx_max"]) { + while ($x <= $chunkx_max) { echo "
"; $chunk_luid = "x".$x."z".$z; $chunk_img_name = $x_opener.$x.$z_opener.$z."$dot_and_ext"; @@ -84,28 +147,5 @@ function echo_chunkymap_table($center_x, $center_z, $zoom_min_1_max_100) { $z++; } echo "
"; - //NOTE: no need to detect range since using $map_dict - /* - $x_max = 0; - $x_min = 0; - $z_min = 0; - $z_max = 0; - if ($handle = opendir($chunkymapdata_path)) { - while (false !== ($file = readdir($handle))) { - if (substr($file, 0, 1) != ".") { - $file_lower = strtolower($file); - if (endsWith($file_lower, $dot_and_ext) and startsWith($file_lower, $x_opener)) { - $z_opener_index = strpos($file_lower, $z_opener, strlen($x_opener)); - if ($z_opener_index !== false) { - $x_len = $z_opener_index - strlen($x_opener); - $z_len = strlen($file_lower) - strlen($x_opener) - $x_len - strlen($z_opener) - $dot_and_ext; - $x = substr($file_lower, strlen($x_opener), $x_len); - $z = substr($file_lower, $z_opener_index + strlen($z_opener), $z_len); - } - } - } - } - } - */ } ?> \ No newline at end of file