diff --git a/Dockerfile b/Dockerfile index 3cc1eda..9c5deaa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,6 +76,13 @@ RUN unzip /var/www/html/remoteCP_v4.0.3.5.zip -d /var/www/html \ COPY assets/config/remotecp/plugins/CustomPoints/index.php /var/www/html/remotecp/plugins/CustomPoints/index.php RUN chown www-data:www-data /var/www/html/remotecp/plugins/CustomPoints/index.php +# Fix PHP-Warnungen in RemoteCP Mods-Plugin (foreach auf leere Umgebungen) +# Leere Umgebungen (Island, Bay, …) fuehrten zu "Invalid argument supplied +# for foreach()", weil $this->mods['Env'] nicht initialisiert war. +# Zusaetzlich bare-constant-Warnungen (pt_*) mit defined()-Pruefungen entschaerft. +COPY assets/config/remotecp/plugins/Mods/index.php /var/www/html/remotecp/plugins/Mods/index.php +RUN chown www-data:www-data /var/www/html/remotecp/plugins/Mods/index.php + # RemoteCP Mods-Plugin: Vorkonfigurierte Skin-Liste (techniverse.net) COPY assets/config/remotecp/plugins/Mods/settings.xml /var/www/html/remotecp/plugins/Mods/settings.xml RUN chown www-data:www-data /var/www/html/remotecp/plugins/Mods/settings.xml diff --git a/assets/config/remotecp/plugins/Mods/index.php b/assets/config/remotecp/plugins/Mods/index.php new file mode 100644 index 0000000..b2ebac6 --- /dev/null +++ b/assets/config/remotecp/plugins/Mods/index.php @@ -0,0 +1,320 @@ +mods['Env'] nicht initialisiert war. +* Zusaetzlich bare-constant-Warnungen (pt_*) mit defined()-Pruefungen entschaerft. +*/ +class Mods extends rcp_plugin +{ + public $display = 'side'; + public $title = 'Mods'; + public $author = 'hal.ko.sascha'; + public $version = '4.0.3.5'; + public $nservstatus = array(2,3,4,5); + public $vpermissions = array('editserversettings'); + public $apermissions = array( + 'setMods' => 'editserversettings', + 'setMusic' => 'editserversettings' + ); + + private $mods = array(); + private $music = array(); + + /** + * Alle bekannten Umgebungs-Keys mit leeren Arrays vorbelegen, + * damit foreach() auch bei fehlenden Eintraegen nicht warnt. + */ + private function initModDefaults() + { + $envs = array('Stadium', 'Island', 'Bay', 'Coast', 'Speed', 'Alpine', 'Rally'); + foreach($envs as $env) { + if(!isset($this->mods[$env])) { + $this->mods[$env] = array(); + } + } + } + + public function onLoadSettings($settings) + { + // Set defaults + $this->mods = array(); + $this->music = array(); + + // Alle Umgebungen vorinitialisieren + $this->initModDefaults(); + + // Read mods settings + if(!$settings->mods) return; + foreach($settings->mods->children() AS $env) + { + if(!$env) continue; + $tmp = (string) $env->getName(); + if(!isset($this->mods[$tmp])) { + $this->mods[$tmp] = array(); + } + foreach($env->children() AS $item) + { + $this->mods[$tmp][] = array( + 'url' => (string) $item, + 'name' => (string) $item['name'] + ); + } + } + + // Read music settings + if(!$settings->music) return; + foreach($settings->music->children() AS $song) + { + $this->music[] = array( + 'url' => (string) $song, + 'name' => (string) $song['name'] + ); + } + } + + public function onOutput() { + if(Core::getObject('gbx')->query('GetForcedMods')) { + $ForcedMods = Core::getObject('gbx')->getResponse(); + + if(!empty($ForcedMods)) { + echo "
"; + echo "
".(defined('pt_forcedmods') ? pt_forcedmods : 'Forced Mods')."
"; + if(is_array($ForcedMods['Mods'])) { + foreach($ForcedMods['Mods'] as $mod) + { + echo "
+ +
". $this->getModName($mod['Env'], $mod['Url']) ."
"; + echo "
"; + } + } + echo "
"; + } + } + + echo "
"; + echo "
"; + echo "
".(defined('pt_forcemods') ? pt_forcemods : 'Force Mods')."
"; + + // --- Stadium --- + echo "
+ +
+ +
+
"; + + // --- Island --- + echo "
+ +
+ +
+
"; + + // --- Bay --- + echo "
+ +
+ +
+
"; + + // --- Coast --- + echo "
+ +
+ +
+
"; + + // --- Speed --- + echo "
+ +
+ +
+
"; + + // --- Alpine --- + echo "
+ +
+ +
+
"; + + // --- Rally --- + echo "
+ +
+ +
+
"; + + echo "
+ +
+
"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo "
"; + + if(Core::getObject('gbx')->query('GetForcedMusic')) { + $ForcedMusic = Core::getObject('gbx')->getResponse(); + + if(!empty($ForcedMusic)) { + echo "
"; + echo "
".(defined('pt_forcedmusic') ? pt_forcedmusic : 'Forced Music')."
"; + echo "
+ +
{$ForcedMusic['Url']}
"; + echo "
"; + echo "
"; + } + } + + echo "
"; + echo "
"; + echo "
".(defined('pt_forcemusic') ? pt_forcemusic : 'Force Music')."
"; + echo "
+ +
+ +
"; + echo "
+ +
+
"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo "
"; + } + + public function setMods() + { + $array = array(); + $override = true; + if(!array_key_exists('DisableAllMods', $_REQUEST)) { + if(!empty($_REQUEST['modstadium'])) + $array[] = array('Env' => 'Stadium', 'Url' => $_REQUEST['modstadium']); + if(!empty($_REQUEST['modisland'])) + $array[] = array('Env' => 'Island' , 'Url' => $_REQUEST['modisland']); + if(!empty($_REQUEST['modbay'])) + $array[] = array('Env' => 'Bay' , 'Url' => $_REQUEST['modbay']); + if(!empty($_REQUEST['modcoast'])) + $array[] = array('Env' => 'Coast' , 'Url' => $_REQUEST['modcoast']); + if(!empty($_REQUEST['modspeed'])) + $array[] = array('Env' => 'Speed' , 'Url' => $_REQUEST['modspeed']); + if(!empty($_REQUEST['modalpine'])) + $array[] = array('Env' => 'Alpine' , 'Url' => $_REQUEST['modalpine']); + if(!empty($_REQUEST['modrally'])) + $array[] = array('Env' => 'Rally' , 'Url' => $_REQUEST['modrally']); + } else { + $override = false; + } + Core::getObject('actions')->add('SetForcedMods', $override, $array); + } + + public function setMusic() + { + $url = ''; + $override = true; + if(!array_key_exists('DisableAllMusic', $_REQUEST)) { + $url = $_REQUEST['song']; + } else { + $override = false; + } + Core::getObject('actions')->add('SetForcedMusic', $override, $url); + } + + private function getModName($env, $url) + { + if(!isset($this->mods[$env]) || !is_array($this->mods[$env])) { + return ''; + } + foreach($this->mods[$env] AS $value) + { + if($url == $value['url']) { + return $value['name']; + } + } + return ''; + } +}