Make possible to remove disconnected player vote

This commit is contained in:
Benau 2018-12-07 00:28:49 +08:00
parent 2127105985
commit 7fa92366ed
3 changed files with 14 additions and 7 deletions

View File

@ -455,7 +455,6 @@ void ClientLobby::displayPlayerVote(Event* event)
std::string player_name; std::string player_name;
data.decodeString(&player_name); data.decodeString(&player_name);
uint32_t host_id = data.getUInt32(); uint32_t host_id = data.getUInt32();
player_name += ": ";
std::string track_name; std::string track_name;
data.decodeString(&track_name); data.decodeString(&track_name);
Track* track = track_manager->getTrack(track_name); Track* track = track_manager->getTrack(track_name);
@ -502,7 +501,7 @@ void ClientLobby::displayPlayerVote(Event* event)
vote_msg = _("Track: %s,\nlaps: %d, reversed: %s", vote_msg = _("Track: %s,\nlaps: %d, reversed: %s",
track_readable, lap, rev == 1 ? yes : no); track_readable, lap, rev == 1 ? yes : no);
} }
vote_msg = StringUtils::utf8ToWide(player_name) + vote_msg; vote_msg = StringUtils::utf8ToWide(player_name) + L": " + vote_msg;
TracksScreen::getInstance()->addVoteMessage(player_name + TracksScreen::getInstance()->addVoteMessage(player_name +
StringUtils::toString(host_id), vote_msg); StringUtils::toString(host_id), vote_msg);
} // displayPlayerVote } // displayPlayerVote
@ -527,11 +526,15 @@ void ClientLobby::disconnectedPlayer(Event* event)
unsigned disconnected_player_count = data.getUInt8(); unsigned disconnected_player_count = data.getUInt8();
for (unsigned i = 0; i < disconnected_player_count; i++) for (unsigned i = 0; i < disconnected_player_count; i++)
{ {
core::stringw player_name; std::string name;
data.decodeStringW(&player_name); data.decodeString(&name);
core::stringw player_name = StringUtils::utf8ToWide(name);
core::stringw msg = _("%s disconnected.", player_name); core::stringw msg = _("%s disconnected.", player_name);
uint32_t host_id = data.getUInt32();
// Use the friend icon to avoid an error-like message // Use the friend icon to avoid an error-like message
MessageQueue::add(MessageQueue::MT_FRIEND, msg); MessageQueue::add(MessageQueue::MT_FRIEND, msg);
TracksScreen::getInstance()->removeVote(
name + StringUtils::toString(host_id));
} }
} // disconnectedPlayer } // disconnectedPlayer

View File

@ -1406,7 +1406,7 @@ void ServerLobby::clientDisconnected(Event* event)
for (auto p : players_on_peer) for (auto p : players_on_peer)
{ {
std::string name = StringUtils::wideToUtf8(p->getName()); std::string name = StringUtils::wideToUtf8(p->getName());
msg->encodeString(name); msg->encodeString(name).addUInt32(event->getPeer()->getHostId());
Log::info("ServerLobby", "%s disconnected", name.c_str()); Log::info("ServerLobby", "%s disconnected", name.c_str());
} }

View File

@ -112,10 +112,14 @@ public:
void setVoteTimeout(float timeout); void setVoteTimeout(float timeout);
void addVoteMessage(const std::string& user, void addVoteMessage(const std::string& user_host_id,
const irr::core::stringw& message) const irr::core::stringw& message)
{ {
m_vote_messages[user] = message; m_vote_messages[user_host_id] = message;
}
void removeVote(const std::string& user_host_id)
{
m_vote_messages.erase(user_host_id);
} }
}; };