mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
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:
@@ -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<uint8_t>(i);
|
||||
if (!characterIds.empty()) {
|
||||
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()) {
|
||||
|
||||
Reference in New Issue
Block a user