1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Propagate peer ID change to outgoing reliables (#15680)

Otherwise a desync could ocurr since the server does strict checking.
fixes #15627
This commit is contained in:
sfan5 2025-02-01 13:23:00 +01:00 committed by GitHub
parent 29cfb6efff
commit c0422b18e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 64 additions and 2 deletions

View file

@ -53,6 +53,15 @@ u16 BufferedPacket::getSeqnum() const
return readU16(&data[BASE_HEADER_SIZE + 1]);
}
void BufferedPacket::setSenderPeerId(session_t id)
{
if (size() < BASE_HEADER_SIZE) {
assert(false); // should never happen
return;
}
writeU16(&data[4], id);
}
BufferedPacketPtr makePacket(const Address &address, const SharedBuffer<u8> &data,
u32 protocol_id, session_t sender_peer_id, u8 channel)
{
@ -337,6 +346,13 @@ void ReliablePacketBuffer::insert(BufferedPacketPtr &p_ptr, u16 next_expected)
m_oldest_non_answered_ack = m_list.front()->getSeqnum();
}
void ReliablePacketBuffer::fixPeerId(session_t new_id)
{
MutexAutoLock listlock(m_list_mutex);
for (auto &packet : m_list)
packet->setSenderPeerId(new_id);
}
void ReliablePacketBuffer::incrementTimeouts(float dtime)
{
MutexAutoLock listlock(m_list_mutex);
@ -569,6 +585,13 @@ ConnectionCommandPtr ConnectionCommand::resend_one(session_t peer_id)
return c;
}
ConnectionCommandPtr ConnectionCommand::peer_id_set(session_t own_peer_id)
{
auto c = create(CONNCMD_PEER_ID_SET);
c->peer_id = own_peer_id;
return c;
}
ConnectionCommandPtr ConnectionCommand::send(session_t peer_id, u8 channelnum,
NetworkPacket *pkt, bool reliable)
{
@ -1615,6 +1638,14 @@ void Connection::DisconnectPeer(session_t peer_id)
putCommand(ConnectionCommand::disconnect_peer(peer_id));
}
void Connection::SetPeerID(session_t id)
{
m_peer_id = id;
// fix peer id in existing queued reliable packets
if (id != PEER_ID_INEXISTENT)
putCommand(ConnectionCommand::peer_id_set(id));
}
void Connection::doResendOne(session_t peer_id)
{
assert(peer_id != PEER_ID_INEXISTENT);