Updates
This commit is contained in:
parent
b2b46b23db
commit
74fbe0773a
5 changed files with 101 additions and 25 deletions
|
|
@ -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.
|
||||
|
|
|
|||
1
modules/steam_workshop/data/game_adapter_map.json
Normal file
1
modules/steam_workshop/data/game_adapter_map.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
0
modules/steam_workshop/data/game_adapters/.gitkeep
Normal file
0
modules/steam_workshop/data/game_adapters/.gitkeep
Normal file
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
"<a class='monitorbutton' href='" . $href . "'>
|
||||
<img src='" . check_theme_image("images/steam_workshop.png") . "' title='" . $label . "'>
|
||||
<span>" . $label . "</span>
|
||||
</a>"
|
||||
);
|
||||
}
|
||||
$href = "?m=steam_workshop&p=main&action=edit&home_id=" . $homeId;
|
||||
$module_buttons = array(
|
||||
"<a class='monitorbutton' href='" . $href . "'>
|
||||
<img src='" . check_theme_image("images/steam_workshop.png") . "' title='" . $label . "'>
|
||||
<span>" . $label . "</span>
|
||||
</a>"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$module_buttons = array();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$module_buttons = array();
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue