From a35a8c2d1fe333b072f224e8eeb582011824eeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 1 Apr 2026 17:52:22 -0300 Subject: [PATCH] Sort quest missions and map hunt updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve quest mission ordering and robustly handle server hunt updates. Commands.pm: sort mission entries by mission_index (fallback to 9999) then by numeric mobID so missions display in intended order. Network/Receive.pm: ignore mission updates for unknown quests early, and add a fallback mapping for servers that send updates keyed only by hunt_id — derive a mission_index from hunt_id and match against existing missions (allowing off-by-one), with safety checks to avoid applying updates to non-existent missions. These changes prevent incorrect ordering and missed/incorrect mission updates from varied server implementations. --- src/Commands.pm | 5 +++-- src/Network/Receive.pm | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Commands.pm b/src/Commands.pm index d607e74c17..165172ef02 100644 --- a/src/Commands.pm +++ b/src/Commands.pm @@ -7091,7 +7091,9 @@ sub cmdQuest { my $quest = $questList->{$questID}; $msg .= swrite(sprintf("\@%s \@%s \@%s \@%s \@%s", ('>'x2), ('<'x5), ('<'x30), ('<'x10), ('<'x24)), [$k, $questID, $quests_lut{$questID} ? $quests_lut{$questID}{title} : '', $quest->{active} ? T("active") : T("inactive"), $quest->{time_expire} ? scalar localtime $quest->{time_expire} : '']); - foreach my $mobID (keys %{$quest->{missions}}) { + foreach my $mobID (sort { + ($quest->{missions}{$a}{mission_index} // 9999) <=> ($quest->{missions}{$b}{mission_index} // 9999) || $a <=> $b + } keys %{$quest->{missions}}) { my $mission = $quest->{missions}->{$mobID}; $msg .= swrite(sprintf("\@%s \@%s \@%s", ('>'x2), ('<'x30), ('<'x30)), [" -", $mission->{mob_name}, sprintf(defined $mission->{mob_goal} ? '%d/%d' : '%d', @{$mission}{qw(mob_count mob_goal)})]); @@ -8786,4 +8788,3 @@ sub cmdEden { 1; - diff --git a/src/Network/Receive.pm b/src/Network/Receive.pm index 0382a8cf37..8a167cc457 100644 --- a/src/Network/Receive.pm +++ b/src/Network/Receive.pm @@ -4891,6 +4891,8 @@ sub quest_update_mission_hunt { @{$mission}{@{$quest_info->{mission_keys}}} = unpack($quest_info->{mission_pack}, substr($args->{message}, $offset, $quest_info->{mission_len})); + next unless exists $questList->{$mission->{questID}}; + my $quest = \%{$questList->{$mission->{questID}}}; my $mission_id; @@ -4924,6 +4926,21 @@ sub quest_update_mission_hunt { } } + # Some servers can return mission updates keyed only by hunt identification. + # If direct lookup fails, map update by mission index from hunt_id. + if (!defined $mission_id && exists $mission->{hunt_id}) { + my $mission_index = $mission->{hunt_id} - ($mission->{questID} * 1000); + + foreach my $current_key (keys %{$quest->{missions}}) { + next unless exists $quest->{missions}->{$current_key}{mission_index}; + next unless $quest->{missions}->{$current_key}{mission_index} == $mission_index || $quest->{missions}->{$current_key}{mission_index} == $mission_index - 1; + $mission_id = $current_key; + last; + } + } + + next unless defined $mission_id && exists $quest->{missions}->{$mission_id}; + my $quest_mission = \%{$quest->{missions}->{$mission_id}}; $quest_mission->{mob_count} = $mission->{mob_count}; @@ -12604,4 +12621,3 @@ sub notify_accessible_mapname { } 1; -