Added sendDisconnectPacket function to D2GS TestClient

This commit is contained in:
Collin Smith 2020-06-27 17:06:03 -07:00
parent 26173a8fd1
commit 88b8e7a096

View File

@ -26,6 +26,7 @@ import com.riiablo.net.EndpointedChannelHandler;
import com.riiablo.net.PacketProcessor;
import com.riiablo.net.UnicastEndpoint;
import com.riiablo.net.packet.netty.Connection;
import com.riiablo.net.packet.netty.Disconnect;
import com.riiablo.net.packet.netty.Netty;
import com.riiablo.net.packet.netty.NettyData;
import com.riiablo.net.reliable.QoS;
@ -70,6 +71,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
ChannelFuture f = b.connect("localhost", Main.PORT).sync();
sendConnectionPacket();
sendConnectionPacket();
sendDisconnectPacket();
} catch (Throwable t) {
Gdx.app.error(TAG, t.getMessage(), t);
Gdx.app.exit();
@ -91,6 +93,19 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
endpoint.sendMessage(QoS.Unreliable, builder.dataBuffer());
}
private void sendDisconnectPacket() {
SocketAddress remoteAddress = endpoint.channel().remoteAddress();
Gdx.app.log(TAG, "Sending Disconnect packet to " + remoteAddress);
FlatBufferBuilder builder = new FlatBufferBuilder();
Disconnect.startDisconnect(builder);
int dataOffset = Disconnect.endDisconnect(builder);
int offset = Netty.createNetty(builder, 0L, NettyData.Disconnect, dataOffset);
Netty.finishSizePrefixedNettyBuffer(builder, offset);
endpoint.sendMessage(QoS.Unreliable, builder.dataBuffer());
}
@Override
public void render() {
endpoint.update(Gdx.graphics.getDeltaTime());