Fix ranked server going back to lobby
This commit is contained in:
parent
4ce5678fd6
commit
918d762893
@ -2116,9 +2116,10 @@ void ServerLobby::connectionRequested(Event* event)
|
||||
// Reject non-valiated player joinning if WAN server and not disabled
|
||||
// encforement of validation, unless it's player from localhost or lan
|
||||
// And no duplicated online id or split screen players in ranked server
|
||||
std::set<uint32_t> all_online_ids =
|
||||
STKHost::get()->getAllPlayerOnlineIds();
|
||||
bool duplicated_ranked_player =
|
||||
m_ranked_players.find(online_id) != m_ranked_players.end() &&
|
||||
!m_ranked_players.at(online_id).expired();
|
||||
all_online_ids.find(online_id) != all_online_ids.end();
|
||||
|
||||
if (((encrypted_size == 0 || online_id == 0) &&
|
||||
!(peer->getAddress().isPublicAddressLocalhost() ||
|
||||
@ -2177,9 +2178,10 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
|
||||
}
|
||||
|
||||
// Check again for duplicated player in ranked server
|
||||
std::set<uint32_t> all_online_ids =
|
||||
STKHost::get()->getAllPlayerOnlineIds();
|
||||
bool duplicated_ranked_player =
|
||||
m_ranked_players.find(online_id) != m_ranked_players.end() &&
|
||||
!m_ranked_players.at(online_id).expired();
|
||||
all_online_ids.find(online_id) != all_online_ids.end();
|
||||
if (ServerConfig::m_ranked && duplicated_ranked_player)
|
||||
{
|
||||
NetworkString* message = getNetworkString(2);
|
||||
@ -3077,25 +3079,6 @@ void ServerLobby::addWaitingPlayersToGame()
|
||||
auto peer = profile->getPeer();
|
||||
if (!peer || !peer->isValidated())
|
||||
continue;
|
||||
uint32_t online_id = profile->getOnlineId();
|
||||
if (ServerConfig::m_ranked)
|
||||
{
|
||||
bool duplicated_ranked_player =
|
||||
m_ranked_players.find(online_id) != m_ranked_players.end() &&
|
||||
!m_ranked_players.at(online_id).expired();
|
||||
if (duplicated_ranked_player)
|
||||
{
|
||||
NetworkString* message = getNetworkString(2);
|
||||
message->setSynchronous(true);
|
||||
message->addUInt8(LE_CONNECTION_REFUSED)
|
||||
.addUInt8(RR_INVALID_PLAYER);
|
||||
peer->sendPacket(message, true/*reliable*/);
|
||||
peer->reset();
|
||||
delete message;
|
||||
Log::verbose("ServerLobby", "Player refused: invalid player");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
peer->setWaitingForGame(false);
|
||||
if (m_peers_ready.find(peer) == m_peers_ready.end())
|
||||
@ -3107,7 +3090,11 @@ void ServerLobby::addWaitingPlayersToGame()
|
||||
profile->getOnlineId(), peer->getAddress().toString().c_str(),
|
||||
peer->getUserVersion().c_str());
|
||||
}
|
||||
if (ServerConfig::m_ranked)
|
||||
uint32_t online_id = profile->getOnlineId();
|
||||
if (ServerConfig::m_ranked &&
|
||||
(m_ranked_players.find(online_id) == m_ranked_players.end() ||
|
||||
(m_ranked_players.find(online_id) != m_ranked_players.end() &&
|
||||
m_ranked_players.at(online_id).expired())))
|
||||
{
|
||||
getRankingForPlayer(peer->getPlayerProfiles()[0]);
|
||||
}
|
||||
|
@ -1278,7 +1278,7 @@ std::vector<std::shared_ptr<NetworkPlayerProfile> >
|
||||
{
|
||||
std::vector<std::shared_ptr<NetworkPlayerProfile> > p;
|
||||
std::unique_lock<std::mutex> lock(m_peers_mutex);
|
||||
for (auto peer : m_peers)
|
||||
for (auto& peer : m_peers)
|
||||
{
|
||||
if (peer.second->isDisconnected() || !peer.second->isValidated())
|
||||
continue;
|
||||
@ -1289,6 +1289,25 @@ std::vector<std::shared_ptr<NetworkPlayerProfile> >
|
||||
return p;
|
||||
} // getAllPlayerProfiles
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::set<uint32_t> STKHost::getAllPlayerOnlineIds() const
|
||||
{
|
||||
std::set<uint32_t> online_ids;
|
||||
std::unique_lock<std::mutex> lock(m_peers_mutex);
|
||||
for (auto& peer : m_peers)
|
||||
{
|
||||
if (peer.second->isDisconnected() || !peer.second->isValidated())
|
||||
continue;
|
||||
if (!peer.second->getPlayerProfiles().empty())
|
||||
{
|
||||
online_ids.insert(
|
||||
peer.second->getPlayerProfiles()[0]->getOnlineId());
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
return online_ids;
|
||||
} // getAllPlayerOnlineIds
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::shared_ptr<STKPeer> STKHost::findPeerByHostId(uint32_t id) const
|
||||
{
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
|
||||
@ -242,6 +243,8 @@ public:
|
||||
std::vector<std::shared_ptr<NetworkPlayerProfile> >
|
||||
getAllPlayerProfiles() const;
|
||||
// ------------------------------------------------------------------------
|
||||
std::set<uint32_t> getAllPlayerOnlineIds() const;
|
||||
// ------------------------------------------------------------------------
|
||||
std::shared_ptr<STKPeer> findPeerByHostId(uint32_t id) const;
|
||||
// ------------------------------------------------------------------------
|
||||
void sendPacketExcept(STKPeer* peer, NetworkString *data,
|
||||
|
Loading…
Reference in New Issue
Block a user