fix: character select starts on the last used character again

Sorting the list by creation order (as live did) picked the selected
character by Character::GetLastLogin, which is never loaded, so the
oldest character was always selected. Select the one the database lists
first (ORDER BY last_login DESC), as main does, and keep the live order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-27 18:41:28 -05:00
parent 7f53de1072
commit 929bf152f9

View File

@@ -241,22 +241,24 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) {
chars.clear(); chars.clear();
for (const auto& characterId : Database::Get()->GetAccountCharacterIds(u->GetAccountID())) { // Newest last login first (charinfo.last_login; a new character counts as logged in when it is made)
const auto characterIds = Database::Get()->GetAccountCharacterIds(u->GetAccountID());
for (const auto& characterId : characterIds) {
Character* character = new Character(characterId, u); Character* character = new Character(characterId, u);
character->UpdateFromDatabase(); character->UpdateFromDatabase();
character->SetIsNewLogin(); character->SetIsNewLogin();
chars.push_back(character); chars.push_back(character);
} }
// Live kept the characters in the order they were made and selected the one with the latest last login (a new // Live kept the characters in the order they were made and selected the one with the latest last login, as 2014
// character counts as logged in when it is made), as 2014 captures of the character list show. Character IDs // captures of the character list show. Character IDs only grow, so sorting by ID gives the order they were made in.
// only grow, so sorting by ID gives the order they were made in.
std::ranges::sort(chars, {}, &Character::GetID); std::ranges::sort(chars, {}, &Character::GetID);
ClientPackets::CharacterListResponse response; ClientPackets::CharacterListResponse response;
response.selectedCharacterIndex = 0; response.selectedCharacterIndex = 0;
for (size_t i = 1; i < chars.size(); i++) { if (!characterIds.empty()) {
if (chars[i]->GetLastLogin() > chars[response.selectedCharacterIndex]->GetLastLogin()) response.selectedCharacterIndex = static_cast<uint8_t>(i); const auto lastUsed = std::ranges::find(chars, characterIds.front(), &Character::GetID);
if (lastUsed != chars.end()) response.selectedCharacterIndex = static_cast<uint8_t>(lastUsed - chars.begin());
} }
for (const auto* const character : u->GetCharacters()) { for (const auto* const character : u->GetCharacters()) {