From cd9ca9500f1b16a6e7e9ce0dd0021b3604c4db0e Mon Sep 17 00:00:00 2001 From: Stephan Messlinger Date: Tue, 16 Feb 2021 04:22:04 +0100 Subject: [PATCH] Fix Exitroom cellar/01 --- maps/ir/cellar.json | 2 +- maps/ir/cellar/01/.htaccess | 4 +-- maps/ir/cellar/01/01.json | 2 +- maps/ir/cellar/01/01.php | 6 +++- maps/ir/cellar/01/01_closed.json | 2 +- maps/ir/cellar/01/01_sub.php | 6 +++- maps/ir/cellar/01/switch.php | 5 +++ maps/ir/cellar/01/testcookie.php | 8 ----- maps/ir/cellar/01/uncache.php | 39 ---------------------- maps/ir/gmaze/.htaccess | 4 +-- maps/ir/gmaze/gmaze.php | 1 - maps/ir/gmaze/{left_old.php => left.php} | 1 - maps/ir/gmaze/{right_old.php => right.php} | 1 - maps/ir/gmaze/uncache.php | 18 +++++----- maps/ir/ir.tiled-session | 24 ++++++------- rc3_notes.md | 11 ++---- 16 files changed, 43 insertions(+), 91 deletions(-) delete mode 100644 maps/ir/cellar/01/testcookie.php delete mode 100644 maps/ir/cellar/01/uncache.php rename maps/ir/gmaze/{left_old.php => left.php} (92%) rename maps/ir/gmaze/{right_old.php => right.php} (92%) diff --git a/maps/ir/cellar.json b/maps/ir/cellar.json index e9cda77..7abe4b2 100644 --- a/maps/ir/cellar.json +++ b/maps/ir/cellar.json @@ -157,7 +157,7 @@ { "name":"exitUrl", "type":"string", - "value":"cellar\/01\/01.json#start" + "value":"cellar\/01\/01.php#start" }], "type":"tilelayer", "visible":true, diff --git a/maps/ir/cellar/01/.htaccess b/maps/ir/cellar/01/.htaccess index a5f4b18..b65be13 100644 --- a/maps/ir/cellar/01/.htaccess +++ b/maps/ir/cellar/01/.htaccess @@ -4,7 +4,5 @@ RewriteEngine On # replace name.number.php --> name.php -#RewriteRule ^(.+)\.\d+\.php$ $1.php +RewriteRule ^(.+)\.\d+\.php$ $1.php -# replace name.number.php --> uncache.php?taget=name -RewriteRule ^(.+)\.\d+\.php$ uncache.php?target=$1 \ No newline at end of file diff --git a/maps/ir/cellar/01/01.json b/maps/ir/cellar/01/01.json index 1c7b0fd..7b44058 100644 --- a/maps/ir/cellar/01/01.json +++ b/maps/ir/cellar/01/01.json @@ -229,7 +229,7 @@ { "name":"playAudio", "type":"string", - "value":"switch.mp3" + "value":"switch.php" }], "type":"tilelayer", "visible":true, diff --git a/maps/ir/cellar/01/01.php b/maps/ir/cellar/01/01.php index 8b12a75..480836d 100644 --- a/maps/ir/cellar/01/01.php +++ b/maps/ir/cellar/01/01.php @@ -28,7 +28,11 @@ file_put_contents("$sub"."/01_closed.json", $data); $data = file_get_contents("01.json"); $data = str_replace("01.php#", "$sub"."/"."01.php#", $data); -header("Expires: 0"); +// 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); + header('Content-type: application/json'); echo($data); exit; diff --git a/maps/ir/cellar/01/01_closed.json b/maps/ir/cellar/01/01_closed.json index 0903e7e..c96f4e2 100644 --- a/maps/ir/cellar/01/01_closed.json +++ b/maps/ir/cellar/01/01_closed.json @@ -229,7 +229,7 @@ { "name":"playAudio", "type":"string", - "value":"switch.mp3" + "value":"switch.php" }], "type":"tilelayer", "visible":true, diff --git a/maps/ir/cellar/01/01_sub.php b/maps/ir/cellar/01/01_sub.php index fef4e09..e7fd405 100644 --- a/maps/ir/cellar/01/01_sub.php +++ b/maps/ir/cellar/01/01_sub.php @@ -7,7 +7,11 @@ $switch = $state["switch"]; # Load open/closed level depending on switch $data = file_get_contents( $switch ? "01.json" : "01_closed.json"); -header("Expires: 0"); +// 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); + header('Content-type: application/json'); echo($data); exit; diff --git a/maps/ir/cellar/01/switch.php b/maps/ir/cellar/01/switch.php index 7bb5736..3a32779 100644 --- a/maps/ir/cellar/01/switch.php +++ b/maps/ir/cellar/01/switch.php @@ -2,5 +2,10 @@ $state = json_decode(file_get_contents("state.json"), true); $state["switch"] = 1; file_put_contents("state.json", json_encode($state)); + +# Load current level and patch exits to target the copy +$data = file_get_contents("switch.mp3"); +header('Content-type: audio/mpeg'); +echo($data); exit; ?> \ No newline at end of file diff --git a/maps/ir/cellar/01/testcookie.php b/maps/ir/cellar/01/testcookie.php deleted file mode 100644 index 1d979d4..0000000 --- a/maps/ir/cellar/01/testcookie.php +++ /dev/null @@ -1,8 +0,0 @@ - \ No newline at end of file diff --git a/maps/ir/cellar/01/uncache.php b/maps/ir/cellar/01/uncache.php deleted file mode 100644 index 0232793..0000000 --- a/maps/ir/cellar/01/uncache.php +++ /dev/null @@ -1,39 +0,0 @@ - destination.number.php#start -$tstamp = round(microtime(true)*100); # 0.01 sec resolution -$data = str_replace(".php#", ".".$tstamp.".php#", $data); // Patch php-exits to prevent caching -header("Expires: 0"); -header('Content-type: application/json'); -echo($data); -exit; -?> \ No newline at end of file diff --git a/maps/ir/gmaze/.htaccess b/maps/ir/gmaze/.htaccess index a5f4b18..b65be13 100644 --- a/maps/ir/gmaze/.htaccess +++ b/maps/ir/gmaze/.htaccess @@ -4,7 +4,5 @@ RewriteEngine On # replace name.number.php --> name.php -#RewriteRule ^(.+)\.\d+\.php$ $1.php +RewriteRule ^(.+)\.\d+\.php$ $1.php -# replace name.number.php --> uncache.php?taget=name -RewriteRule ^(.+)\.\d+\.php$ uncache.php?target=$1 \ No newline at end of file diff --git a/maps/ir/gmaze/gmaze.php b/maps/ir/gmaze/gmaze.php index 6372da3..1ce443d 100644 --- a/maps/ir/gmaze/gmaze.php +++ b/maps/ir/gmaze/gmaze.php @@ -8,7 +8,6 @@ exec("python genmaze.py ".$name); $data = file_get_contents($name); $data = str_replace(".php#", ".".$tstamp.".php#", $data); // Patch php-exits to prevent caching -header("Expires: 0"); header('Content-type: application/json'); echo($data); exit; diff --git a/maps/ir/gmaze/left_old.php b/maps/ir/gmaze/left.php similarity index 92% rename from maps/ir/gmaze/left_old.php rename to maps/ir/gmaze/left.php index 8a519ff..e2250ae 100644 --- a/maps/ir/gmaze/left_old.php +++ b/maps/ir/gmaze/left.php @@ -3,7 +3,6 @@ $tstamp = round(microtime(true)*100); // 0.01 sec resolution $data = file_get_contents('left.json'); $data = str_replace(".php#", ".".$tstamp.".php#", $data); // Patch php-exits to prevent caching -header("Expires: 0"); header('Content-type: application/json'); echo($data); exit; diff --git a/maps/ir/gmaze/right_old.php b/maps/ir/gmaze/right.php similarity index 92% rename from maps/ir/gmaze/right_old.php rename to maps/ir/gmaze/right.php index b0297f2..09d4c72 100644 --- a/maps/ir/gmaze/right_old.php +++ b/maps/ir/gmaze/right.php @@ -2,7 +2,6 @@ $data = file_get_contents('right.json'); $tstamp = round(microtime(true)*100); # 0.01 sec resolution $data = str_replace(".php#", ".".$tstamp.".php#", $data); // Patch php-exits to prevent caching -header("Expires: 0"); header('Content-type: application/json'); echo($data); exit; diff --git a/maps/ir/gmaze/uncache.php b/maps/ir/gmaze/uncache.php index 96c66a2..9bca15f 100644 --- a/maps/ir/gmaze/uncache.php +++ b/maps/ir/gmaze/uncache.php @@ -2,37 +2,37 @@ // Workadventure cache destroyer // URL rewrite rule calls us with the original filename in URL paramter "target" -if (!isset($_GET['target'])) { +if (!isset($_GET['target'])) { echo("No target"); exit; } $target = $_GET["target"]; -if (file_exists($target.".php")) -{ +if (file_exists($target.".php")) { // If a PHP file target.php exists: // Run that file and capture its output ob_start(); include $target.".php"; ob_end_flush(); } -else -{ +else { // If no PHP file target.php exists: // Load contents from target.json - if (!file_exists($target.".json")) - { + if (file_exists($target.".json")) + $data = file_get_contents($target.".json"); + else { echo($target.".json"." not found."); exit; } + } // Replace map exit names with timestamps: // destination.php#start --> destination.number.php#start $tstamp = round(microtime(true)*100); # 0.01 sec resolution $data = str_replace(".php#", ".".$tstamp.".php#", $data); // Patch php-exits to prevent caching -header("Expires: 0"); + header('Content-type: application/json'); echo($data); exit; -?> \ No newline at end of file +?> diff --git a/maps/ir/ir.tiled-session b/maps/ir/ir.tiled-session index e0ebe5f..998608f 100644 --- a/maps/ir/ir.tiled-session +++ b/maps/ir/ir.tiled-session @@ -86,10 +86,10 @@ }, "cellar.json": { "scale": 1.5, - "selectedLayer": 3, + "selectedLayer": 9, "viewCenter": { - "x": 2047.6666666666665, - "y": 127.66666666666666 + "x": 3826.333333333333, + "y": 127.66666666666669 } }, "cellar.json#cija": { @@ -100,7 +100,7 @@ }, "cellar/01/01.json": { "scale": 1, - "selectedLayer": 0, + "selectedLayer": 10, "viewCenter": { "x": 553.5, "y": 550.5 @@ -111,7 +111,7 @@ }, "cellar/01/01_closed.json": { "scale": 0.8465435606060606, - "selectedLayer": 0, + "selectedLayer": 12, "viewCenter": { "x": 527.4388947927736, "y": 401.0425639017842 @@ -190,7 +190,7 @@ "selectedLayer": 6, "viewCenter": { "x": 511.0390289839908, - "y": 527.0607931359214 + "y": 527.61326776185 } }, "gmaze/gmaze.json#cija": { @@ -245,8 +245,8 @@ "scale": 1.5, "selectedLayer": 6, "viewCenter": { - "x": 207.66666666666663, - "y": 208 + "x": 207.66666666666666, + "y": 208.3333333333333 } }, "gmaze/right.json#cija": { @@ -435,8 +435,8 @@ "scale": 0.33, "selectedLayer": 10, "viewCenter": { - "x": 883.3333333333335, - "y": 883.3333333333333 + "x": 1022.7272727272727, + "y": 512.121212121212 } }, "lobby.json#mapUtilities": { @@ -780,8 +780,8 @@ "scale": 1, "selectedLayer": 8, "viewCenter": { - "x": 288.5, - "y": 288.5 + "x": 287.5, + "y": 288 } }, "warp.json#ir_logo_set": { diff --git a/rc3_notes.md b/rc3_notes.md index 0d9e445..1fe8fc7 100644 --- a/rc3_notes.md +++ b/rc3_notes.md @@ -162,21 +162,14 @@ * Workaround: Dynamische einamalige Dateinamen für Maps * Nachteil: Jeder Spieler bekommt eine andere Map, kein Multiplayer mehr * Funktioniert nur für Maps, nicht für Audio-Events - * Implementierung A: + * Implementierung: (1) Wenn eine Karte map.php aufgerufen wird: * Lade map.json * Ersetze alle Exit-URLs der Form dest.php#start --> dest.timestamp.php#start (dest.json wird so gelassen, damit man wieder in Multiplayer-Maps zurück kann). (2) URL-Rewrite rule via .htaccess: Entferne timestamp RewriteRule ^(.+)\.\d+\.php$ $1.php - * Implementierung B (timestamp-patching ausgelagert in eigenes file): - (1) URL-Rewrite: Entferne timestamp und übergebe Mapnamen an uncache.php via URL-Parameter - RewriteRule ^(.+)\.\d+\.php$ uncache.php?target=$1 - (2) In uncache.php: - * Wenn es target.php gibt, dann rufe diese auf und fange ihren output ab. - * sonst lade target.json - * Patch Exit-URLS mit timestamp. - + * Cache deaktivieren Engineseitig: * Karten beim betreten neu laden