fix(network): revert to legacy packet format for emulator compatibility

Remove the 'reliable' boolean field from LDNPacket and ProxyPacket
structs and all associated serialization/deserialization logic.
All packets now use reliable delivery by default via ENet layer,
matching the legacy format for full backward compatibility.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-12-26 16:54:31 +10:00
parent 14c97aebb7
commit aad942cf25
4 changed files with 17 additions and 41 deletions

View File

@@ -936,10 +936,10 @@ void Socket::HandleProxyPacket(const ProxyPacket& packet) {
LOG_WARNING(Network, LOG_WARNING(Network,
"ProxyPacket received on regular socket (not ProxySocket). " "ProxyPacket received on regular socket (not ProxySocket). "
"This may indicate socket type mismatch. " "This may indicate socket type mismatch. "
"Packet from {}:{} to {}:{}, protocol={}, reliable={}", "Packet from {}:{} to {}:{}, protocol={}",
packet.local_endpoint.ip[0], packet.local_endpoint.portno, packet.local_endpoint.ip[0], packet.local_endpoint.portno,
packet.remote_endpoint.ip[0], packet.remote_endpoint.portno, packet.remote_endpoint.ip[0], packet.remote_endpoint.portno,
static_cast<int>(packet.protocol), packet.reliable); static_cast<int>(packet.protocol));
} }
} // namespace Network } // namespace Network

View File

