Fix ordering issue with new server peers

This commit is contained in:
sfan5 2024-08-21 22:13:03 +02:00
parent 7afa78ec82
commit 1380bf9b88
4 changed files with 9 additions and 62 deletions

@ -436,6 +436,8 @@ void Client::step(float dtime)
}
}
// The issue that made this workaround necessary was fixed in August 2024, but
// it's not like we can remove this code - ever.
if (m_state == LC_Created) {
float &counter = m_connection_reinit_timer;
counter -= dtime;

@ -30,9 +30,10 @@ class PeerHandler
{
public:
PeerHandler() = default;
virtual ~PeerHandler() = default;
// Note: all functions are called from within a Receive() call on the same thread.
/*
This is called after the Peer has been inserted into the
Connection's peer container.
@ -46,22 +47,4 @@ public:
virtual void deletingPeer(IPeer *peer, bool timeout) = 0;
};
enum PeerChangeType : u8
{
PEER_ADDED,
PEER_REMOVED
};
struct PeerChange
{
PeerChange(PeerChangeType t, session_t _peer_id, bool _timeout) :
type(t), peer_id(_peer_id), timeout(_timeout)
{
}
PeerChange() = delete;
PeerChangeType type;
session_t peer_id;
bool timeout;
};
}

@ -623,8 +623,6 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
*/
m_uptime_counter->increment(dtime);
handlePeerChanges();
/*
Update time of day and overall game time
*/
@ -1257,19 +1255,18 @@ void Server::onMapEditEvent(const MapEditEvent &event)
void Server::peerAdded(con::IPeer *peer)
{
verbosestream<<"Server::peerAdded(): peer->id="
<<peer->id<<std::endl;
verbosestream << "Server::peerAdded(): id=" << peer->id << std::endl;
m_peer_change_queue.push(con::PeerChange(con::PEER_ADDED, peer->id, false));
m_clients.CreateClient(peer->id);
}
void Server::deletingPeer(con::IPeer *peer, bool timeout)
{
verbosestream<<"Server::deletingPeer(): peer->id="
<<peer->id<<", timeout="<<timeout<<std::endl;
verbosestream << "Server::deletingPeer(): id=" << peer->id
<< ", timeout=" << timeout << std::endl;
m_clients.event(peer->id, CSE_Disconnect);
m_peer_change_queue.push(con::PeerChange(con::PEER_REMOVED, peer->id, timeout));
DeleteClient(peer->id, timeout ? CDR_TIMEOUT : CDR_LEAVE);
}
bool Server::getClientConInfo(session_t peer_id, con::rtt_stat_type type, float* retval)
@ -1313,34 +1310,6 @@ const ClientDynamicInfo *Server::getClientDynamicInfo(session_t peer_id)
return &client->getDynamicInfo();
}
void Server::handlePeerChanges()
{
while(!m_peer_change_queue.empty())
{
con::PeerChange c = m_peer_change_queue.front();
m_peer_change_queue.pop();
verbosestream<<"Server: Handling peer change: "
<<"id="<<c.peer_id<<", timeout="<<c.timeout
<<std::endl;
switch(c.type)
{
case con::PEER_ADDED:
m_clients.CreateClient(c.peer_id);
break;
case con::PEER_REMOVED:
DeleteClient(c.peer_id, c.timeout?CDR_TIMEOUT:CDR_LEAVE);
break;
default:
FATAL_ERROR("Invalid peer change event received!");
break;
}
}
}
void Server::printToConsoleOnly(const std::string &text)
{
if (m_admin_chat) {

@ -673,13 +673,6 @@ private:
*/
ClientInterface m_clients;
/*
Peer change queue.
Queues stuff from peerAdded() and deletingPeer() to
handlePeerChanges()
*/
std::queue<con::PeerChange> m_peer_change_queue;
std::unordered_map<session_t, std::string> m_formspec_state_data;
/*