From 4399daad4c33196d9174875e15a1fbe5a86d7516 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sun, 27 Sep 2026 08:42:01 -0500 Subject: [PATCH] fix(login): select the last played character in a stable list The character list selected index 0 and was ordered by last login, so the characters swapped places on the selection screen after each session. Live kept them 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): 2014 captures show e.g. a new fourth character appended and selected (index 3), and after the next login the list in the same order with index 0 for the character played last. Characters are now sorted by ID (creation order) and the one with the latest last login is selected. Co-Authored-By: Claude Opus 5.5 --- dGame/UserManager.cpp | 10 +++++++++- dNet/ClientPackets.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 7b54407b5..8f10d4219 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -248,8 +248,16 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) { 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. + std::ranges::sort(chars, {}, &Character::GetID); + ClientPackets::CharacterListResponse response; - response.selectedCharacterIndex = 0; //TODO: Pick the most recent played index. character index in front, just picking 0 + 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); + } for (const auto* const character : u->GetCharacters()) { auto& entry = response.characters.emplace_back(); diff --git a/dNet/ClientPackets.h b/dNet/ClientPackets.h index c85c83ebb..19eb5ffa8 100644 --- a/dNet/ClientPackets.h +++ b/dNet/ClientPackets.h @@ -113,7 +113,7 @@ namespace ClientPackets { }; // Written as a u8 count first - uint8_t selectedCharacterIndex{}; // TODO: Pick the most recent played index. DLU always sends 0 + uint8_t selectedCharacterIndex{}; // The character with the latest last login std::vector characters{}; CharacterListResponse() : LUBitStream(ServiceType::CLIENT, MessageType::Client::CHARACTER_LIST_RESPONSE) {}