From 82762c3f5a9438f654baf646bd91375271d1c4ee Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 5 Apr 2023 10:29:16 -0400 Subject: [PATCH] [Cleanup] Use variable for character instead of a loop (#3268) # Notes - Store character in a variable instead of looping a list of 1 entry. --- zone/client.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index d26d5c025..aa843e117 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -9226,27 +9226,29 @@ void Client::SetSecondaryWeaponOrnamentation(uint32 model_id) */ bool Client::GotoPlayer(std::string player_name) { - auto characters = CharacterDataRepository::GetWhere( + const auto& l = CharacterDataRepository::GetWhere( database, fmt::format("name = '{}' AND last_login > (UNIX_TIMESTAMP() - 600) LIMIT 1", player_name) ); - for (auto &c: characters) { - if (c.zone_instance > 0 && !database.CheckInstanceExists(c.zone_instance)) { - Message(Chat::Yellow, "Instance no longer exists..."); - return false; - } - - if (c.zone_instance > 0) { - database.AddClientToInstance(c.zone_instance, CharacterID()); - } - - MovePC(c.zone_id, c.zone_instance, c.x, c.y, c.z, c.heading); - - return true; + if (l.empty()) { + return false; } - return false; + const auto& c = l[0]; + + if (c.zone_instance > 0 && !database.CheckInstanceExists(c.zone_instance)) { + Message(Chat::Yellow, "Instance no longer exists..."); + return false; + } + + if (c.zone_instance > 0) { + database.AddClientToInstance(c.zone_instance, CharacterID()); + } + + MovePC(c.zone_id, c.zone_instance, c.x, c.y, c.z, c.heading); + + return true; } bool Client::GotoPlayerGroup(const std::string& player_name)