Skip to content

Commit

Permalink
Allow morepackets(player) to override the set-back by other checks.
Browse files Browse the repository at this point in the history
This is meant to prevent packet based speeding, employing micro
violations of other checks, in order to erase the morepackets data.
  • Loading branch information
asofold committed Apr 22, 2016
1 parent 067497f commit 6625470
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Expand Up @@ -152,6 +152,19 @@ public static void onReload() {
public float walkSpeed = 0.0f;
public float flySpeed = 0.0f;

/** Count set-back (re-) setting. */
private int setBackResetCount = 0;
/**
* setBackResetCount (incremented) at the time of (re-) setting the ordinary
* set-back.
*/
private int setBackResetTime = 0;
/**
* setBackResetCount (incremented) at the time of (re-) setting the
* morepackets set-back.
*/
private int morePacketsSetBackResetTime = 0;

/**
* Keep track of past moves edge data. First entry always is the last fully
* processed move, or invalid, even during processing. The currently
Expand Down Expand Up @@ -500,6 +513,7 @@ public void setSetBack(final PlayerLocation loc) {
LocUtil.set(setBack, loc);
}
// TODO: Consider adjusting the set-back-y here. Problem: Need to take into account for bounding box (collect max-ground-height needed).
setBackResetTime = ++setBackResetCount;
}

/**
Expand All @@ -513,6 +527,7 @@ public void setSetBack(final Location loc) {
else{
LocUtil.set(setBack, loc);
}
setBackResetTime = ++setBackResetCount;
}

/**
Expand Down Expand Up @@ -561,6 +576,7 @@ public double getSetBackZ() {

public void setSetBackY(final double y) {
setBack.setY(y);
// (Skip setting/increasing the reset count.)
}

/**
Expand Down Expand Up @@ -595,13 +611,24 @@ public boolean hasMorePacketsSetBack() {
return morePacketsSetback != null;
}

/**
* Test if the morepackets set-back is older than the ordinary set-back.
* Does not check for existence of either.
*
* @return
*/
public boolean isMorePacketsSetBackOldest() {
return morePacketsSetBackResetTime < setBackResetTime;
}

public final void setMorePacketsSetBack(final PlayerLocation loc) {
if (morePacketsSetback == null) {
morePacketsSetback = loc.getLocation();
}
else {
LocUtil.set(morePacketsSetback, loc);
}
morePacketsSetBackResetTime = ++setBackResetCount;
}

public final void setMorePacketsSetBack(final Location loc) {
Expand All @@ -611,6 +638,7 @@ public final void setMorePacketsSetBack(final Location loc) {
else {
LocUtil.set(morePacketsSetback, loc);
}
morePacketsSetBackResetTime = ++setBackResetCount;
}

public Location getMorePacketsSetBack() {
Expand Down
Expand Up @@ -700,9 +700,18 @@ else if (checkCf) {
}

// Morepackets.
if (newTo == null && cc.morePacketsCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_MOREPACKETS) && !player.hasPermission(Permissions.MOVING_MOREPACKETS)) {
// If it hasn't been stopped by any other check and is handled by the more packets check, execute it.
newTo = morePackets.check(player, pFrom, pTo, data, cc);
if (cc.morePacketsCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_MOREPACKETS) && !player.hasPermission(Permissions.MOVING_MOREPACKETS)) {
// (Always check morepackets, to avoid packet speeding using micro-violations.)
final Location mpNewTo = morePackets.check(player, pFrom, pTo, data, cc);
if (mpNewTo != null) {
// Only override set-back, if the morepackets set-back location is older/-est.
if (newTo == null || data.isMorePacketsSetBackOldest()) {
if (newTo != null && data.debug) {
debug(player, "Override set-back by the older morepackets set-back.");
}
newTo = mpNewTo;
}
}
} else {
// Otherwise we need to clear their data.
data.clearMorePacketsData();
Expand Down

0 comments on commit 6625470

Please sign in to comment.