rc3/maps/ir/cellar/01/01.php

38 lines
1.1 KiB
PHP
Raw Normal View History

2021-02-15 19:14:50 +00:00
<?php
# Turn off switch
$state = json_decode(file_get_contents("state.json"), true);
2021-02-16 03:51:02 +00:00
$state["switch_open"] = 0;
2021-02-15 19:14:50 +00:00
file_put_contents("state.json", json_encode($state));
# Create unique copy of the complete level
$sub = uniqid();
mkdir($sub);
foreach (glob("*.*") as $f)
copy($f, $sub."/".$f);
copy(".htaccess", $sub."/.htaccess");
2021-02-16 03:51:02 +00:00
# Patch paths of the copied maps
$data = file_get_contents("$sub"."/room_open.json");
2021-02-15 19:14:50 +00:00
$data = str_replace("..\/..", "..\/..\/..", $data);
2021-02-16 03:51:02 +00:00
file_put_contents("$sub"."/room_open.json", $data);
2021-02-15 19:14:50 +00:00
2021-02-16 03:51:02 +00:00
$data = file_get_contents("$sub"."/room_closed.json");
2021-02-15 19:14:50 +00:00
$data = str_replace("..\/..", "..\/..\/..", $data);
2021-02-16 03:51:02 +00:00
file_put_contents("$sub"."/room_closed.json", $data);
2021-02-15 19:14:50 +00:00
# Load current level and patch exits to target the copy
2021-02-16 03:51:02 +00:00
$data = file_get_contents("room_open.json");
$data = str_replace("room.php#", "$sub"."/"."room.php#", $data);
2021-02-15 19:14:50 +00:00
2021-02-16 03:22:04 +00:00
// Patch php filenames with timestamps to defeat cache
// destination.php --> destination.number.php
$tstamp = round(microtime(true)*100); # 0.01 sec resolution
$data = str_replace(".php", ".".$tstamp.".php", $data);
2021-02-15 19:14:50 +00:00
header('Content-type: application/json');
echo($data);
exit;
?>