From 25e057c08a26ab5839bcf1bf8d85745b03e1ca8e Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sat, 28 Dec 2019 22:45:42 -0800 Subject: [PATCH] Only send connection packets to unconnected players -- prevents flooding until sync packets aggregated --- .../riiablo/engine/client/ClientNetworkSyncronizer.java | 2 +- server/d2gs/src/com/riiablo/server/d2gs/D2GS.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java b/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java index fd6dcd65..f3dca075 100644 --- a/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java +++ b/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java @@ -115,7 +115,7 @@ public class ClientNetworkSyncronizer extends IntervalSystem { while (buffer.hasRemaining()) { int size = ByteBufferUtil.getSizePrefix(buffer); D2GS.getRootAsD2GS(ByteBufferUtil.removeSizePrefix(buffer), d2gs); - if (DEBUG_PACKET) Gdx.app.debug(TAG, "packet type " + D2GSData.name(d2gs.dataType()) + ":" + ByteBufferUtil.getSizePrefix(buffer) + "B"); + if (DEBUG_PACKET) Gdx.app.debug(TAG, "packet type " + D2GSData.name(d2gs.dataType()) + ":" + size + "B"); connected = d2gs.dataType() == D2GSData.Connection; if (!connected) { if (DEBUG_CONNECT) Gdx.app.debug(TAG, "dropping... "); diff --git a/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java b/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java index 686792f5..b318f76b 100644 --- a/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java +++ b/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java @@ -152,7 +152,7 @@ public class D2GS extends ApplicationAdapter { int connected = 0; final BlockingQueue packets = new ArrayBlockingQueue<>(32); - final Collection cache = new ArrayList<>(); + final Collection cache = new ArrayList<>(1024); final BlockingQueue outPackets = new ArrayBlockingQueue<>(1024); final IntIntMap player = new IntIntMap(); @@ -287,7 +287,7 @@ public class D2GS extends ApplicationAdapter { Gdx.app.log(TAG, "assigned " + socket.getRemoteAddress() + " to " + id); Client client = clients[id] = new Client(id, socket); numClients++; - connected |= (1 << id); + //connected |= (1 << id); client.start(); } } catch (Throwable t) { @@ -347,7 +347,7 @@ public class D2GS extends ApplicationAdapter { for (Packet packet : cache) { Gdx.app.log(TAG, "dispatching " + D2GSData.name(packet.data.dataType()) + " packet to " + String.format("0x%08X", packet.id)); for (int i = 0, flag = 1; i < MAX_CLIENTS; i++, flag <<= 1) { - if ((packet.id & flag) == flag && (connected & flag) == flag) { + if ((packet.id & flag) == flag && ((connected & flag) == flag || packet.data.dataType() == D2GSData.Connection)) { Client client = clients[i]; if (client == null) continue; try { @@ -499,6 +499,9 @@ public class D2GS extends ApplicationAdapter { packet.buffer.mark(); out.write(packet.buffer); packet.buffer.reset(); + if ((connected & (1 << id)) == 0 && packet.data.dataType() == D2GSData.Connection) { + connected |= (1 << id); + } } @Override