From 185bd6a73d997c59217f0fb6b1aab219fcb56e54 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Tue, 23 Jun 2020 20:41:32 -0700 Subject: [PATCH] Roughed out ReliablePacketController#sentAck --- .../com/riiablo/net/reliable/ReliableEndpoint.java | 3 +++ .../net/reliable/ReliablePacketController.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java b/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java index ec632875..1015df12 100644 --- a/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java +++ b/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java @@ -117,5 +117,8 @@ public class ReliableEndpoint implements MessageChannel.PacketTransceiver { public int NUM_FRAGMENTS_SENT; public int NUM_FRAGMENTS_RECEIVED; public int NUM_FRAGMENTS_INVALID; + public int NUM_ACKS_SENT; + public int NUM_ACKS_RECEIVED; + public int NUM_ACKS_INVALID; } } diff --git a/server/netty/src/com/riiablo/net/reliable/ReliablePacketController.java b/server/netty/src/com/riiablo/net/reliable/ReliablePacketController.java index 0b9d93aa..bf5f9788 100644 --- a/server/netty/src/com/riiablo/net/reliable/ReliablePacketController.java +++ b/server/netty/src/com/riiablo/net/reliable/ReliablePacketController.java @@ -51,7 +51,21 @@ public class ReliablePacketController { } public void sendAck(int channelId, DatagramChannel ch) { + int ack, ackBits; + synchronized (receivedPackets) { + ack = receivedPackets.generateAck(); + ackBits = receivedPackets.generateAckBits(ack); + } + ByteBuf packet = ch.alloc().directBuffer(config.packetHeaderSize); + int headerSize = Packet.writeAck(packet, channelId, ack, ackBits); + if (headerSize < 0) { + Log.error(TAG, "failed to write ack"); + ReliableEndpoint.stats.NUM_ACKS_INVALID++; + return; + } + + ch.writeAndFlush(packet); } public int sendPacket(int channelId, DatagramChannel ch, ByteBuf bb) {