From fc66d120d7f43e7c54e31159dfe435aaa2d88388 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 17 Jun 2020 21:54:08 -0700 Subject: [PATCH] Filled in some of anonymous PacketHandler within Main to process some packet types --- .../src/com/riiablo/server/netty/Main.java | 29 ++++++++++++++++++- .../riiablo/server/netty/PacketHandler.java | 2 -- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/server/netty/src/com/riiablo/server/netty/Main.java b/server/netty/src/com/riiablo/server/netty/Main.java index 39ce1944..e0cf604d 100644 --- a/server/netty/src/com/riiablo/server/netty/Main.java +++ b/server/netty/src/com/riiablo/server/netty/Main.java @@ -26,9 +26,12 @@ import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration; import com.riiablo.Riiablo; import com.riiablo.codec.Animation; +import com.riiablo.net.packet.netty.Connection; +import com.riiablo.net.packet.netty.Disconnect; import com.riiablo.net.packet.netty.Header; import com.riiablo.net.packet.netty.Netty; import com.riiablo.net.packet.netty.NettyData; +import com.riiablo.net.packet.netty.Ping; public class Main extends ApplicationAdapter { private static final String TAG = "Server"; @@ -75,11 +78,35 @@ public class Main extends ApplicationAdapter { protected void initChannel(DatagramChannel ch) { ch.pipeline() .addLast(new PacketHandler() { - final String TAG = "abstract PacketHandler"; + final String TAG = "PacketHandler$1"; @Override protected void processPacket(ChannelHandlerContext ctx, Netty netty) { Gdx.app.debug(TAG, "Processing packet..."); + byte dataType = netty.dataType(); + if (0 <= dataType && dataType < NettyData.names.length) { + Gdx.app.debug(TAG, "dataType=" + NettyData.name(dataType)); + } + switch (dataType) { + case NettyData.Connection: { + Connection packet = (Connection) netty.data(new Connection()); + break; + } + case NettyData.Disconnect: { + Disconnect packet = (Disconnect) netty.data(new Disconnect()); + break; + } + case NettyData.Ping: { + Ping ping = (Ping) netty.data(new Ping()); + break; + } + default: + if (0 <= dataType && dataType < NettyData.names.length) { + Gdx.app.error(TAG, "Ignoring packet /w data type " + dataType + " (" + NettyData.name(dataType) + ")"); + } else { + Gdx.app.error(TAG, "Ignoring packet /w data type " + dataType); + } + } } }) ; diff --git a/server/netty/src/com/riiablo/server/netty/PacketHandler.java b/server/netty/src/com/riiablo/server/netty/PacketHandler.java index 6039d769..68a74daa 100644 --- a/server/netty/src/com/riiablo/server/netty/PacketHandler.java +++ b/server/netty/src/com/riiablo/server/netty/PacketHandler.java @@ -13,7 +13,6 @@ import com.badlogic.gdx.Gdx; import com.riiablo.net.packet.netty.Header; import com.riiablo.net.packet.netty.Netty; -import com.riiablo.net.packet.netty.NettyData; public abstract class PacketHandler implements ChannelInboundHandler { private static final String TAG = "PacketHandler"; @@ -35,7 +34,6 @@ public abstract class PacketHandler implements ChannelInboundHandler { try { ByteBuffer buffer = in.nioBuffer(); Packet packet = Packet.obtain(0, buffer); - Gdx.app.log(TAG, " " + NettyData.name(packet.data.dataType())); processHeader(ctx, packet.data.header()); processPacket(ctx, packet.data); } finally {