From 042af60417c91412f08e809ce16d978121f8706d Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 25 Mar 2019 01:53:48 +0800 Subject: [PATCH] Clean up icon handling, split spectate icon out of waiting --- src/network/protocols/client_lobby.cpp | 25 +++++++++++-------------- src/network/protocols/server_lobby.cpp | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index cabf7ac71..7c7f9ac24 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -735,29 +735,26 @@ void ClientLobby::updatePlayerList(Event* event) lp.m_local_player_id = local_id; data.decodeStringW(&lp.m_user_name); total_players += lp.m_user_name; - uint8_t waiting_and_spectator = data.getUInt8(); - bool is_peer_waiting_for_game = waiting_and_spectator == 1; - bool is_spectator = waiting_and_spectator == 2; - bool is_peer_server_owner = data.getUInt8() == 1; + uint8_t boolean_combine = data.getUInt8(); + bool is_peer_waiting_for_game = (boolean_combine & 1) == 1; + bool is_spectator = ((boolean_combine >> 1) & 1) == 1; + bool is_peer_server_owner = ((boolean_combine >> 2) & 1) == 1; + bool ready = ((boolean_combine >> 3) & 1) == 1; // icon to be used, see NetworkingLobby::loadedFromFile lp.m_icon_id = is_peer_server_owner ? 0 : lp.m_online_id != 0 /*if online account*/ ? 1 : 2; - if (waiting) - { - if (is_spectator) - lp.m_icon_id = 5; - else if (!is_peer_waiting_for_game) - lp.m_icon_id = 3; - } + if (waiting && !is_peer_waiting_for_game) + lp.m_icon_id = 3; + if (is_spectator) + lp.m_icon_id = 5; + if (ready) + lp.m_icon_id = 4; lp.m_difficulty = (PerPlayerDifficulty)data.getUInt8(); if (lp.m_difficulty == PLAYER_DIFFICULTY_HANDICAP) { lp.m_user_name = _("%s (handicapped)", lp.m_user_name); } lp.m_kart_team = (KartTeam)data.getUInt8(); - bool ready = data.getUInt8() == 1; - if (ready) - lp.m_icon_id = 4; if (lp.m_host_id == STKHost::get()->getMyHostId()) { if (is_peer_server_owner) diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 0d021a94f..e5408368a 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -2358,22 +2358,24 @@ void ServerLobby::updatePlayerList(bool update_when_reset_server) .addUInt8(profile->getLocalPlayerId()) .encodeString(profile->getName()); std::shared_ptr p = profile->getPeer(); - pl->addUInt8((uint8_t) - (p && p->isWaitingForGame() ? 1 : p && p->isSpectator() ? 2 : 0)); - uint8_t server_owner = 0; + uint8_t boolean_combine = 0; + if (p && p->isWaitingForGame()) + boolean_combine |= 1; + if (p && p->isSpectator()) + boolean_combine |= (1 << 1); if (p && m_server_owner_id.load() == p->getHostId()) - server_owner = 1; - pl->addUInt8(server_owner); + boolean_combine |= (1 << 2); + if (ServerConfig::m_owner_less && !game_started && + m_peers_ready.find(p) != m_peers_ready.end() && + m_peers_ready.at(p)) + boolean_combine |= (1 << 3); + pl->addUInt8(boolean_combine); pl->addUInt8(profile->getPerPlayerDifficulty()); if (ServerConfig::m_team_choosing && race_manager->teamEnabled()) pl->addUInt8(profile->getTeam()); else pl->addUInt8(KART_TEAM_NONE); - uint8_t ready = (!game_started && - m_peers_ready.find(p) != m_peers_ready.end() && - m_peers_ready.at(p)) ? 1 : 0; - pl->addUInt8(ready); pl->encodeString(profile->getCountryId()); }