Updated workshop
This commit is contained in:
parent
0d4cbd66fc
commit
0885bfef92
6 changed files with 531 additions and 75 deletions
|
|
@ -7,6 +7,8 @@ class AdminWorkshopController
|
|||
{
|
||||
private SteamWorkshopService $service;
|
||||
private array $lang;
|
||||
private ?array $adapterFormOverride = null;
|
||||
private ?string $adapterFormGameKey = null;
|
||||
|
||||
public function __construct(OGPDatabase $db)
|
||||
{
|
||||
|
|
@ -27,13 +29,19 @@ class AdminWorkshopController
|
|||
echo '<link rel="stylesheet" type="text/css" href="modules/steam_workshop/steam_workshop.css" />';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$this->processSave();
|
||||
$this->processPost();
|
||||
}
|
||||
|
||||
$gameKeys = $this->service->listAvailableGameKeys();
|
||||
$mappings = $this->service->getAdapterMappings();
|
||||
$adapters = $this->service->loadAdapters();
|
||||
$adapterOptions = $this->service->getAdapterOptions();
|
||||
$gameRows = $this->buildGameRows($gameKeys);
|
||||
|
||||
$activeGame = $this->resolveActiveGameKey();
|
||||
$adapterForm = $activeGame !== ''
|
||||
? $this->service->getAdapterFormData($activeGame, $this->adapterFormOverride)
|
||||
: null;
|
||||
|
||||
$this->render('admin/index', [
|
||||
'lang' => $this->lang,
|
||||
|
|
@ -41,10 +49,30 @@ class AdminWorkshopController
|
|||
'mappings' => $mappings,
|
||||
'adapters' => $adapters,
|
||||
'adapterOptions' => $adapterOptions,
|
||||
'gameRows' => $gameRows,
|
||||
'adapterForm' => $adapterForm,
|
||||
'activeGameKey' => $activeGame,
|
||||
]);
|
||||
}
|
||||
|
||||
private function processSave(): void
|
||||
private function processPost(): void
|
||||
{
|
||||
$action = $_POST['admin_action'] ?? 'save_mappings';
|
||||
switch ($action) {
|
||||
case 'save_adapter':
|
||||
$this->processAdapterSave();
|
||||
break;
|
||||
case 'delete_adapter':
|
||||
$this->processAdapterDelete();
|
||||
break;
|
||||
case 'save_mappings':
|
||||
default:
|
||||
$this->processSaveMappings();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function processSaveMappings(): void
|
||||
{
|
||||
$payload = $_POST['mapping'] ?? [];
|
||||
if (!is_array($payload)) {
|
||||
|
|
@ -54,6 +82,88 @@ class AdminWorkshopController
|
|||
print_success($this->lang['message_mappings_saved'] ?? 'Adapter mappings saved.');
|
||||
}
|
||||
|
||||
private function processAdapterSave(): void
|
||||
{
|
||||
$gameKey = $this->sanitizeGameKeyInput($_POST['game_key'] ?? '');
|
||||
if ($gameKey === '') {
|
||||
print_failure($this->lang['error_game_key_required'] ?? 'Game key required.');
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = $_POST['adapter'] ?? [];
|
||||
if (!is_array($payload)) {
|
||||
$payload = [];
|
||||
}
|
||||
|
||||
try {
|
||||
$this->service->saveGameAdapter($gameKey, $payload);
|
||||
$this->service->upsertAdapterMapping($gameKey, $gameKey);
|
||||
print_success($this->lang['message_adapter_saved'] ?? 'Adapter saved.');
|
||||
$this->adapterFormOverride = null;
|
||||
$this->adapterFormGameKey = null;
|
||||
} catch (RuntimeException $e) {
|
||||
$this->adapterFormGameKey = $gameKey;
|
||||
$this->adapterFormOverride = [
|
||||
'name' => trim((string)($payload['name'] ?? '')),
|
||||
'steam_app_id' => trim((string)($payload['steam_app_id'] ?? '')),
|
||||
'mods_dir' => trim((string)($payload['mods_dir'] ?? '')),
|
||||
'keys_dir' => trim((string)($payload['keys_dir'] ?? '')),
|
||||
'supports_hot_reload' => !empty($payload['supports_hot_reload']),
|
||||
'activation_template' => trim((string)($payload['activation_template'] ?? '')),
|
||||
'notes' => trim((string)($payload['notes'] ?? '')),
|
||||
];
|
||||
print_failure($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function processAdapterDelete(): void
|
||||
{
|
||||
$gameKey = $this->sanitizeGameKeyInput($_POST['game_key'] ?? '');
|
||||
if ($gameKey === '') {
|
||||
print_failure($this->lang['error_game_key_required'] ?? 'Game key required.');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->service->deleteGameAdapter($gameKey)) {
|
||||
$this->service->removeAdapterMapping($gameKey, $gameKey);
|
||||
print_success($this->lang['message_adapter_deleted'] ?? 'Adapter deleted.');
|
||||
} else {
|
||||
print_failure($this->lang['error_adapter_delete_failed'] ?? 'Unable to delete adapter.');
|
||||
}
|
||||
}
|
||||
|
||||
private function buildGameRows(array $gameKeys): array
|
||||
{
|
||||
$rows = [];
|
||||
foreach ($gameKeys as $gameKey) {
|
||||
$rows[] = [
|
||||
'game_key' => $gameKey,
|
||||
'exists' => $this->service->gameAdapterExists($gameKey),
|
||||
'adapter' => $this->service->getGameAdapter($gameKey),
|
||||
'updated_at' => $this->service->getGameAdapterUpdatedAt($gameKey),
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function resolveActiveGameKey(): string
|
||||
{
|
||||
if ($this->adapterFormGameKey !== null) {
|
||||
return $this->adapterFormGameKey;
|
||||
}
|
||||
|
||||
$queryKey = $_GET['adapter_game'] ?? '';
|
||||
return $this->sanitizeGameKeyInput($queryKey);
|
||||
}
|
||||
|
||||
private function sanitizeGameKeyInput($value): string
|
||||
{
|
||||
$gameKey = strtolower(trim((string)$value));
|
||||
$sanitized = preg_replace('/[^a-z0-9_\-.]/', '', $gameKey);
|
||||
return is_string($sanitized) ? $sanitized : '';
|
||||
}
|
||||
|
||||
private function render(string $view, array $data = []): void
|
||||
{
|
||||
extract($data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue