From 929bf152f916f752adf42abac2f66e40eee75bb0 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sun, 27 Sep 2026 18:41:28 -0500 Subject: [PATCH] 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 --- dGame/UserManager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 8f10d4219..d60022e0e 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -241,22 +241,24 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) { 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->UpdateFromDatabase(); character->SetIsNewLogin(); 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 - // character counts as logged in when it is made), as 2014 captures of the character list show. Character IDs - // only grow, so sorting by ID gives the order they were made in. + // Live kept the characters in the order they were made and selected the one with the latest last login, as 2014 + // captures of the character list show. Character IDs only grow, so sorting by ID gives the order they were made in. std::ranges::sort(chars, {}, &Character::GetID); ClientPackets::CharacterListResponse response; response.selectedCharacterIndex = 0; - for (size_t i = 1; i < chars.size(); i++) { - if (chars[i]->GetLastLogin() > chars[response.selectedCharacterIndex]->GetLastLogin()) response.selectedCharacterIndex = static_cast(i); + if (!characterIds.empty()) { + const auto lastUsed = std::ranges::find(chars, characterIds.front(), &Character::GetID); + if (lastUsed != chars.end()) response.selectedCharacterIndex = static_cast(lastUsed - chars.begin()); } for (const auto* const character : u->GetCharacters()) {