diff --git a/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java b/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java index e1d4df36..f62b0385 100644 --- a/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java +++ b/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java @@ -2,15 +2,23 @@ package com.riiablo.engine.client; import com.google.flatbuffers.ByteBufferUtil; import com.google.flatbuffers.Table; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Arrays; import com.artemis.ComponentMapper; import com.artemis.annotations.All; import com.artemis.annotations.Wire; import com.artemis.systems.IntervalSystem; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.net.Socket; import com.badlogic.gdx.physics.box2d.Body; + import com.riiablo.Riiablo; import com.riiablo.codec.excel.MonStats; import com.riiablo.codec.util.BitStream; @@ -70,13 +78,6 @@ import com.riiablo.util.BufferUtils; import com.riiablo.util.DebugUtils; import com.riiablo.widget.TextArea; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.util.Arrays; - @All public class ClientNetworkReceiver extends IntervalSystem { private static final String TAG = "ClientNetworkReceiver"; @@ -136,7 +137,7 @@ public class ClientNetworkReceiver extends IntervalSystem { if (DEBUG_PACKET) Gdx.app.debug(TAG, p++ + " packet type " + D2GSData.name(d2gs.dataType()) + ":" + size + "B"); process(d2gs); // System.out.println(buffer.position() + "->" + (buffer.position() + size + 4)); - buffer.position(buffer.position() + size + 4); + buffer.position(buffer.position() + size + 4); // advance position passed current packet + size prefix of next packet } } } catch (Throwable t) { diff --git a/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java b/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java index 381fcb45..8bb0423b 100644 --- a/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java +++ b/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java @@ -2,14 +2,22 @@ package com.riiablo.engine.client; import com.google.flatbuffers.ByteBufferUtil; import com.google.flatbuffers.FlatBufferBuilder; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.WritableByteChannel; import com.artemis.ComponentMapper; import com.artemis.annotations.All; import com.artemis.annotations.Wire; import com.artemis.systems.IntervalSystem; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.net.Socket; + import com.riiablo.Riiablo; import com.riiablo.engine.server.component.Angle; import com.riiablo.engine.server.component.CofAlphas; @@ -32,13 +40,6 @@ import com.riiablo.net.packet.d2gs.VelocityP; import com.riiablo.save.CharData; import com.riiablo.util.ArrayUtils; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.nio.channels.WritableByteChannel; - @All public class ClientNetworkSyncronizer extends IntervalSystem { private static final String TAG = "ClientNetworkSyncronizer"; @@ -110,6 +111,7 @@ public class ClientNetworkSyncronizer extends IntervalSystem { WritableByteChannel channelOut = Channels.newChannel(out); channelOut.write(builder.dataBuffer()); + // Before we can connect, we need to wait for our connection ack to be received boolean connected = false; ByteBuffer buffer = ByteBuffer.allocate(1 << 20).order(ByteOrder.LITTLE_ENDIAN); while (!connected) { @@ -127,7 +129,7 @@ public class ClientNetworkSyncronizer extends IntervalSystem { if (!connected) { if (DEBUG_CONNECT) Gdx.app.debug(TAG, "dropping... "); // System.out.println(buffer.position() + "->" + (buffer.position() + size + 4)); - buffer.position(buffer.position() + size + 4); + buffer.position(buffer.position() + size + 4); // advance position passed current packet + size prefix of next packet continue; } Connection connection = (Connection) d2gs.data(new Connection()); @@ -135,7 +137,7 @@ public class ClientNetworkSyncronizer extends IntervalSystem { if (!connected) { if (DEBUG_CONNECT) Gdx.app.debug(TAG, "dropping... "); // System.out.println(buffer.position() + "->" + (buffer.position() + size + 4)); - buffer.position(buffer.position() + size + 4); + buffer.position(buffer.position() + size + 4); // advance position passed current packet + size prefix of next packet continue; }