Warn high ping user earlier
This commit is contained in:
parent
241e0ae772
commit
a7311238cf
@ -590,19 +590,6 @@ void ServerLobby::asynchronousUpdate()
|
||||
|
||||
} // asynchronousUpdate
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ServerLobby::sendBadConnectionMessageToPeer(std::shared_ptr<STKPeer> p)
|
||||
{
|
||||
const unsigned max_ping = ServerConfig::m_max_ping;
|
||||
Log::warn("ServerLobby", "Peer %s cannot catch up with max ping %d.",
|
||||
p->getAddress().toString().c_str(), max_ping);
|
||||
NetworkString* msg = getNetworkString();
|
||||
msg->setSynchronous(true);
|
||||
msg->addUInt8(LE_BAD_CONNECTION);
|
||||
p->sendPacket(msg, /*reliable*/true);
|
||||
delete msg;
|
||||
} // sendBadConnectionMessageToPeer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Simple finite state machine. Once this
|
||||
* is known, register the server and its address with the stk server so that
|
||||
@ -2406,7 +2393,9 @@ void ServerLobby::configPeersStartTime()
|
||||
continue;
|
||||
if (peer->getAveragePing() > max_ping_from_peers)
|
||||
{
|
||||
sendBadConnectionMessageToPeer(peer);
|
||||
Log::warn("ServerLobby",
|
||||
"Peer %s cannot catch up with max ping %d.",
|
||||
peer->getAddress().toString().c_str(), max_ping);
|
||||
continue;
|
||||
}
|
||||
max_ping = std::max(peer->getAveragePing(), max_ping);
|
||||
|
@ -252,7 +252,6 @@ private:
|
||||
double getModeSpread();
|
||||
double scalingValueForTime(double time);
|
||||
void checkRaceFinished();
|
||||
void sendBadConnectionMessageToPeer(std::shared_ptr<STKPeer> p);
|
||||
std::pair<int, float> getHitCaptureLimit(float num_karts);
|
||||
void configPeersStartTime();
|
||||
void updateWaitingPlayers();
|
||||
|
@ -758,18 +758,33 @@ void STKHost::mainLoop()
|
||||
p.second->getPing();
|
||||
const unsigned ap = p.second->getAveragePing();
|
||||
const unsigned max_ping = ServerConfig::m_max_ping;
|
||||
if (ServerConfig::m_kick_high_ping_players &&
|
||||
p.second->isValidated() &&
|
||||
if (p.second->isValidated() &&
|
||||
p.second->getConnectedTime() > 5.0f && ap > max_ping)
|
||||
{
|
||||
Log::info("STKHost", "%s with ping %d is higher than"
|
||||
" %d ms, kick.",
|
||||
p.second->getAddress().toString().c_str(),
|
||||
ap, max_ping);
|
||||
std::lock_guard<std::mutex> lock(m_enet_cmd_mutex);
|
||||
m_enet_cmd.emplace_back(p.second->getENetPeer(),
|
||||
(ENetPacket*)NULL, PDI_BAD_CONNECTION,
|
||||
ECT_DISCONNECT);
|
||||
if (ServerConfig::m_kick_high_ping_players &&
|
||||
!p.second->isDisconnected())
|
||||
{
|
||||
Log::info("STKHost", "%s with ping %d is higher"
|
||||
" than %d ms, kick.",
|
||||
p.second->getAddress().toString().c_str(),
|
||||
ap, max_ping);
|
||||
std::lock_guard<std::mutex> lock(m_enet_cmd_mutex);
|
||||
m_enet_cmd.emplace_back(p.second->getENetPeer(),
|
||||
(ENetPacket*)NULL, PDI_BAD_CONNECTION,
|
||||
ECT_DISCONNECT);
|
||||
}
|
||||
else if (!p.second->hasWarnedForHighPing())
|
||||
{
|
||||
Log::info("STKHost", "%s with ping %d is higher"
|
||||
" than %d ms.",
|
||||
p.second->getAddress().toString().c_str(),
|
||||
ap, max_ping);
|
||||
p.second->setWarnedForHighPing(true);
|
||||
NetworkString msg(PROTOCOL_LOBBY_ROOM);
|
||||
msg.setSynchronous(true);
|
||||
msg.addUInt8(LobbyProtocol::LE_BAD_CONNECTION);
|
||||
p.second->sendPacket(&msg, /*reliable*/true);
|
||||
}
|
||||
}
|
||||
}
|
||||
BareNetworkString ping_packet;
|
||||
|
@ -42,6 +42,7 @@ STKPeer::STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id)
|
||||
m_average_ping.store(0);
|
||||
m_waiting_for_game.store(true);
|
||||
m_disconnected.store(false);
|
||||
m_warned_for_high_ping.store(false);
|
||||
} // STKPeer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -70,6 +70,8 @@ protected:
|
||||
|
||||
std::atomic_bool m_disconnected;
|
||||
|
||||
std::atomic_bool m_warned_for_high_ping;
|
||||
|
||||
/** Host id of this peer. */
|
||||
uint32_t m_host_id;
|
||||
|
||||
@ -187,7 +189,11 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
bool isDisconnected() const { return m_disconnected.load(); }
|
||||
// ------------------------------------------------------------------------
|
||||
void clearAvailableKartIDs() { m_available_kart_ids.clear(); }
|
||||
bool hasWarnedForHighPing() const { return m_warned_for_high_ping.load(); }
|
||||
// ------------------------------------------------------------------------
|
||||
void setWarnedForHighPing(bool val) { m_warned_for_high_ping.store(val); }
|
||||
// ------------------------------------------------------------------------
|
||||
void clearAvailableKartIDs() { m_available_kart_ids.clear(); }
|
||||
// ------------------------------------------------------------------------
|
||||
void addAvailableKartID(unsigned id) { m_available_kart_ids.insert(id); }
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user