- Each set has three pages (tabs with counters): equipment, skills (active and passive) and stigmas; the skill pages live in includes/gear_skills_view.php - Specializations of active skills like in the aion2hub planner: collapsible list with unlock level and effect, three from level 8, one from 12, one from 16; one slot at 8, two at 12, three at 20; locked options are disabled, lowering the level drops options that no longer fit (checked on the server too, stored as bitmask gear_set_skills.specs) - Stigmas: the chosen ones as the 4 slots on top, each stigma lists its four bonuses at 5/10/15/20 with effect, reached ones are highlighted - Admin: "Spezialisierungen & Stigma-Boni übernehmen" reads the build planner page, finds the JavaScript file with the data set (one request per second, remembers the file) and stores the effects of all classes (gear_skills.spec_effects); new page "Namen & Spezialisierungen" (admin/gear_skills.php) for German skill names and texts - Autosave sends level and specializations per skill card, the tab counter updates live; compare shows specializations, copies keep them - Schema version 39 (gear_skills.name_de, spec_effects, spec_names; gear_set_skills.specs), patch notes, README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
224 lines
11 KiB
PHP
224 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* Gear-Planer, Katalog: Gegenstaende und die Skill-Listen der Klassen von aion2hub uebernehmen
|
|
* und abgleichen. Antwortet als JSON (Aufrufe aus assets/js/gear-admin.js), nur "delete" und
|
|
* "skills_prune" leiten zurueck.
|
|
*/
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
require_once __DIR__ . '/../includes/gear.php';
|
|
require_permission('gear.manage');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
redirect('/admin/gear_items.php');
|
|
}
|
|
verify_csrf();
|
|
|
|
$userId = (int) current_user()['id'];
|
|
$action = (string) ($_POST['action'] ?? '');
|
|
|
|
/** JSON-Antwort und Ende. */
|
|
$respond = static function (array $data, int $status = 200): void {
|
|
http_response_code($status);
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
};
|
|
|
|
/**
|
|
* Hoechstens ein Abruf pro Sekunde (pro Sitzung) - aion2hub soll von uns nicht mehr merken als
|
|
* von jemandem, der sich durch die Seiten klickt.
|
|
*/
|
|
$politePause = static function (): void {
|
|
$last = (float) ($_SESSION['gear_source_last_fetch'] ?? 0);
|
|
$wait = 1.0 - (microtime(true) - $last);
|
|
if ($wait > 0) {
|
|
usleep((int) ($wait * 1000000));
|
|
}
|
|
$_SESSION['gear_source_last_fetch'] = microtime(true);
|
|
};
|
|
|
|
try {
|
|
switch ($action) {
|
|
case 'plan':
|
|
// Was steckt hinter der Eingabe? Ein einzelner Gegenstand oder Listen je Kategorie.
|
|
$input = trim((string) ($_POST['url'] ?? ''));
|
|
$single = gear_source_parse_id($input);
|
|
if ($single !== null) {
|
|
$respond(['ok' => true, 'ids' => [$single], 'known' => gear_item($single) ? [$single] : []]);
|
|
}
|
|
$respond(['ok' => true, 'lists' => gear_source_list_urls($input)]);
|
|
|
|
case 'list':
|
|
// Eine Seite einer Liste (Adresse aus "plan") -> enthaltene IDs und Seitenzahl
|
|
$url = trim((string) ($_POST['url'] ?? ''));
|
|
$page = max(1, (int) ($_POST['page'] ?? 1));
|
|
if (!in_array($url, gear_source_list_urls($url), true)) {
|
|
$respond(['ok' => false, 'error' => 'Ungültige Listen-Adresse.'], 400);
|
|
}
|
|
$politePause();
|
|
$result = gear_source_list_page(gear_source_fetch($url . '&page=' . $page));
|
|
$known = $result['ids']
|
|
? db()->query('SELECT id FROM gear_items WHERE id IN (' . implode(',', $result['ids']) . ')')->fetchAll(PDO::FETCH_COLUMN)
|
|
: [];
|
|
$respond(['ok' => true, 'known' => array_map('intval', $known)] + $result);
|
|
|
|
case 'import':
|
|
case 'check':
|
|
$id = (int) ($_POST['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
$respond(['ok' => false, 'error' => 'Ungültige ID.'], 400);
|
|
}
|
|
$politePause();
|
|
$parsed = gear_item_fetch($id);
|
|
$old = gear_item($id);
|
|
$diffs = gear_item_diff($old, $parsed);
|
|
// Abgleich ohne Uebernehmen: nur zeigen, was anders waere
|
|
$apply = $action === 'import' || !empty($_POST['apply']);
|
|
if ($apply) {
|
|
$result = gear_item_store($parsed, $userId);
|
|
} elseif ($old !== null) {
|
|
// Trotzdem als "geprueft" vermerken, wenn sich nichts geaendert hat
|
|
if (!$diffs) {
|
|
db()->prepare('UPDATE gear_items SET checked_at = NOW(), checked_by = ?, source_version = ? WHERE id = ?')
|
|
->execute([$userId, mb_substr($parsed['source_version'], 0, 120), $id]);
|
|
}
|
|
}
|
|
if (empty($_POST['batch']) && $apply) {
|
|
admin_log($old === null ? '🗡️ Gear-Planer: Gegenstand übernommen' : '🗡️ Gear-Planer: Gegenstand abgeglichen', [
|
|
'Gegenstand' => $parsed['name'] . ' (#' . $id . ')',
|
|
'Änderungen' => $old === null ? 'neu' : ($diffs ? implode(', ', array_column($diffs, 0)) : 'keine'),
|
|
], 'info', 'gear');
|
|
}
|
|
$respond([
|
|
'ok' => true,
|
|
'id' => $id,
|
|
'name' => $parsed['name'],
|
|
'new' => $old === null,
|
|
'applied' => $apply,
|
|
'diffs' => $old === null ? [] : $diffs,
|
|
]);
|
|
|
|
case 'batch_done':
|
|
// Eine Zusammenfassung pro Durchlauf statt eines Eintrags je Gegenstand
|
|
$summary = array_filter([
|
|
'Art' => (string) ($_POST['kind'] ?? '') === 'check' ? 'Abgleich' : 'Übernahme',
|
|
'Neu' => (int) ($_POST['new'] ?? 0) ?: null,
|
|
'Geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
|
|
'Unverändert' => (int) ($_POST['same'] ?? 0) ?: null,
|
|
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
|
|
'Quelle' => mb_substr((string) ($_POST['source'] ?? ''), 0, 200) ?: null,
|
|
], static fn ($value): bool => $value !== null);
|
|
admin_log('🗡️ Gear-Planer: Gegenstände von aion2hub', $summary, 'info', 'gear');
|
|
$respond(['ok' => true]);
|
|
|
|
case 'skills_class':
|
|
// Skill-Liste einer Klasse von ihrer Klassenseite uebernehmen bzw. abgleichen
|
|
$className = (string) ($_POST['class_name'] ?? '');
|
|
if (!isset(GEAR_SOURCE_CLASSES[$className])) {
|
|
$respond(['ok' => false, 'error' => 'Unbekannte Klasse.'], 400);
|
|
}
|
|
[$slug, $sourceClass] = GEAR_SOURCE_CLASSES[$className];
|
|
$politePause();
|
|
$parsed = gear_source_parse_class_skills(gear_source_fetch(GEAR_SOURCE_CLASS_URL . $slug), $sourceClass);
|
|
$respond(['ok' => true, 'class_name' => $className] + gear_skills_store($className, $parsed, $userId));
|
|
|
|
case 'skill_icon':
|
|
$skill = gear_skill((int) ($_POST['id'] ?? 0));
|
|
if (!$skill) {
|
|
$respond(['ok' => false, 'error' => 'Diesen Skill gibt es nicht (mehr).'], 404);
|
|
}
|
|
if (!empty($skill['icon']) && is_file(GEAR_SKILL_ICON_DIR . $skill['icon'])) {
|
|
$respond(['ok' => true, 'icon' => $skill['icon']]);
|
|
}
|
|
$politePause();
|
|
$icon = gear_skill_icon_download((int) $skill['id']);
|
|
if ($icon === null) {
|
|
$respond(['ok' => false, 'error' => 'Icon für „' . $skill['name'] . '“ ließ sich nicht laden (bei aion2hub fehlt es evtl. noch) - der nächste Abgleich versucht es erneut.'], 422);
|
|
}
|
|
db()->prepare('UPDATE gear_skills SET icon = ? WHERE id = ?')->execute([$icon, $skill['id']]);
|
|
$respond(['ok' => true, 'icon' => $icon]);
|
|
|
|
case 'specs_plan':
|
|
// Wo stecken die Spezialisierungen? In einer der JavaScript-Dateien des Build-Planers (die zuletzt
|
|
// passende zuerst - die Namen aendern sich nur mit neuen Versionen der Seite)
|
|
$politePause();
|
|
$chunks = gear_source_planner_chunks(gear_source_fetch(GEAR_SOURCE_PLANNER_URL));
|
|
$known = setting_get('gear_planner_chunk');
|
|
if ($known !== '' && in_array($known, $chunks, true)) {
|
|
$chunks = array_values(array_unique(array_merge([$known], $chunks)));
|
|
}
|
|
if (!$chunks) {
|
|
$respond(['ok' => false, 'error' => 'Im Build-Planer von aion2hub stehen keine Dateien mehr, in denen die Spezialisierungen stecken könnten - hat sich die Seite geändert?'], 422);
|
|
}
|
|
$respond(['ok' => true, 'chunks' => $chunks]);
|
|
|
|
case 'specs_chunk':
|
|
// Eine Datei des Build-Planers durchsuchen - steckt der Datensatz drin, gleich speichern
|
|
$path = (string) ($_POST['path'] ?? '');
|
|
if (!preg_match('#^/_next/static/chunks/[A-Za-z0-9_~-]+\.js$#', $path)) {
|
|
$respond(['ok' => false, 'error' => 'Ungültige Datei.'], 400);
|
|
}
|
|
$politePause();
|
|
$planner = gear_source_parse_planner_specs(gear_source_fetch('https://' . GEAR_SOURCE_HOST . $path, '*/*'));
|
|
if ($planner === null) {
|
|
$respond(['ok' => true, 'found' => false]);
|
|
}
|
|
$result = gear_skills_store_specs($planner);
|
|
setting_set('gear_planner_chunk', $path);
|
|
admin_log('🗡️ Gear-Planer: Spezialisierungen von aion2hub', array_filter([
|
|
'Stand' => $result['built_at'],
|
|
'Aktualisiert' => $result['updated'] ?: null,
|
|
'Unverändert' => $result['same'] ?: null,
|
|
'Ohne Daten' => $result['missing'] ? count($result['missing']) : null,
|
|
'Hinweis' => $result['warning'] ?: null,
|
|
], static fn ($value): bool => $value !== null && $value !== ''), 'info', 'gear');
|
|
$respond(['ok' => true, 'found' => true] + $result);
|
|
|
|
case 'skills_done':
|
|
// Eine Zusammenfassung pro Durchlauf
|
|
$summary = array_filter([
|
|
'Klassen' => mb_substr((string) ($_POST['classes'] ?? ''), 0, 200) ?: null,
|
|
'Skills' => (int) ($_POST['total'] ?? 0) ?: null,
|
|
'Neu' => (int) ($_POST['new'] ?? 0) ?: null,
|
|
'Geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
|
|
'Nicht mehr gelistet' => (int) ($_POST['unlisted'] ?? 0) ?: null,
|
|
'Icons geladen' => (int) ($_POST['icons'] ?? 0) ?: null,
|
|
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
|
|
], static fn ($value): bool => $value !== null);
|
|
admin_log('🗡️ Gear-Planer: Skills von aion2hub', $summary, 'info', 'gear');
|
|
$respond(['ok' => true]);
|
|
|
|
case 'skills_prune':
|
|
// Skills, die aion2hub nicht mehr listet, samt ihrer geplanten Stufen entfernen
|
|
$gone = db()->query('SELECT id, name, class_name, icon FROM gear_skills WHERE is_listed = 0')->fetchAll();
|
|
if ($gone) {
|
|
db()->exec('DELETE FROM gear_skills WHERE is_listed = 0');
|
|
foreach ($gone as $skill) {
|
|
if (!empty($skill['icon']) && strpos((string) $skill['icon'], '/') === false) {
|
|
@unlink(GEAR_SKILL_ICON_DIR . $skill['icon']);
|
|
}
|
|
}
|
|
admin_log('🗡️ Gear-Planer: alte Skills entfernt', [
|
|
'Skills' => implode(', ', array_map(static fn (array $s): string => $s['name'] . ' (' . $s['class_name'] . ')', $gone)),
|
|
], 'danger', 'gear');
|
|
set_flash('success', count($gone) . (count($gone) === 1 ? ' alter Skill entfernt.' : ' alte Skills entfernt.'));
|
|
}
|
|
redirect('/admin/gear_items.php#skills');
|
|
|
|
case 'delete':
|
|
$item = gear_item((int) ($_POST['id'] ?? 0));
|
|
if ($item) {
|
|
db()->prepare('DELETE FROM gear_items WHERE id = ?')->execute([$item['id']]);
|
|
if (!empty($item['icon']) && strpos((string) $item['icon'], '/') === false) {
|
|
@unlink(GEAR_ICON_DIR . $item['icon']);
|
|
}
|
|
admin_log('🗡️ Gear-Planer: Gegenstand gelöscht', ['Gegenstand' => $item['name'] . ' (#' . $item['id'] . ')'], 'danger', 'gear');
|
|
set_flash('success', '„' . $item['name'] . '“ gelöscht - in Sets ist der Slot jetzt leer.');
|
|
}
|
|
redirect('/admin/gear_items.php');
|
|
}
|
|
} catch (RuntimeException $e) {
|
|
$respond(['ok' => false, 'error' => $e->getMessage()], 422);
|
|
}
|
|
|
|
$respond(['ok' => false, 'error' => 'Unbekannte Aktion.'], 400);
|