Add the possibility to correct invalid reverse at server side

This commit is contained in:
Benau 2018-12-21 21:55:55 +08:00
parent 2eba8c179f
commit a85dbcc0f7
4 changed files with 20 additions and 4 deletions

View File

@ -453,7 +453,7 @@ void ClientLobby::receivePlayerVote(Event* event)
vote.m_track_name.c_str());
}
addVote(host_id, vote);
TracksScreen::getInstance()->addVote(host_id);
TracksScreen::getInstance()->addVote(host_id, vote);
TracksScreen::getInstance()->updatePlayerVotes();
} // receivePlayerVote

View File

@ -2033,6 +2033,8 @@ void ServerLobby::handlePlayerVote(Event* event)
}
else if (vote.m_num_laps == 0 || vote.m_num_laps > 20)
vote.m_num_laps = (uint8_t)3;
if (!t->reverseAvailable() && vote.m_reverse)
vote.m_reverse = false;
}
else if (race_manager->isSoccerMode())
{
@ -2133,6 +2135,7 @@ bool ServerLobby::handleAllVotes(PeerVote* winner_vote,
std::string top_track = m_default_vote->m_track_name;
int top_laps = m_default_vote->m_num_laps;
bool top_reverse = m_default_vote->m_reverse;
std::map<std::string, unsigned> tracks;
std::map<unsigned, unsigned> laps;
@ -2211,6 +2214,7 @@ bool ServerLobby::handleAllVotes(PeerVote* winner_vote,
}
if (reverse_vote != reverses.end())
{
top_reverse = reverse_vote->first;
reverses_rate = float(reverse_vote->second) / cur_players;
}
@ -2220,7 +2224,9 @@ bool ServerLobby::handleAllVotes(PeerVote* winner_vote,
{
while (it != m_peers_votes.end())
{
if (it->second.m_track_name == top_track)
if (it->second.m_track_name == top_track &&
it->second.m_num_laps == top_laps &&
it->second.m_reverse == top_reverse)
break;
else
it++;

View File

@ -175,6 +175,8 @@ void TracksScreen::tearDown()
{
m_network_tracks = false;
m_selected_track = NULL;
m_laps = NULL;
m_reversed = NULL;
m_quit_server = false;
} // tearDown
@ -678,8 +680,9 @@ void TracksScreen::onUpdate(float dt)
* already mapped, this is ignored (this can happen in case one host changes
* its vote.
* \param host_id Index of the host that is voting.
* \param vote Vote information.
*/
void TracksScreen::addVote(uint32_t host_id)
void TracksScreen::addVote(uint32_t host_id, const PeerVote& vote)
{
auto it = std::find(m_index_to_hostid.begin(), m_index_to_hostid.end(),
host_id);
@ -695,6 +698,11 @@ void TracksScreen::addVote(uint32_t host_id)
SFXManager::get()->quickSound("plopp");
m_index_to_hostid.push_back(host_id);
}
if (host_id == STKHost::get()->getMyHostId() && m_laps && m_reversed)
{
m_laps->setValue(vote.m_num_laps);
m_reversed->setState(vote.m_reverse);
}
} // addVote
// ----------------------------------------------------------------------------

View File

@ -94,13 +94,15 @@ private:
m_timer = NULL;
m_winning_index = std::numeric_limits<uint32_t>::max();
m_vote_list = NULL;
m_reversed = NULL;
m_laps = NULL;
}
// ------------------------------------------------------------------------
void updateProgressBarText();
public:
void addVote(uint32_t host_id);
void addVote(uint32_t host_id, const PeerVote& vote);
void removeVote(uint32_t host_id);
void setResult(uint32_t winner_host, const PeerVote& winner_vote);