Skip to content

Commit

Permalink
Make cancelling flying/waiting packets configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Apr 29, 2017
1 parent de0cabd commit c7d7210
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Expand Up @@ -225,14 +225,29 @@ private void onFlyingPacket(final PacketEvent event) {
if (data.debug) {
debug(player, "Incoming packet, still waiting for ACK on outgoing position.");
}
// Don't add to the flying queue for now (assumed invalid).
final AckReference ackReference = data.teleportQueue.getLastAckReference();
if (ackReference.lastOutgoingId != Integer.MIN_VALUE
&& ackReference.lastOutgoingId != ackReference.maxConfirmedId) {
// Still waiting for a 'confirm teleport' packet. More or less safe to cancel this out.
// TODO: Timeout -> either skip cancel or schedule a set back (to last valid pos or other).
// TODO: Config?
cancel = true;
if (cc.supersededFlyingCancelWaiting) {
// Don't add to the flying queue for now (assumed invalid).
final AckReference ackReference = data.teleportQueue.getLastAckReference();
if (ackReference.lastOutgoingId != Integer.MIN_VALUE
&& ackReference.lastOutgoingId != ackReference.maxConfirmedId) {
// Still waiting for a 'confirm teleport' packet. More or less safe to cancel this out.
/*
* TODO: The actual issue with this, apart from
* potential freezing, also concerns gameplay experience
* in case of minor set backs, which also could be
* caused by the server, e.g. with 'moved wrongly' or
* setting players outside of blocks. In this case the
* moves sent before teleport ack would still be valid
* after the teleport, because distances are small. The
* actual solution should still be to a) not have false
* positives b) somehow get rid all the
* position-correction teleporting the server does, for
* the cases a plugin can handle.
*/
// TODO: Timeout -> either skip cancel or schedule a set back (to last valid pos or other).
// TODO: Config?
cancel = true;
}
}
break;
}
Expand Down
Expand Up @@ -58,6 +58,8 @@ public class NetConfig extends ACheckConfig {
/** Maximum distance for lightning effects (squared). */
public final double soundDistanceSq;

public final boolean supersededFlyingCancelWaiting;

public NetConfig(final ConfigFile config) {
super(config, ConfPaths.NET, new String[] {
Permissions.NET_ATTACKFREQUENCY,
Expand Down Expand Up @@ -97,6 +99,8 @@ public NetConfig(final ConfigFile config) {
double dist = config.getDouble(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE);
soundDistanceSq = dist * dist;

supersededFlyingCancelWaiting = config.getBoolean(ConfPaths.NET_SUPERSEDED_FLYING_CANCELWAITING);

}

@Override
Expand Down
Expand Up @@ -732,6 +732,11 @@ public abstract class ConfPaths {
public static final String NET_SOUNDDISTANCE_ACTIVE = NET_SOUNDDISTANCE + "active";
public static final String NET_SOUNDDISTANCE_MAXDISTANCE = NET_SOUNDDISTANCE + "maxdistance";

/** Somehow superseded packets, typically leniency options .*/
private static final String NET_SUPERSEDED = NET + "superseded.";
private static final String NET_SUPERSEDED_FLYING = NET_SUPERSEDED + "flying.";
public static final String NET_SUPERSEDED_FLYING_CANCELWAITING = NET_SUPERSEDED_FLYING + "cancelwaiting";

public static final String STRINGS = "strings";

// Compatibility section (possibly temporary).
Expand Down
Expand Up @@ -520,6 +520,9 @@ public DefaultConfig() {
set(ConfPaths.NET_SOUNDDISTANCE_ACTIVE, true, 785);
set(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE, 320, 785);

// Superseded
set(ConfPaths.NET_SUPERSEDED_FLYING_CANCELWAITING, true, 1090);


// TODO: An extra file might suit these.
final String start = "[player] failed [check]: ";
Expand Down

0 comments on commit c7d7210

Please sign in to comment.