diff --git a/modules/config_games/config_servers.php b/modules/config_games/config_servers.php index 811fe5a4..08b59b90 100644 --- a/modules/config_games/config_servers.php +++ b/modules/config_games/config_servers.php @@ -30,6 +30,11 @@ function config_games_normalize_path($path) return ltrim($clean, '/'); } +function config_games_normalize_newlines($text) +{ + return preg_replace("/\\r\\n?/", "\\n", (string)$text); +} + function config_games_next_form_key(): string { static $counter = 0; @@ -199,11 +204,12 @@ function config_games_save_xml($db, $home_cfg_id, array $nodesPayload) } $hasChildren = !empty($nodeData['has_children']); if (array_key_exists('value', $nodeData)) { + $normalizedValue = config_games_normalize_newlines($nodeData['value']); while ($domNode->firstChild) { $domNode->removeChild($domNode->firstChild); } - if ($nodeData['value'] !== '') { - $domNode->appendChild($dom->createTextNode($nodeData['value'])); + if ($normalizedValue !== '') { + $domNode->appendChild($dom->createTextNode($normalizedValue)); } } elseif (!$hasChildren) { while ($domNode->firstChild) { @@ -235,6 +241,13 @@ function config_games_save_xml($db, $home_cfg_id, array $nodesPayload) if ($dom->save($config_file) === false) { return false; } + $savedContents = @file_get_contents($config_file); + if ($savedContents !== false) { + $normalizedContents = config_games_normalize_newlines($savedContents); + if ($normalizedContents !== $savedContents) { + file_put_contents($config_file, $normalizedContents); + } + } $config = read_server_config($config_file); if ($config !== FALSE) { $db->addGameCfg($config); diff --git a/modules/config_games/create.php b/modules/config_games/create.php index f4255dbf..de869d8a 100644 --- a/modules/config_games/create.php +++ b/modules/config_games/create.php @@ -160,7 +160,8 @@ function exec_ogp_module() { echo "".$myXML.""; echo "".$template.""; $myXML = "modules/config_games/server_configs/".$key_name."_".$os.$arch.".xml"; + $template = preg_replace("/\r\n?|\n/", "\n", $template); $fh = fopen($myXML, 'w') or die("No Write Permission."); fwrite($fh, $template); fclose($fh); -} \ No newline at end of file +}