From 903c4a3285e05afbeee715b26d4c54ede74bf7e3 Mon Sep 17 00:00:00 2001 From: TravianZ Patcher Date: Wed, 3 Jun 2026 15:45:48 +0200 Subject: [PATCH] Add missing handler for admin "Create System Message" The admin panel had a "Create System Message" page (admin.php?p=sysmessage -> Admin/Templates/sysmessage.tpl) whose form posts to GameEngine/Admin/Mods/sysmessage.php, but that backend file never existed, so submitting returned a 404 (Not Found). Add the handler implementing the prepare -> confirm -> execute flow used by the template. On execute it displays a global system message to all players using the existing mechanism (writes Templates/text.tpl from text_format.tpl and sets users.ok = 1), same as the legacy sysmsg.php. %TEKST% is escaped for the PHP double-quoted string context to avoid breakage/injection. Co-Authored-By: Claude Opus 4.8 --- GameEngine/Admin/Mods/sysmessage.php | 112 +++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 GameEngine/Admin/Mods/sysmessage.php diff --git a/GameEngine/Admin/Mods/sysmessage.php b/GameEngine/Admin/Mods/sysmessage.php new file mode 100644 index 00000000..41619b75 --- /dev/null +++ b/GameEngine/Admin/Mods/sysmessage.php @@ -0,0 +1,112 @@ +' . $subject . ''; + $body .= $message; + + // %TEKST% is injected into a PHP double-quoted string inside text_format.tpl, + // so escape backslash, double-quote and $ to avoid breaking the string or + // allowing code injection. str_replace (not preg_replace) so the replacement + // is treated literally. + $safe = str_replace(['\\', '"', '$'], ['\\\\', '\\"', '\\$'], $body); + + $format = @file_get_contents($autoprefix . 'Templates/text_format.tpl'); + if ($format === false) { + die("Cannot read Templates/text_format.tpl"); + } + + $out = str_replace('%TEKST%', $safe, $format); + + if (@file_put_contents($autoprefix . 'Templates/text.tpl', $out) === false) { + die("Cannot write Templates/text.tpl (check permissions)"); + } + + // Make the message visible to every player (they will see it on next page). + $database->setUsersOk(1); + + unset($_SESSION['sys_subject'], $_SESSION['sys_message'], $_SESSION['sys_color']); + + header("Location: ../../../Admin/admin.php?p=sysmessage&done=1"); + exit; +} + +// Fallback +header("Location: ../../../Admin/admin.php?p=sysmessage"); +exit; +?>