mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-09 10:28:25 +07:00
Removed Header table from fbs and inlined fields within the Netty table
This commit is contained in:
parent
101cc92be4
commit
a8fe6bc732
@ -1,45 +0,0 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.riiablo.net.packet.netty;
|
||||
|
||||
import java.nio.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
import com.google.flatbuffers.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Header extends Table {
|
||||
public static Header getRootAsHeader(ByteBuffer _bb) { return getRootAsHeader(_bb, new Header()); }
|
||||
public static Header getRootAsHeader(ByteBuffer _bb, Header obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; vtable_start = bb_pos - bb.getInt(bb_pos); vtable_size = bb.getShort(vtable_start); }
|
||||
public Header __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public int protocol() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) & 0xFF : 0; }
|
||||
public int sequence() { int o = __offset(6); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
public int ack() { int o = __offset(8); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
public int ackBits() { int o = __offset(10); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
|
||||
|
||||
public static int createHeader(FlatBufferBuilder builder,
|
||||
int protocol,
|
||||
int sequence,
|
||||
int ack,
|
||||
int ack_bits) {
|
||||
builder.startObject(4);
|
||||
Header.addAckBits(builder, ack_bits);
|
||||
Header.addAck(builder, ack);
|
||||
Header.addSequence(builder, sequence);
|
||||
Header.addProtocol(builder, protocol);
|
||||
return Header.endHeader(builder);
|
||||
}
|
||||
|
||||
public static void startHeader(FlatBufferBuilder builder) { builder.startObject(4); }
|
||||
public static void addProtocol(FlatBufferBuilder builder, int protocol) { builder.addByte(0, (byte)protocol, (byte)0); }
|
||||
public static void addSequence(FlatBufferBuilder builder, int sequence) { builder.addShort(1, (short)sequence, (short)0); }
|
||||
public static void addAck(FlatBufferBuilder builder, int ack) { builder.addShort(2, (short)ack, (short)0); }
|
||||
public static void addAckBits(FlatBufferBuilder builder, int ackBits) { builder.addInt(3, ackBits, 0); }
|
||||
public static int endHeader(FlatBufferBuilder builder) {
|
||||
int o = builder.endObject();
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
@ -14,26 +14,37 @@ public final class Netty extends Table {
|
||||
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; vtable_start = bb_pos - bb.getInt(bb_pos); vtable_size = bb.getShort(vtable_start); }
|
||||
public Netty __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public Header header() { return header(new Header()); }
|
||||
public Header header(Header obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public byte dataType() { int o = __offset(6); return o != 0 ? bb.get(o + bb_pos) : 0; }
|
||||
public Table data(Table obj) { int o = __offset(8); return o != 0 ? __union(obj, o) : null; }
|
||||
public int protocol() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) & 0xFF : 0; }
|
||||
public int sequence() { int o = __offset(6); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
public int ack() { int o = __offset(8); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
public int ackBits() { int o = __offset(10); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
|
||||
public byte dataType() { int o = __offset(12); return o != 0 ? bb.get(o + bb_pos) : 0; }
|
||||
public Table data(Table obj) { int o = __offset(14); return o != 0 ? __union(obj, o) : null; }
|
||||
|
||||
public static int createNetty(FlatBufferBuilder builder,
|
||||
int headerOffset,
|
||||
int protocol,
|
||||
int sequence,
|
||||
int ack,
|
||||
int ack_bits,
|
||||
byte data_type,
|
||||
int dataOffset) {
|
||||
builder.startObject(3);
|
||||
builder.startObject(6);
|
||||
Netty.addData(builder, dataOffset);
|
||||
Netty.addHeader(builder, headerOffset);
|
||||
Netty.addAckBits(builder, ack_bits);
|
||||
Netty.addAck(builder, ack);
|
||||
Netty.addSequence(builder, sequence);
|
||||
Netty.addDataType(builder, data_type);
|
||||
Netty.addProtocol(builder, protocol);
|
||||
return Netty.endNetty(builder);
|
||||
}
|
||||
|
||||
public static void startNetty(FlatBufferBuilder builder) { builder.startObject(3); }
|
||||
public static void addHeader(FlatBufferBuilder builder, int headerOffset) { builder.addOffset(0, headerOffset, 0); }
|
||||
public static void addDataType(FlatBufferBuilder builder, byte dataType) { builder.addByte(1, dataType, 0); }
|
||||
public static void addData(FlatBufferBuilder builder, int dataOffset) { builder.addOffset(2, dataOffset, 0); }
|
||||
public static void startNetty(FlatBufferBuilder builder) { builder.startObject(6); }
|
||||
public static void addProtocol(FlatBufferBuilder builder, int protocol) { builder.addByte(0, (byte)protocol, (byte)0); }
|
||||
public static void addSequence(FlatBufferBuilder builder, int sequence) { builder.addShort(1, (short)sequence, (short)0); }
|
||||
public static void addAck(FlatBufferBuilder builder, int ack) { builder.addShort(2, (short)ack, (short)0); }
|
||||
public static void addAckBits(FlatBufferBuilder builder, int ackBits) { builder.addInt(3, ackBits, 0); }
|
||||
public static void addDataType(FlatBufferBuilder builder, byte dataType) { builder.addByte(4, dataType, 0); }
|
||||
public static void addData(FlatBufferBuilder builder, int dataOffset) { builder.addOffset(5, dataOffset, 0); }
|
||||
public static int endNetty(FlatBufferBuilder builder) {
|
||||
int o = builder.endObject();
|
||||
return o;
|
||||
|
@ -2,13 +2,6 @@ include "Packets.fbs";
|
||||
|
||||
namespace com.riiablo.net.packet.netty;
|
||||
|
||||
table Header {
|
||||
protocol:uint8;
|
||||
sequence:uint16;
|
||||
ack:uint16;
|
||||
ack_bits:int32;
|
||||
}
|
||||
|
||||
union NettyData {
|
||||
Connection,
|
||||
Disconnect,
|
||||
@ -16,7 +9,13 @@ union NettyData {
|
||||
}
|
||||
|
||||
table Netty {
|
||||
header:Header;
|
||||
// Header
|
||||
protocol:uint8;
|
||||
sequence:uint16;
|
||||
ack:uint16;
|
||||
ack_bits:int32;
|
||||
|
||||
// Content
|
||||
data:NettyData;
|
||||
}
|
||||
|
||||
|
@ -1,126 +0,0 @@
|
||||
package com.riiablo.server.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.internal.TypeParameterMatcher;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import com.riiablo.net.packet.netty.Header;
|
||||
import com.riiablo.net.packet.netty.Netty;
|
||||
|
||||
public abstract class PacketHandler implements ChannelInboundHandler {
|
||||
private static final String TAG = "PacketHandler";
|
||||
|
||||
private final TypeParameterMatcher matcher;
|
||||
|
||||
PacketHandler() {
|
||||
matcher = TypeParameterMatcher.get(DatagramPacket.class);
|
||||
}
|
||||
|
||||
protected boolean acceptInboundMessage(Object msg) throws Exception {
|
||||
return matcher.match(msg);
|
||||
}
|
||||
|
||||
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
|
||||
InetSocketAddress sender = msg.sender();
|
||||
Gdx.app.log(TAG, "channelRead0 Packet from " + sender.getHostName() + ":" + sender.getPort());
|
||||
ByteBuf in = msg.content();
|
||||
try {
|
||||
ByteBuffer buffer = in.nioBuffer();
|
||||
Packet packet = Packet.obtain(0, buffer);
|
||||
processHeader(ctx, packet.data.header());
|
||||
processPacket(ctx, packet.data);
|
||||
} finally {
|
||||
// in.release(); // Automatically released by channelRead() right now
|
||||
}
|
||||
}
|
||||
|
||||
protected void processHeader(ChannelHandlerContext ctx, Header header) throws Exception {
|
||||
Gdx.app.log(TAG, " " + String.format("SEQ:%d ACK:%d ACK_BITS:%08x", header.sequence(), header.ack(), header.ackBits()));
|
||||
}
|
||||
|
||||
protected abstract void processPacket(ChannelHandlerContext ctx, Netty netty) throws Exception;
|
||||
|
||||
@Override
|
||||
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "channelRegistered");
|
||||
ctx.fireChannelRegistered();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "channelUnregistered");
|
||||
ctx.fireChannelUnregistered();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "channelActive");
|
||||
ctx.fireChannelActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "channelInactive");
|
||||
ctx.fireChannelInactive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
Gdx.app.debug(TAG, "channelRead");
|
||||
boolean release = true;
|
||||
try {
|
||||
if (acceptInboundMessage(msg)) {
|
||||
DatagramPacket imsg = (DatagramPacket) msg;
|
||||
channelRead0(ctx, imsg);
|
||||
} else {
|
||||
release = false;
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
} finally {
|
||||
if (release) ReferenceCountUtil.release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "channelReadComplete");
|
||||
ctx.fireChannelReadComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
Gdx.app.debug(TAG, "userEventTriggered");
|
||||
ctx.fireUserEventTriggered(evt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "channelWritabilityChanged");
|
||||
ctx.fireChannelWritabilityChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "handlerAdded");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
Gdx.app.debug(TAG, "handlerRemoved");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
Gdx.app.debug(TAG, "exceptionCaught");
|
||||
ctx.fireExceptionCaught(cause);
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ import java.nio.ByteBuffer;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import com.riiablo.net.packet.netty.Header;
|
||||
import com.riiablo.net.packet.netty.Netty;
|
||||
|
||||
public class ReliableChannelHandler implements ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler {
|
||||
@ -29,9 +28,9 @@ public class ReliableChannelHandler implements ChannelHandler, ChannelInboundHan
|
||||
private static final boolean DEBUG_OUTBOUND = DEBUG && true;
|
||||
|
||||
private final TypeParameterMatcher matcher;
|
||||
private final Header header = new Header();
|
||||
|
||||
int protocol = 0;
|
||||
private static final int PROTOCOL = 0;
|
||||
|
||||
int seq = -1; // 0xFFFFFFFF
|
||||
int ack = -1; // 0xFFFFFFFF
|
||||
int ack_bits = 0;
|
||||
@ -51,16 +50,16 @@ public class ReliableChannelHandler implements ChannelHandler, ChannelInboundHan
|
||||
try {
|
||||
ByteBuffer buffer = in.nioBuffer();
|
||||
Packet packet = Packet.obtain(0, buffer);
|
||||
processHeader(ctx, packet.data.header(header));
|
||||
processHeader(ctx, packet.data);
|
||||
processPacket(ctx, packet.data);
|
||||
} finally {
|
||||
// in.release(); // Automatically released by channelRead() right now
|
||||
}
|
||||
}
|
||||
|
||||
protected void processHeader(ChannelHandlerContext ctx, Header header) throws Exception {
|
||||
Gdx.app.log(TAG, " incoming " + String.format("SEQ:%d ACK:%d ACK_BITS:%08x", header.sequence(), header.ack(), header.ackBits()));
|
||||
int remoteSeq = header.sequence();
|
||||
protected void processHeader(ChannelHandlerContext ctx, Netty netty) throws Exception {
|
||||
Gdx.app.log(TAG, " incoming " + String.format("PROTO:%d SEQ:%d ACK:%d ACK_BITS:%08x", netty.protocol(), netty.sequence(), netty.ack(), netty.ackBits()));
|
||||
int remoteSeq = netty.sequence();
|
||||
if (ack < 0) {
|
||||
ack = remoteSeq;
|
||||
Gdx.app.log(TAG, " init ack=" + ack);
|
||||
@ -100,15 +99,10 @@ public class ReliableChannelHandler implements ChannelHandler, ChannelInboundHan
|
||||
}
|
||||
|
||||
protected void createNetty(FlatBufferBuilder builder, byte data_type, int dataOffset) {
|
||||
int headerOffset = createHeader(builder);
|
||||
int offset = Netty.createNetty(builder, headerOffset, data_type, dataOffset);
|
||||
int offset = Netty.createNetty(builder, PROTOCOL, seq = (seq + 1) & 0xFFFF, ack, ack_bits, data_type, dataOffset);
|
||||
Netty.finishSizePrefixedNettyBuffer(builder, offset);
|
||||
}
|
||||
|
||||
protected int createHeader(FlatBufferBuilder builder) {
|
||||
return Header.createHeader(builder, seq = (seq + 1) & 0xFFFF, ack, ack_bits);
|
||||
}
|
||||
|
||||
protected void channelWrite0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
InetSocketAddress receiver = (InetSocketAddress) ctx.channel().remoteAddress();
|
||||
Gdx.app.log(TAG, "channelWrite0 Packet to " + receiver.getHostName() + ":" + receiver.getPort());
|
||||
@ -121,8 +115,7 @@ public class ReliableChannelHandler implements ChannelHandler, ChannelInboundHan
|
||||
Gdx.app.debug(TAG, "nioBuffer=" + nioBuffer);
|
||||
nioBuffer = ByteBufferUtil.removeSizePrefix(nioBuffer);
|
||||
Netty netty = Netty.getRootAsNetty(nioBuffer);
|
||||
netty.header(header);
|
||||
Gdx.app.log(TAG, " " + String.format("SEQ:%d ACK:%d ACK_BITS:%08x", header.sequence(), header.ack(), header.ackBits()));
|
||||
Gdx.app.log(TAG, " " + String.format("PROTO:%d SEQ:%d ACK:%d ACK_BITS:%08x", netty.protocol(), netty.sequence(), netty.ack(), netty.ackBits()));
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user