diff --git a/src/network/server.cpp b/src/network/server.cpp index c96b28032..f0cf59067 100644 --- a/src/network/server.cpp +++ b/src/network/server.cpp @@ -75,30 +75,26 @@ Server::Server(const XMLNode& server_info) : m_supports_encrytion(true) const XMLNode* player_info = players->getNode(i); assert(player_info->getName() == "player-info"); std::string username; - std::pair > - p; - auto& t = p.second; + std::tuple t; // Default rank and scores if none std::get<0>(t) = -1; std::get<2>(t) = 2000.0; player_info->get("rank", &std::get<0>(t)); player_info->get("username", &username); std::get<1>(t) = StringUtils::utf8ToWide(username); - p.first = StringUtils::toLowerCase(username); + m_lower_case_player_names += StringUtils::toLowerCase(username); player_info->get("scores", &std::get<2>(t)); float time_played = 0.0f; player_info->get("time-played", &time_played); std::get<3>(t) = time_played; - m_players.emplace_back(std::move(p)); + m_players.push_back(t); } // Sort by rank std::sort(m_players.begin(), m_players.end(), - [](const std::pair >& a, - const std::pair >& b)->bool + [](const std::tuple& a, + const std::tuple& b)->bool { - return std::get<0>(a.second) < std::get<0>(b.second); + return std::get<0>(a) < std::get<0>(b); }); // Show owner name as Official right now if official server hoster account diff --git a/src/network/server.hpp b/src/network/server.hpp index 639516b16..ff9b56b86 100644 --- a/src/network/server.hpp +++ b/src/network/server.hpp @@ -52,6 +52,8 @@ protected: std::string m_server_owner_lower_case_name; + std::string m_lower_case_player_names; + uint32_t m_server_id; uint32_t m_server_owner; @@ -89,9 +91,9 @@ protected: bool m_game_started; - std::vector > > m_players; + > > m_players; public: @@ -145,9 +147,8 @@ public: // ------------------------------------------------------------------------ bool isGameStarted() const { return m_game_started; } // ------------------------------------------------------------------------ - const std::vector > >& getPlayers() const - { return m_players; } + const std::vector >& + getPlayers() const { return m_players; } // ------------------------------------------------------------------------ void setServerId(unsigned id) { m_server_id = id; } // ------------------------------------------------------------------------ @@ -158,18 +159,13 @@ public: bool searchByName(const std::string& lower_case_word) { auto list = StringUtils::split(lower_case_word, ' ', false); - bool server_name_found = false; + bool server_name_found = true; for (auto& word : list) { - server_name_found = - m_lower_case_name.find(word) != std::string::npos; - if (server_name_found) - break; - for (auto& p : m_players) - { - if (p.first.find(word) != std::string::npos) - return true; - } + const std::string& for_search = m_lower_case_name + + m_lower_case_player_names; + server_name_found = server_name_found && + for_search.find(word) != std::string::npos; } return server_name_found; } diff --git a/src/states_screens/dialogs/server_info_dialog.cpp b/src/states_screens/dialogs/server_info_dialog.cpp index 84e50b0e7..5acd5eb3d 100644 --- a/src/states_screens/dialogs/server_info_dialog.cpp +++ b/src/states_screens/dialogs/server_info_dialog.cpp @@ -108,9 +108,8 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr server) row.push_back(ListWidget::ListCell(_("Time played"), -1, 1, true)); player_list->addItem("player", row); - for (auto& p : players) + for (auto& r : players) { - auto& r = p.second; row.clear(); row.push_back(ListWidget::ListCell( std::get<0>(r) == -1 ? L"-" :