From 74fbe0773a6cbc68c44d11123ba1e4e76228a330 Mon Sep 17 00:00:00 2001 From: Frank Harris Date: Sat, 17 Jan 2026 19:45:24 -0600 Subject: [PATCH] Updates --- CHANGELOG.md | 1 + .../steam_workshop/data/game_adapter_map.json | 1 + .../data/game_adapters/.gitkeep | 0 .../lib/SteamWorkshopService.php | 79 ++++++++++++++++++- modules/steam_workshop/monitor_buttons.php | 45 ++++++----- 5 files changed, 101 insertions(+), 25 deletions(-) create mode 100644 modules/steam_workshop/data/game_adapter_map.json create mode 100644 modules/steam_workshop/data/game_adapters/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d33a9ae..66e2ce93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ ## 2026-01-17 - Added per-game Steam Workshop adapter management with CRUD UI and automatic mapping helpers. +- Added workshop capability helpers and monitor button gating so only supported SteamCMD homes expose the Steam Workshop shortcut. diff --git a/modules/steam_workshop/data/game_adapter_map.json b/modules/steam_workshop/data/game_adapter_map.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/modules/steam_workshop/data/game_adapter_map.json @@ -0,0 +1 @@ +{} diff --git a/modules/steam_workshop/data/game_adapters/.gitkeep b/modules/steam_workshop/data/game_adapters/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/steam_workshop/lib/SteamWorkshopService.php b/modules/steam_workshop/lib/SteamWorkshopService.php index 2773a1be..a82f8a72 100644 --- a/modules/steam_workshop/lib/SteamWorkshopService.php +++ b/modules/steam_workshop/lib/SteamWorkshopService.php @@ -11,6 +11,8 @@ class SteamWorkshopService private string $adapterDir; private string $adapterMapFile; private string $gameAdapterDir; + private string $workshopConfigDir; + private ?array $workshopAppIds = null; public function __construct(OGPDatabase $db) { @@ -19,6 +21,7 @@ class SteamWorkshopService $this->adapterDir = __DIR__ . '/GameAdapters'; $this->adapterMapFile = __DIR__ . '/../data/game_adapter_map.json'; $this->gameAdapterDir = __DIR__ . '/../data/game_adapters'; + $this->workshopConfigDir = __DIR__ . '/../game_configs'; if (!is_dir($this->configDir)) { mkdir($this->configDir, 0775, true); @@ -501,6 +504,11 @@ class SteamWorkshopService { $configDir = defined('SERVER_CONFIG_LOCATION') ? SERVER_CONFIG_LOCATION : __DIR__ . '/../../config_games/server_configs'; $groups = []; + $supportedAppIds = $this->getWorkshopConfigAppIds(); + if (empty($supportedAppIds)) { + return []; + } + $supportedLookup = array_flip($supportedAppIds); foreach (glob($configDir . '/*.xml') as $file) { $xml = @simplexml_load_file($file); @@ -518,6 +526,10 @@ class SteamWorkshopService continue; } + if (!isset($supportedLookup[$appId])) { + continue; + } + $groupKey = $this->buildWorkshopGroupKey($appId); if (!isset($groups[$groupKey])) { $gameName = isset($xml->game_name) ? trim((string)$xml->game_name) : ''; @@ -707,15 +719,41 @@ class SteamWorkshopService private function ensureDataFiles(): void { - $dir = dirname($this->adapterMapFile); - if (!is_dir($dir)) { - mkdir($dir, 0775, true); + $directories = [ + $this->configDir, + $this->gameAdapterDir, + dirname($this->adapterMapFile), + ]; + + foreach ($directories as $dir) { + if (!is_dir($dir)) { + mkdir($dir, 0775, true); + } } if (!is_file($this->adapterMapFile)) { - file_put_contents($this->adapterMapFile, json_encode([])); + file_put_contents($this->adapterMapFile, json_encode([], JSON_PRETTY_PRINT)); } } + public function gameSupportsWorkshop($serverXml): bool + { + if (!($serverXml instanceof SimpleXMLElement)) { + return false; + } + + $installer = trim((string)($serverXml->installer ?? '')); + if ($installer !== 'steamcmd') { + return false; + } + + $appId = $this->parseSteamAppIdFromConfig($serverXml); + if ($appId === null) { + return false; + } + + return in_array($appId, $this->getWorkshopConfigAppIds(), true); + } + private function parseSteamAppIdFromConfig($xml): ?string { if (!isset($xml->mods) || !isset($xml->mods->mod)) { @@ -744,6 +782,39 @@ class SteamWorkshopService return $candidate; } + private function getWorkshopConfigAppIds(): array + { + if ($this->workshopAppIds !== null) { + return $this->workshopAppIds; + } + + $dir = $this->workshopConfigDir; + if (!is_dir($dir)) { + $this->workshopAppIds = []; + return $this->workshopAppIds; + } + + $appIds = []; + foreach (glob($dir . '/*.xml') as $file) { + $xml = @simplexml_load_file($file); + if ($xml === false) { + continue; + } + + $appId = preg_replace('/[^0-9]/', '', (string)($xml->workshop_id ?? '')); + if ($appId === '') { + continue; + } + + $appIds[$appId] = true; + } + + $this->workshopAppIds = array_keys($appIds); + sort($this->workshopAppIds); + + return $this->workshopAppIds; + } + private function buildWorkshopGroupKey(string $appId): string { return 'steamapp_' . $appId; diff --git a/modules/steam_workshop/monitor_buttons.php b/modules/steam_workshop/monitor_buttons.php index 7c11ec40..e11bcb7b 100644 --- a/modules/steam_workshop/monitor_buttons.php +++ b/modules/steam_workshop/monitor_buttons.php @@ -22,31 +22,34 @@ * */ -if (isset($server_xml->installer) && $server_xml->installer === "steamcmd") +require_once __DIR__ . '/lib/SteamWorkshopService.php'; + +global $db; + +$module_buttons = array(); + +if (isset($server_xml) && isset($server_home['home_id'])) { - $homeId = isset($server_home['home_id']) ? (int)$server_home['home_id'] : 0; - if ($homeId > 0) + $service = new SteamWorkshopService($db); + if ($service->gameSupportsWorkshop($server_xml)) { - $label = get_lang('steam_workshop'); - if ($label === 'steam_workshop') + $homeId = (int)$server_home['home_id']; + if ($homeId > 0) { - $label = 'Steam Workshop'; + $label = get_lang('steam_workshop'); + if ($label === 'steam_workshop') + { + $label = 'Steam Workshop'; + } + + $href = "?m=steam_workshop&p=main&action=edit&home_id=" . $homeId; + $module_buttons = array( + " + + " . $label . " + " + ); } - $href = "?m=steam_workshop&p=main&action=edit&home_id=" . $homeId; - $module_buttons = array( - " - - " . $label . " - " - ); } - else - { - $module_buttons = array(); - } -} -else -{ - $module_buttons = array(); } ?> \ No newline at end of file