diff --git a/includes/armory.php b/includes/armory.php index cd2defc..ccd1b76 100644 --- a/includes/armory.php +++ b/includes/armory.php @@ -220,15 +220,66 @@ function armory_valid_char_id(string $charId): bool return (bool) preg_match('/^[A-Za-z0-9_\-]{20,120}={0,2}$/', $charId); } +// NCSoft liefert manchmal unvollstaendige Antworten (Status 200, aber Ausruestung/Skills null bzw. Gegenstandsstufe 0, +// seit Oktober 2026 gehaeuft) - so oft wird nachgefragt +const ARMORY_HOLLOW_TRIES = 3; + +/** Ausruestung fehlt in der Antwort von /api/character/equipment (equipmentList null). */ +function armory_equip_hollow(array $equip): bool +{ + return !is_array($equip['equipment']['equipmentList'] ?? null); +} + +/** Skills fehlen in der Antwort von /api/character/equipment (skillList null). */ +function armory_skills_hollow(array $equip): bool +{ + return !is_array($equip['skill']['skillList'] ?? null); +} + +/** Ausruestung oder Skills fehlen - dann wird nachgefragt. */ +function armory_equip_or_skills_hollow(array $equip): bool +{ + return armory_equip_hollow($equip) || armory_skills_hollow($equip); +} + +/** Werte fehlen in der Antwort von /api/character/info (Gegenstandsstufe 0 - die hat jeder ausgeruestete Charakter). */ +function armory_stats_hollow(array $info): bool +{ + foreach ((array) ($info['stat']['statList'] ?? []) as $stat) { + if (($stat['type'] ?? '') === 'ItemLevel') { + return (int) ($stat['value'] ?? 0) <= 0; + } + } + return true; +} + +/** + * Fragt nach, solange NCSoft eine leere Antwort liefert - hoechstens ARMORY_HOLLOW_TRIES mal und nur, solange + * seit dem ersten Versuch keine 6 Sekunden vergangen sind (NCSoft antwortet dann oft langsam, die Seite soll nicht haengen). + */ +function armory_request_complete(string $url, callable $hollow): array +{ + $start = microtime(true); + for ($try = 1; ; $try++) { + $data = armory_request($url); + if (!$hollow($data) || $try >= ARMORY_HOLLOW_TRIES || microtime(true) - $start > 6) { + return $data; + } + usleep(300000); + } +} + /** * Holt Charakterinfo und Ausruestung und bereitet sie fuer die Anzeige auf (nur was wir zeigen). + * Bleibt eine Antwort trotz Nachfragen leer, steht das in 'hollow' (equipment/stats) - armory_refresh + * behaelt dann die zuletzt gespeicherten Daten dafuer. * * @return array */ function armory_fetch(string $charId, int $serverId): array { - $info = armory_request('https://' . ARMORY_API_HOST . '/api/character/info?' . armory_query($charId, $serverId)); - $equip = armory_request('https://' . ARMORY_API_HOST . '/api/character/equipment?' . armory_query($charId, $serverId)); + $info = armory_request_complete('https://' . ARMORY_API_HOST . '/api/character/info?' . armory_query($charId, $serverId), 'armory_stats_hollow'); + $equip = armory_request_complete('https://' . ARMORY_API_HOST . '/api/character/equipment?' . armory_query($charId, $serverId), 'armory_equip_or_skills_hollow'); $profile = (array) ($info['profile'] ?? []); if (empty($profile['characterName'])) { throw new RuntimeException('Diesen Charakter gibt es im Spiel nicht (mehr).', 404); @@ -325,9 +376,39 @@ function armory_fetch(string $charId, int $serverId): array 'extra' => $extra, 'pet' => !empty($pet['name']) ? ['name' => (string) $pet['name'], 'icon' => (string) ($pet['icon'] ?? ''), 'level' => (int) ($pet['level'] ?? 0)] : null, 'wing' => !empty($wing['name']) ? ['name' => (string) $wing['name'], 'icon' => (string) ($wing['icon'] ?? ''), 'grade' => (string) ($wing['grade'] ?? ''), 'enchant' => (int) ($wing['enchantLevel'] ?? 0)] : null, + 'hollow' => array_keys(array_filter([ + 'equipment' => armory_equip_hollow($equip), 'skills' => armory_skills_hollow($equip), 'stats' => armory_stats_hollow($info), + ])), ]; } +/** + * Was NCSoft gerade leer geliefert hat (armory_fetch: 'hollow'), aus den zuletzt gespeicherten Daten uebernehmen - + * sofern die etwas enthalten. 'hollow' bleibt nur stehen, wo es auch vorher nichts gab. + */ +function armory_keep_previous(array $data, ?array $previous): array +{ + $hollow = []; + foreach ((array) ($data['hollow'] ?? []) as $part) { + $keys = ['equipment' => ['equipment', 'extra', 'pet', 'wing'], 'skills' => ['skills'], 'stats' => ['stats', 'item_level']][$part] ?? []; + $usable = match ($part) { + 'equipment' => !empty($previous['equipment']), + 'skills' => !empty($previous['skills']), + 'stats' => (int) ($previous['item_level'] ?? 0) > 0, + default => false, + }; + if ($usable) { + foreach ($keys as $key) { + $data[$key] = $previous[$key] ?? $data[$key]; + } + } else { + $hollow[] = $part; + } + } + $data['hollow'] = $hollow; + return $data; +} + /** * Raster eines Daevanion-Boards kompakt: Felder als [Reihe, Spalte, Art, Seltenheit, offen, Name, Effekt] * (leere Felder fallen weg) und die Summe der Effekte aller freigeschalteten Felder. @@ -382,6 +463,7 @@ function armory_refresh(array $character): array throw $e; } + $data = armory_keep_previous($data, armory_data($character)); $portrait = armory_store_portrait((int) $character['id'], $data['portrait']); $data['portrait'] = $portrait; $json = json_encode($data, JSON_UNESCAPED_UNICODE); @@ -747,6 +829,11 @@ function armory_panel_html(array $character, bool $canRefresh): string $head .= ' '; } $head .= ''; + if (!empty($data['hollow'])) { + $missing = array_intersect_key(['equipment' => 'Ausrüstung', 'skills' => 'Skills', 'stats' => 'Werte'], array_flip($data['hollow'])); + $head .= '