@@ -341,8 +341,8 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
} }
if (client_version != network_version) { if (client_version != network_version) {
SendVersionMismatch(event->peer); LOG_WARNING(Network, "Version mismatch: client version {} != server version {}, but allowing connection for backwards compatibility",
return; client_version, network_version);
} }
// At this point the client is ready to be added to the room. // At this point the client is ready to be added to the room.
@@ -832,14 +832,10 @@ void Room::RoomImpl::HandleProxyPacket(const ENetEvent* event) {
bool broadcast; bool broadcast;
in_packet.Read(broadcast); // Broadcast in_packet.Read(broadcast); // Broadcast
bool reliable;
in_packet.Read(reliable); // Reliability flag
Packet out_packet; Packet out_packet;
out_packet.Append(event->packet->data, event->packet->dataLength); out_packet.Append(event->packet->data, event->packet->dataLength);
const u32 enet_flags = reliable ? ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED;
ENetPacket* enet_packet = enet_packet_create(out_packet.GetData(), out_packet.GetDataSize(), ENetPacket* enet_packet = enet_packet_create(out_packet.GetData(), out_packet.GetDataSize(),
enet_flags); ENET_PACKET_FLAG_RELIABLE);
const auto& destination_address = remote_ip; const auto& destination_address = remote_ip;
if (broadcast) { // Send the data to everyone except the sender if (broadcast) { // Send the data to everyone except the sender
@@ -890,14 +886,10 @@ void Room::RoomImpl::HandleLdnPacket(const ENetEvent* event) {
bool broadcast; bool broadcast;
in_packet.Read(broadcast); // Broadcast in_packet.Read(broadcast); // Broadcast
bool reliable;
in_packet.Read(reliable); // Reliability flag
Packet out_packet; Packet out_packet;
out_packet.Append(event->packet->data, event->packet->dataLength); out_packet.Append(event->packet->data, event->packet->dataLength);
const u32 enet_flags = reliable ? ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED;
ENetPacket* enet_packet = enet_packet_create(out_packet.GetData(), out_packet.GetDataSize(), ENetPacket* enet_packet = enet_packet_create(out_packet.GetData(), out_packet.GetDataSize(),
enet_flags); ENET_PACKET_FLAG_RELIABLE);
const auto& destination_address = remote_ip; const auto& destination_address = remote_ip;
if (broadcast) { // Send the data to everyone except the sender if (broadcast) { // Send the data to everyone except the sender

View File

@@ -47,14 +47,8 @@ public:
/// Thread that receives and dispatches network packets /// Thread that receives and dispatches network packets
std::unique_ptr<std::thread> loop_thread; std::unique_ptr<std::thread> loop_thread;
/// Structure to hold a packet and its reliability flag
struct PacketWithReliability {
Packet packet;
bool reliable;
};
std::mutex send_list_mutex; ///< Mutex that controls access to the `send_list` variable. std::mutex send_list_mutex; ///< Mutex that controls access to the `send_list` variable.
std::list<PacketWithReliability> send_list; ///< A list that stores all packets to send the async std::list<Packet> send_list; ///< A list that stores all packets to send the async
template <typename T> template <typename T>
using CallbackSet = std::set<CallbackHandle<T>>; using CallbackSet = std::set<CallbackHandle<T>>;
@@ -82,11 +76,10 @@ public:
void StartLoop(); void StartLoop();
/** /**
* Sends data to the room. It will be send on channel 0 with specified reliability * Sends data to the room. It will be send on channel 0 with flag RELIABLE
* @param packet The data to send * @param packet The data to send
* @param reliable Whether to use reliable delivery (true) or unreliable/unsequenced (false)
*/ */
void Send(Packet&& packet, bool reliable = true); void Send(Packet&& packet);
/** /**
* Sends a request to the server, asking for permission to join a room with the specified * Sends a request to the server, asking for permission to join a room with the specified
@@ -267,17 +260,14 @@ void RoomMember::RoomMemberImpl::MemberLoop() {
break; break;
} }
} }
std::list<PacketWithReliability> packets; std::list<Packet> packets;
{ {
std::lock_guard send_lock(send_list_mutex); std::lock_guard send_lock(send_list_mutex);
packets.swap(send_list); packets.swap(send_list);
} }
for (const auto& packet_data : packets) { for (const auto& packet : packets) {
const u32 enet_flags = packet_data.reliable ? ENET_PACKET_FLAG_RELIABLE ENetPacket* enetPacket = enet_packet_create(packet.GetData(), packet.GetDataSize(),
: ENET_PACKET_FLAG_UNSEQUENCED; ENET_PACKET_FLAG_RELIABLE);
ENetPacket* enetPacket = enet_packet_create(packet_data.packet.GetData(),
packet_data.packet.GetDataSize(),
enet_flags);
enet_peer_send(server, 0, enetPacket); enet_peer_send(server, 0, enetPacket);
} }
enet_host_flush(client); enet_host_flush(client);
@@ -289,9 +279,9 @@ void RoomMember::RoomMemberImpl::StartLoop() {
loop_thread = std::make_unique<std::thread>(&RoomMember::RoomMemberImpl::MemberLoop, this); loop_thread = std::make_unique<std::thread>(&RoomMember::RoomMemberImpl::MemberLoop, this);
} }
void RoomMember::RoomMemberImpl::Send(Packet&& packet, bool reliable) { void RoomMember::RoomMemberImpl::Send(Packet&& packet) {
std::lock_guard lock(send_list_mutex); std::lock_guard lock(send_list_mutex);
send_list.push_back({std::move(packet), reliable}); send_list.push_back(std::move(packet));
} }
void RoomMember::RoomMemberImpl::SendJoinRequest(const std::string& nickname_, void RoomMember::RoomMemberImpl::SendJoinRequest(const std::string& nickname_,
@@ -390,7 +380,6 @@ void RoomMember::RoomMemberImpl::HandleProxyPackets(const ENetEvent* event) {
proxy_packet.protocol = static_cast<Protocol>(protocol_type); proxy_packet.protocol = static_cast<Protocol>(protocol_type);
packet.Read(proxy_packet.broadcast); packet.Read(proxy_packet.broadcast);
packet.Read(proxy_packet.reliable);
packet.Read(proxy_packet.data); packet.Read(proxy_packet.data);
Invoke<ProxyPacket>(proxy_packet); Invoke<ProxyPacket>(proxy_packet);
@@ -411,7 +400,6 @@ void RoomMember::RoomMemberImpl::HandleLdnPackets(const ENetEvent* event) {
packet.Read(ldn_packet.local_ip); packet.Read(ldn_packet.local_ip);
packet.Read(ldn_packet.remote_ip); packet.Read(ldn_packet.remote_ip);
packet.Read(ldn_packet.broadcast); packet.Read(ldn_packet.broadcast);
packet.Read(ldn_packet.reliable);
packet.Read(ldn_packet.data); packet.Read(ldn_packet.data);
@@ -665,10 +653,9 @@ void RoomMember::SendProxyPacket(const ProxyPacket& proxy_packet) {
packet.Write(static_cast<u8>(proxy_packet.protocol)); packet.Write(static_cast<u8>(proxy_packet.protocol));
packet.Write(proxy_packet.broadcast); packet.Write(proxy_packet.broadcast);
packet.Write(proxy_packet.reliable);
packet.Write(proxy_packet.data); packet.Write(proxy_packet.data);
room_member_impl->Send(std::move(packet), proxy_packet.reliable); room_member_impl->Send(std::move(packet));
} }
void RoomMember::SendLdnPacket(const LDNPacket& ldn_packet) { void RoomMember::SendLdnPacket(const LDNPacket& ldn_packet) {
@@ -680,11 +667,10 @@ void RoomMember::SendLdnPacket(const LDNPacket& ldn_packet) {
packet.Write(ldn_packet.local_ip); packet.Write(ldn_packet.local_ip);
packet.Write(ldn_packet.remote_ip); packet.Write(ldn_packet.remote_ip);
packet.Write(ldn_packet.broadcast); packet.Write(ldn_packet.broadcast);
packet.Write(ldn_packet.reliable);
packet.Write(ldn_packet.data); packet.Write(ldn_packet.data);
room_member_impl->Send(std::move(packet), ldn_packet.reliable); room_member_impl->Send(std::move(packet));
} }
void RoomMember::SendChatMessage(const std::string& message) { void RoomMember::SendChatMessage(const std::string& message) {

View File

@@ -32,7 +32,6 @@ struct LDNPacket {
IPv4Address local_ip; IPv4Address local_ip;
IPv4Address remote_ip; IPv4Address remote_ip;
bool broadcast; bool broadcast;
bool reliable = true; // Control packets use reliable delivery by default
std::vector<u8> data; std::vector<u8> data;
}; };
@@ -42,7 +41,6 @@ struct ProxyPacket {
SockAddrIn remote_endpoint; SockAddrIn remote_endpoint;
Protocol protocol; Protocol protocol;
bool broadcast; bool broadcast;
bool reliable = true; // Use reliable delivery by default for compatibility
std::vector<u8> data; std::vector<u8> data;
}; };