Add a sequence count to DataPacketFlying.

Set with adding to the flyingQueue.
This commit is contained in:
asofold 2016-06-25 10:57:43 +02:00
parent cce7e76211
commit 2623a1ae5c
3 changed files with 24 additions and 1 deletions

View File

@ -96,6 +96,7 @@ public class MovingFlying extends BaseAdapter {
// Always update last received time.
final NetData data = dataFactory.getData(player);
data.lastKeepAliveTime = time; // Update without much of a contract.
// TODO: Leniency options too (packet order inversion).
if (!cc.flyingFrequencyActive) {
return;
}

View File

@ -82,6 +82,11 @@ public class NetData extends ACheckData {
private final LinkedList<DataPacketFlying> flyingQueue = new LinkedList<DataPacketFlying>();
/** Maximum amount of packets to store. */
private final int flyingQueueMaxSize = 10;
/**
* The maximum of so far already returned sequence values, altered under
* lock.
*/
private long maxSequence = 0;
public NetData(final NetConfig config) {
super(config);
@ -100,7 +105,8 @@ public class NetData extends ACheckData {
}
/**
* Add a packet to the queue (under lock).
* Add a packet to the queue (under lock). The sequence number of the packet
* will be set here, according to a count maintained per-data.
*
* @param packetData
* @return If a packet has been removed due to exceeding maximum size.
@ -108,6 +114,7 @@ public class NetData extends ACheckData {
public boolean addFlyingQueue(final DataPacketFlying packetData) {
boolean res = false;
lock.lock();
packetData.setSequence(++maxSequence);
flyingQueue.addFirst(packetData);
if (flyingQueue.size() > flyingQueueMaxSize) {
flyingQueue.removeLast();

View File

@ -25,6 +25,7 @@ public class DataPacketFlying extends DataLocation {
public final boolean hasPos;
public final boolean hasLook;
public final long time;
private long sequence = 0;
public DataPacketFlying(boolean onGround, long time) {
super(0, 0, 0, 0, 0);
@ -117,4 +118,18 @@ public class DataPacketFlying extends DataLocation {
return builder.toString();
}
/**
* Get the sequence number. This may or may not be set, depending on
* context.
*
* @return
*/
public long getSequence() {
return sequence;
}
public void setSequence(long sequence) {
this.sequence = sequence;
}
}