NCSoft hat gerade nicht alles geliefert (fehlt: ' . e(implode(', ', $missing)) + . ') – bitte später noch einmal aktualisieren.

'; + } if ($data === null) { $html .= $head . '

' . (!empty($character['aion_error']) diff --git a/includes/patchnotes.php b/includes/patchnotes.php index 94dc1c3..8079c83 100644 --- a/includes/patchnotes.php +++ b/includes/patchnotes.php @@ -37,6 +37,7 @@ const PATCHNOTES = [ 'changes' => [ ['type' => 'behoben', 'area' => 'Profil', 'text' => 'Beim Ansehen einer Profilseite werden verknüpfte Charaktere im Hintergrund mit dem Spiel abgeglichen. Bisher wurde danach nur die Kurzinfo (Kampfkraft usw.) neu angezeigt, die Stufe unter dem Namen erst beim nächsten Laden – jetzt beides sofort.'], ['type' => 'behoben', 'area' => 'Profil', 'text' => 'Wer einen verknüpften Charakter bearbeitet und speichert, schreibt damit nicht mehr die alte Stufe aus dem Formular zurück: Name, Klasse und Stufe kommen bei verknüpften Charakteren immer aus dem Spiel, beim Speichern wird gleich abgeglichen.'], + ['type' => 'behoben', 'area' => 'Profil', 'text' => 'NCSoft liefert die Charakterdaten zurzeit oft unvollständig (Ausrüstung, Skills oder Werte fehlen, Gearscore 0). Die Website fragt dann bis zu dreimal nach und behält sonst den letzten vollständigen Stand, statt ihn mit leeren Daten zu überschreiben. Fehlt trotzdem etwas, steht ein Hinweis im Popup.'], ['type' => 'verbessert', 'area' => 'Profil', 'text' => 'Abgeglichen wird jetzt schon, wenn die Daten älter als 15 Minuten sind (bisher eine Stunde). Von Hand geht es weiterhin mit „Aktualisieren“ im Popup des Charakters (Klick auf die Charakterkarte).'], ], ],