From 244b59ea90bbef6f2c740031261abc7400a012ff Mon Sep 17 00:00:00 2001 From: Lars Bleckwenn Date: Thu, 18 Jan 2018 15:59:00 +0100 Subject: [PATCH] =?UTF-8?q?loadConfig.php=20=C3=BCberarbeitet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redundanten Programmcode entfernt. Neues Dateiformat für die Karteninformationen. --- config/goldcrestValley/map.cfg | 26 ++++ config/goldcrestValley/map.txt | 9 -- .../FS17_Saatgut_Duenger_Lager_placeable.xml | 0 .../{placeables => mods}/HayLoftPlaceable.xml | 0 .../Paletten_Fabrik.xml.disabled | 0 config/{placeables => mods}/README.md | 0 .../Saat_Prod.xml.disabled | 0 .../aaa_WEINPACKohneTipping_placeable.xml | 0 config/mods/vehicles.xml | 29 +++++ config/nfmarsch29/map.cfg | 26 ++++ config/nfmarsch30/map.cfg | 26 ++++ config/nfmarsch30/map.txt | 9 -- config/nfmarsch4f13/map.cfg | 26 ++++ config/nfmarsch4f13/map.txt | 9 -- config/sosnovka/map.cfg | 26 ++++ config/sosnovka/map.txt | 9 -- config/tanneberg20/map.cfg | 26 ++++ config/tanneberg20/map.txt | 9 -- config/vehicles.conf | 31 ----- include/functions.php | 68 ++++++++++ include/loadConfig.php | 120 ++++-------------- 21 files changed, 278 insertions(+), 171 deletions(-) create mode 100644 config/goldcrestValley/map.cfg delete mode 100755 config/goldcrestValley/map.txt rename config/{placeables => mods}/FS17_Saatgut_Duenger_Lager_placeable.xml (100%) rename config/{placeables => mods}/HayLoftPlaceable.xml (100%) rename config/{placeables => mods}/Paletten_Fabrik.xml.disabled (100%) rename config/{placeables => mods}/README.md (100%) rename config/{placeables => mods}/Saat_Prod.xml.disabled (100%) rename config/{placeables => mods}/aaa_WEINPACKohneTipping_placeable.xml (100%) create mode 100644 config/mods/vehicles.xml create mode 100644 config/nfmarsch29/map.cfg create mode 100644 config/nfmarsch30/map.cfg delete mode 100755 config/nfmarsch30/map.txt create mode 100644 config/nfmarsch4f13/map.cfg delete mode 100755 config/nfmarsch4f13/map.txt create mode 100644 config/sosnovka/map.cfg delete mode 100755 config/sosnovka/map.txt create mode 100644 config/tanneberg20/map.cfg delete mode 100755 config/tanneberg20/map.txt delete mode 100755 config/vehicles.conf diff --git a/config/goldcrestValley/map.cfg b/config/goldcrestValley/map.cfg new file mode 100644 index 0000000..587453f --- /dev/null +++ b/config/goldcrestValley/map.cfg @@ -0,0 +1,26 @@ +// Full map name +Name=Goldcrest Valley + +// Short map name (for e.g. the navbar) +Short=Goldcrest Valley + +// Version of the map +Version= + +// Download link of the map +Link=https://giants-software.com/ + +// Map creator / copyright +Copyright=Copyright 2017 GIANTS Software GmbH + +// Map size (standard: 2048; 4x maps: 4096) +Size=2048 + +// Config creator / copyright +configBy=John Hawk + +// Version of the map config +configVersion=1.0 + +// Config format (old = php; new = xml) +configFormat=php diff --git a/config/goldcrestValley/map.txt b/config/goldcrestValley/map.txt deleted file mode 100755 index eaee608..0000000 --- a/config/goldcrestValley/map.txt +++ /dev/null @@ -1,9 +0,0 @@ -Goldcrest Valley -Goldcrest Valley - -https://giants-software.com/ -Copyright 2017 GIANTS Software GmbH -2048 -John Hawk -1.0 -php diff --git a/config/placeables/FS17_Saatgut_Duenger_Lager_placeable.xml b/config/mods/FS17_Saatgut_Duenger_Lager_placeable.xml similarity index 100% rename from config/placeables/FS17_Saatgut_Duenger_Lager_placeable.xml rename to config/mods/FS17_Saatgut_Duenger_Lager_placeable.xml diff --git a/config/placeables/HayLoftPlaceable.xml b/config/mods/HayLoftPlaceable.xml similarity index 100% rename from config/placeables/HayLoftPlaceable.xml rename to config/mods/HayLoftPlaceable.xml diff --git a/config/placeables/Paletten_Fabrik.xml.disabled b/config/mods/Paletten_Fabrik.xml.disabled similarity index 100% rename from config/placeables/Paletten_Fabrik.xml.disabled rename to config/mods/Paletten_Fabrik.xml.disabled diff --git a/config/placeables/README.md b/config/mods/README.md similarity index 100% rename from config/placeables/README.md rename to config/mods/README.md diff --git a/config/placeables/Saat_Prod.xml.disabled b/config/mods/Saat_Prod.xml.disabled similarity index 100% rename from config/placeables/Saat_Prod.xml.disabled rename to config/mods/Saat_Prod.xml.disabled diff --git a/config/placeables/aaa_WEINPACKohneTipping_placeable.xml b/config/mods/aaa_WEINPACKohneTipping_placeable.xml similarity index 100% rename from config/placeables/aaa_WEINPACKohneTipping_placeable.xml rename to config/mods/aaa_WEINPACKohneTipping_placeable.xml diff --git a/config/mods/vehicles.xml b/config/mods/vehicles.xml new file mode 100644 index 0000000..e328d41 --- /dev/null +++ b/config/mods/vehicles.xml @@ -0,0 +1,29 @@ + + + + + + Universal Sattelauflieger + Universal Sattelauflieger + Universal Sattelauflieger + + + + Bandit SB 30/60 + Bandit SB 30/60 + Bandit SB 30/60 + + + + SA T + SA T + SA T + + + + Lexion + Lexion + Lexion + + + diff --git a/config/nfmarsch29/map.cfg b/config/nfmarsch29/map.cfg new file mode 100644 index 0000000..2253e7e --- /dev/null +++ b/config/nfmarsch29/map.cfg @@ -0,0 +1,26 @@ +// Full map name +Name=Nordfriesische Marsch + +// Short map name (for e.g. the navbar) +Short=NF Marsch + +// Version of the map +Version=2.9 + +// Download link of the map +Link=https://www.fedaction-letsplay.de + +// Map creator / copyright +Copyright=Copyright dani1803 / FedActionLetsPlay + +// Map size (standard: 2048; 4x maps: 4096) +Size=2048 + +// Config creator / copyright +configBy=John Hawk + +// Version of the map config +configVersion=1.0 + +// Config format (old = php; new = xml) +configFormat=php diff --git a/config/nfmarsch30/map.cfg b/config/nfmarsch30/map.cfg new file mode 100644 index 0000000..d5688ac --- /dev/null +++ b/config/nfmarsch30/map.cfg @@ -0,0 +1,26 @@ +// Full map name +Name=Nordfriesische Marsch + +// Short map name (for e.g. the navbar) +Short=NF Marsch + +// Version of the map +Version=3.0 + +// Download link of the map +Link=https://www.fedaction-letsplay.de + +// Map creator / copyright +Copyright=Copyright dani1803 / FedActionLetsPlay + +// Map size (standard: 2048; 4x maps: 4096) +Size=2048 + +// Config creator / copyright +configBy=John Hawk + +// Version of the map config +configVersion=1.0 + +// Config format (old = php; new = xml) +configFormat=php diff --git a/config/nfmarsch30/map.txt b/config/nfmarsch30/map.txt deleted file mode 100755 index c327837..0000000 --- a/config/nfmarsch30/map.txt +++ /dev/null @@ -1,9 +0,0 @@ -Nordfriesische Marsch -NF Marsch -3.0 -https://www.fedaction-letsplay.de -Copyright dani1803 / FedActionLetsPlay -2048 -John Hawk -1.0 -php diff --git a/config/nfmarsch4f13/map.cfg b/config/nfmarsch4f13/map.cfg new file mode 100644 index 0000000..6b2851b --- /dev/null +++ b/config/nfmarsch4f13/map.cfg @@ -0,0 +1,26 @@ +// Full map name +Name=Nordfriesische Marsch + +// Short map name (for e.g. the navbar) +Short=NF Marsch + +// Version of the map +Version=4fach 1.3 + +// Download link of the map +Link=https://www.fedaction-letsplay.de + +// Map creator / copyright +Copyright=Copyright dani1803 / FedActionLetsPlay + +// Map size (standard: 2048; 4x maps: 4096) +Size=4096 + +// Config creator / copyright +configBy=alex83we, John Hawk + +// Version of the map config +configVersion=1.0 + +// Config format (old = php; new = xml) +configFormat=xml diff --git a/config/nfmarsch4f13/map.txt b/config/nfmarsch4f13/map.txt deleted file mode 100755 index 958469a..0000000 --- a/config/nfmarsch4f13/map.txt +++ /dev/null @@ -1,9 +0,0 @@ -Nordfriesische Marsch -NF Marsch -4fach 1.3 -https://www.fedaction-letsplay.de -Copyright dani1803 / FedActionLetsPlay -4096 -alex83we, John Hawk -1.0 -xml diff --git a/config/sosnovka/map.cfg b/config/sosnovka/map.cfg new file mode 100644 index 0000000..2df4c67 --- /dev/null +++ b/config/sosnovka/map.cfg @@ -0,0 +1,26 @@ +// Full map name +Name=Sosnovka + +// Short map name (for e.g. the navbar) +Short=Sosnovka + +// Version of the map +Version= + +// Download link of the map +Link=https://giants-software.com/ + +// Map creator / copyright +Copyright=Copyright 2017 GIANTS Software GmbH + +// Map size (standard: 2048; 4x maps: 4096) +Size=2048 + +// Config creator / copyright +configBy=John Hawk + +// Version of the map config +configVersion=1.0 + +// Config format (old = php; new = xml) +configFormat=php diff --git a/config/sosnovka/map.txt b/config/sosnovka/map.txt deleted file mode 100755 index 38be493..0000000 --- a/config/sosnovka/map.txt +++ /dev/null @@ -1,9 +0,0 @@ -Sosnovka -Sosnovka - -https://giants-software.com/ -Copyright 2017 GIANTS Software GmbH -2048 -John Hawk -1.0 -php diff --git a/config/tanneberg20/map.cfg b/config/tanneberg20/map.cfg new file mode 100644 index 0000000..2125deb --- /dev/null +++ b/config/tanneberg20/map.cfg @@ -0,0 +1,26 @@ +// Full map name +Name=Tanneberg + +// Short map name (for e.g. the navbar) +Short=Tanneberg + +// Version of the map +Version=2.0 + +// Download link of the map +Link=https://www.modhoster.de/mods/tanneberg-fs17 + +// Map creator / copyright +Copyright=Copyright ruffrider + +// Map size (standard: 2048; 4x maps: 4096) +Size=2048 + +// Config creator / copyright +configBy=John Hawk + +// Version of the map config +configVersion=1.0 + +// Config format (old = php; new = xml) +configFormat=php diff --git a/config/tanneberg20/map.txt b/config/tanneberg20/map.txt deleted file mode 100755 index 4e0ec4a..0000000 --- a/config/tanneberg20/map.txt +++ /dev/null @@ -1,9 +0,0 @@ -Tanneberg -Tanneberg -2.0 -https://www.modhoster.de/mods/tanneberg-fs17 -Copyright ruffrider -2048 -John Hawk -1.0 -php diff --git a/config/vehicles.conf b/config/vehicles.conf deleted file mode 100755 index 46df347..0000000 --- a/config/vehicles.conf +++ /dev/null @@ -1,31 +0,0 @@ -//////////////////////////////////////////////////////////// -/// Farming Simulator 17 -//////////////////////////////////////////////////////////// -gp3P1006NT=3P1006NT -kroneTX560D=TX 560 D -newHollandRollBelt150=Roll-Belt 150 -newHollandBB1290=BigBaler 1290 -caseIH1660=1660 Axial-Flow -joskinAquaTrans7300=AQUATRANS 7300 S -krampeSB3060=Bandit SB 30/60 -horschPronto9DC=##horschPronto9DC## -horschMaestro12SW=##horschMaestro12SW## -amazoneCondor15001=##amazoneCondor15001## -lizardBeltSystem=##lizardBeltSystem## -grimmeSL8022=##grimmeSL8022## - -//////////////////////////////////////////////////////////// -/// Mods -//////////////////////////////////////////////////////////// - -//FS17_kotteUniversalPack -kotteUniSemi=Universal Sattelauflieger - -//krampeSB3060_Mod -krampeSB3060_Mod=Bandit SB 30/60 - -//FortunaPack -SA_T=SA T - -//Claas -Lexion=Lexion \ No newline at end of file diff --git a/include/functions.php b/include/functions.php index 850d954..08d9a07 100755 --- a/include/functions.php +++ b/include/functions.php @@ -70,6 +70,53 @@ function addFillType($i3dName, $fillLevel, $fillMax, $prodPerHour, $factor, $sta 'state' => $state ); } + +// Load XML configurations files +function loadXMLMapConfig($directory, $language) { + $objects = $translations = array (); + foreach ( glob ( "./config/$directory/*.xml" ) as $filename ) { + $object = simplexml_load_file ( $filename ); + if (isset ( $object->item )) { + foreach ( $object->item as $item ) { + $className = strval ( $item ['name'] ); + $objects = array_merge ( $objects, array ( + $className => array () + ) ); + foreach ( $item->attributes () as $attribute => $value ) { + if ($attribute != 'filename') { + $objects [$className] [$attribute] = get_bool ( $value ); + } + } + foreach ( $item->children () as $childName => $childData ) { + if (empty ( $objects [$className] [$childName] ) || ! is_array ( $objects [$className] [$childName] )) { + $objects [$className] [$childName] = array (); + } + $fillType = strval ( $childData ['name'] ); + $objects [$className] [$childName] [$fillType] = array (); + foreach ( $childData->attributes () as $attribute => $value ) { + if ($attribute != 'name') { + $objects [$className] [$childName] [$fillType] [$attribute] = get_bool ( $value ); + } + } + } + } + } + if (isset ( $object->l10n )) { + foreach ( $object->l10n->text as $text ) { + $key = strval ( $text ['name'] ); + $value = strval ( $text->$language ); + $translations = array_merge ( $translations, array ( + $key => $value + ) ); + } + } + } + return array ( + $objects, + $translations + ); +} + // convert values while reading xml files function get_bool($value) { $value = strval ( $value ); @@ -86,6 +133,27 @@ function get_bool($value) { return $value; } +// Load CFG configurations files +function loadCFGfiles ($readFile) { + $returnArray = array (); + if (file_exists ( $readFile )) { + $entries = file ( $readFile ); + foreach ( $entries as $row ) { + if (substr ( ltrim ( $row ), 0, 2 ) == '//' || trim ( $row ) == '') { // ignore comments and emtpty rows + continue; + } + $keyValuePair = explode ( '=', $row ); + $key = trim ( $keyValuePair [0] ); + $value = $keyValuePair [1]; + if (! empty ( $key )) { + $returnArray [$key] = chop ( $value ); + } + } + return $returnArray; + } + return false; +} + // Karten laden function getMaps() { $maps = array (); diff --git a/include/loadConfig.php b/include/loadConfig.php index c01acff..830bd7e 100755 --- a/include/loadConfig.php +++ b/include/loadConfig.php @@ -21,15 +21,13 @@ if (! defined ( 'IN_NFMWS' )) { exit (); } -// Serverkonfiguration laden - wenn nicht vorhanden Instalation starten + +// Load server configuration - start install if it does not exists $configFile = './config/server.conf'; if (file_exists ( $configFile )) { $server = file ( $configFile ); $serverConfig = unserialize ( $server [0] ); list ( $dSrvIp, $dSrvPort, $dSrvCode, $savegame, $isDediServer, $mapPath ) = $serverConfig; - if ($mapPath == '') { - $mapPath = 'nfmarsch29'; - } $smarty->assign ( 'isDediServer', $isDediServer ); } else { define ( 'IN_INSTALL', true ); @@ -54,25 +52,24 @@ } $stylesDir->close (); -// Kartendetails laden -list ( $mapName, $mapShort, $mapVersion, $mapLink, $mapCopyright, $mapSize, $configBy, $configVersion, $configFormat ) = file ( "./config/$mapPath/map.txt" ); - -$map = array ( - 'Name' => $mapName, - 'Path' => $mapPath, - 'Short' => $mapShort, - 'Version' => $mapVersion, - 'Link' => $mapLink, - 'Copyright' => $mapCopyright, - 'Size' => $mapSize, - 'configBy' => $configBy, - 'configVersion' => $configVersion, - 'configFormat' => $configFormat -); +// Load map infomations +$map = array_merge ( array ( + 'Name' => '', + 'Path' => '', + 'Short' => '', + 'Version' => '', + 'Link' => '', + 'Copyright' => '', + 'Size' => 2048, + 'configBy' => '', + 'configVersion' => '', + 'configFormat' => 'xml' +), loadCFGfiles ( "./config/$mapPath/map.cfg" ) ); $smarty->assign ( 'map', $map ); -$userLang = $_SESSION ['language']; -if (trim($configFormat) != 'xml') { +// Load map config +$userLang = $_SESSION ['language']; +if (trim ( $map ['configFormat'] ) != 'xml') { require ("./config/$mapPath/mapconfig.php"); if (! file_exists ( "./config/$mapPath/translation/{$_SESSION ['language']}.php" )) { require ("./config/$mapPath/translation/$defaultLanguage.php"); @@ -81,80 +78,13 @@ } } else { // Kartenkonfiguration aus XML Dateien laden - $lang = $mapconfig = array (); - foreach ( glob ( "./config/$mapPath/*.xml" ) as $filename ) { - $object = simplexml_load_file ( $filename ); - if (isset ( $object->item )) { - foreach ( $object->item as $item ) { - $className = strval ( $item ['name'] ); - $mapconfig = array_merge ( $mapconfig, array ( - $className => array () - ) ); - foreach ( $item->attributes () as $attribute => $value ) { - if ($attribute != 'filename') { - $mapconfig [$className] [$attribute] = get_bool ( $value ); - } - } - foreach ( $item->children () as $childName => $childData ) { - if (empty ( $mapconfig [$className] [$childName] ) || ! is_array ( $mapconfig [$className] [$childName] )) { - $mapconfig [$className] [$childName] = array (); - } - $fillType = strval ( $childData ['name'] ); - $mapconfig [$className] [$childName] [$fillType] = array (); - foreach ( $childData->attributes () as $attribute => $value ) { - if ($attribute != 'name') { - $mapconfig [$className] [$childName] [$fillType] [$attribute] = get_bool ( $value ); - } - } - } - } - } - if (isset ( $object->l10n )) { - foreach ( $object->l10n->text as $text ) { - $key = strval ( $text ['name'] ); - $value = strval ( $text->$userLang ); - $lang = array_merge ( $lang, array ( - $key => $value - ) ); - } - } - } + $loadedConfig = loadXMLMapConfig ( $mapPath, $userLang ); + $mapconfig = $loadedConfig [0]; + $lang = $loadedConfig [1]; } -$lang = array_merge ( $lang, getVehicleNames () ); -// load installed placeables -$placeableObjects = $placeablesLang = array (); +// load installed mods +$loadedConfig = loadXMLMapConfig ( 'mods', $userLang ); +$placeableObjects = $loadedConfig [0]; +$placeablesLang = $loadedConfig [1]; -foreach ( glob ( './config/placeables/*.xml' ) as $filename ) { - $placeable = simplexml_load_file ( $filename ); - foreach ( $placeable->item as $item ) { - $className = strval ( $item ['filename'] ); - $placeableObjects = array_merge ( $placeableObjects, array ( - $className => array () - ) ); - foreach ( $item->attributes () as $attribute => $value ) { - if ($attribute != 'filename') { - $placeableObjects [$className] [$attribute] = get_bool ( $value ); - } - } - foreach ( $item->children () as $childName => $childData ) { - if (empty ( $placeableObjects [$className] [$childName] ) || ! is_array ( $placeableObjects [$className] [$childName] )) { - $placeableObjects [$className] [$childName] = array (); - } - $fillType = strval ( $childData ['name'] ); - $placeableObjects [$className] [$childName] [$fillType] = array (); - foreach ( $childData->attributes () as $attribute => $value ) { - if ($attribute != 'name') { - $placeableObjects [$className] [$childName] [$fillType] [$attribute] = get_bool ( $value ); - } - } - } - } - foreach ( $placeable->l10n->text as $text ) { - $key = strval ( $text ['name'] ); - $value = strval ( $text->$userLang ); - $placeablesLang = array_merge ( $placeablesLang, array ( - $key => $value - ) ); - } -}