Skip to content

Commit

Permalink
Fixes for handling illegal vehicle coordinates.
Browse files Browse the repository at this point in the history
* Only load chunks, if there is no illegal coordinates.
* If there is no valid set-back on receiving illegal coordinates,
attempt to recover from past move / current (bug), or kick.
  • Loading branch information
asofold committed Jun 18, 2016
1 parent d6bb1e8 commit 3073742
Showing 1 changed file with 40 additions and 3 deletions.
Expand Up @@ -359,8 +359,6 @@ private void checkVehicleMove(final Entity vehicle, final EntityType vehicleType
// (Currently always use firstPastMove and vehicleLocation.)
final Location useFrom = LocUtil.set(useLoc1, world, firstPastMove.toIsValid ? firstPastMove.to : firstPastMove.from);
final Location useTo = vehicleLocation;
// Ensure chunks are loaded.
MovingUtil.ensureChunksLoaded(player, useFrom, useTo, firstPastMove, "vehicle move", data, cc);
// Initialize moveInfo.
if (vehicleType == EntityType.PIG) {
// TODO: Special cases by config rather.
Expand All @@ -375,11 +373,18 @@ private void checkVehicleMove(final Entity vehicle, final EntityType vehicleType
// Check coordinates, just in case.
if (checkIllegal(moveInfo.from, moveInfo.to)) {
// Likely superfluous.
// TODO: Obviously applies under unknown conditions.
SetBackEntry newTo = data.vehicleSetBacks.getValidSafeMediumEntry();
if (newTo == null) {
recoverVehicleSetBack(player, vehicle, vehicleLocation, moveInfo, data);
}
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, CheckType.MOVING_VEHICLE) + "Illegal coordinates on checkVehicleMove: from: " + from + " , to: " + to);
setBack(player, vehicle, data.vehicleSetBacks.getValidSafeMediumEntry(), data, cc);
setBack(player, vehicle, newTo, data, cc);
aux.returnVehicleMoveInfo(moveInfo);
return;
}
// Ensure chunks are loaded.
MovingUtil.ensureChunksLoaded(player, useFrom, useTo, firstPastMove, "vehicle move", data, cc);
// Initialize currentMove.
final VehicleMoveData thisMove = data.vehicleMoves.getCurrentMove();
thisMove.set(moveInfo.from, moveInfo.to);
Expand All @@ -392,6 +397,38 @@ private void checkVehicleMove(final Entity vehicle, final EntityType vehicleType
aux.returnVehicleMoveInfo(moveInfo);
}

/**
* Try to recover the vehicle / player position on illegal coordinates.
*
* @param player
* @param moveInfo
* @param data
*/
private void recoverVehicleSetBack(final Player player, final Entity vehicle,
final Location vehicleLocation, final VehicleMoveInfo moveInfo, final MovingData data) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, checkType) + "Illegal coordinates on vehicle moving: world: " + moveInfo.from.getWorldName() + " , from: " + LocUtil.simpleFormat(moveInfo.from) + " , to: " + LocUtil.simpleFormat(moveInfo.to));
// TODO: Kick for illegal moves?
if (moveInfo.from.hasIllegalCoords()) {
// (from is from the past moves usually.)
// Attempt to use the current location.
if (CheckUtils.isBadCoordinate(vehicleLocation.getX(), vehicleLocation.getY(), vehicleLocation.getZ())) {
// Can't recover vehicle coordinates.
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, checkType) + "Could not recover vehicle coordinates. Player will be kicked.");
// Just kick.
player.kickPlayer("Vehicle error.");
}
else {
// Better than nothing.
data.vehicleSetBacks.setDefaultEntry(vehicleLocation);
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, checkType) + "Using the current vehicle location for set-back, due to not having a past location to rely on. This could be a bug.");
}
}
else {
// Perhaps safe to use.
data.vehicleSetBacks.setDefaultEntry(moveInfo.from);
}
}

private boolean checkIllegal(final RichBoundsLocation from, final RichBoundsLocation to) {
// TODO: Only for VehicleMove or not at all (vehicle position is already set to 'to' anyway)?
return from.hasIllegalCoords() || to.hasIllegalCoords();
Expand Down

0 comments on commit 3073742

Please sign in to comment.