2 require("login-config.php");
3 error_reporting(E_ERROR | E_PARSE);
5 function get_files($path)
7 $base = explode("\n", shell_exec("ls $path 2>/dev/null"));
9 echo json_encode($base);
12 function walk_directory($path, $func)
16 $files = scandir($path);
18 foreach ($files as $filename) {
19 if ($filename[0] == ".")
22 $result = $func($filename, $path . "/" . $filename);
24 $data[$filename] = $result;
27 echo json_encode($data);
30 function check_worldname($name)
32 return preg_match("/^[a-zA-Z0-9]+$/", $name);
35 function world_exists($name)
37 return check_worldname($name) && file_exists("worlds/" . $name);
40 function get_mods($path)
42 walk_directory($path, function($modname, $modpath) {
43 $dependencies = file_get_contents($modpath . "/dependencies.txt");
47 "description" => file_get_contents($modpath . "/description.txt"),
48 "dependencies" => $dependencies ? array_values(array_filter(explode("\n", $dependencies))) : array(),
54 switch($_POST["call"]) {
64 walk_directory("worlds", function($worldname, $path) {
67 "owned" => is_loggedin() && get_username() == file_get_contents($path . "/owner.txt"),
73 get_files("textures/* game/*/textures/* mods/*/textures/*");
77 get_files("sounds/* game/*/sounds/* mods/*/sounds/*");
81 echo json_encode(is_loggedin());
91 else if (! $_POST["name"])
93 else if (! check_worldname($_POST["name"]))
96 if (! world_exists($_POST["name"]))
97 mkdir("worlds/" . $_POST["name"]);
98 else if (file_get_contents("worlds/" . $_POST["name"] . "/owner.txt") != get_username())
101 file_put_contents("worlds/" . $_POST["name"] . "/world.json", $_POST["world"]);
102 file_put_contents("worlds/" . $_POST["name"] . "/owner.txt", get_username());
106 echo shell_exec("git rev-parse --short HEAD");