From 2f066cbd0fefe54050d8df82ed1efbe9ce7a2c30 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 24 Jun 2020 12:19:31 -0700 Subject: [PATCH] Created PacketSender abstraction to send Flatbuffer data using any protocol --- server/netty/src/com/riiablo/net/PacketSender.java | 8 ++++++++ .../src/com/riiablo/net/reliable/ReliableEndpoint.java | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 server/netty/src/com/riiablo/net/PacketSender.java diff --git a/server/netty/src/com/riiablo/net/PacketSender.java b/server/netty/src/com/riiablo/net/PacketSender.java new file mode 100644 index 00000000..8180f32f --- /dev/null +++ b/server/netty/src/com/riiablo/net/PacketSender.java @@ -0,0 +1,8 @@ +package com.riiablo.net; + +import java.nio.ByteBuffer; + +public interface PacketSender { + void sendMessage(ByteBuffer bb); + void sendMessage(T qos, ByteBuffer bb); +} diff --git a/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java b/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java index 4587720f..73a573f3 100644 --- a/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java +++ b/server/netty/src/com/riiablo/net/reliable/ReliableEndpoint.java @@ -10,12 +10,13 @@ import java.nio.ByteBuffer; import org.apache.commons.lang3.Validate; import com.riiablo.net.PacketProcessor; +import com.riiablo.net.PacketSender; import com.riiablo.net.reliable.channel.ReliableMessageChannel; import com.riiablo.net.reliable.channel.UnreliableMessageChannel; import com.riiablo.net.reliable.channel.UnreliableOrderedMessageChannel; import com.riiablo.util.EnumIntMap; -public class ReliableEndpoint implements MessageChannel.PacketTransceiver { +public class ReliableEndpoint implements PacketSender, MessageChannel.PacketTransceiver { private static final String TAG = "ReliableEndpoint"; private static final boolean DEBUG = true; @@ -62,6 +63,13 @@ public class ReliableEndpoint implements MessageChannel.PacketTransceiver { for (MessageChannel mc : channels) if (mc != null) mc.update(delta, channel); } + @Override + public void sendMessage(ByteBuffer bb) { + if (DEBUG_SEND) Log.debug(TAG, "sendMessage (auto)"); + sendMessage(QoS.Reliable, bb); + } + + @Override public void sendMessage(QoS qos, ByteBuffer bb) { if (DEBUG_SEND) Log.debug(TAG, "sendMessage"); if (DEBUG_QOS) Log.debug(TAG, "sending message with %s QoS (0x%02x)", qos, qos.ordinal());