Ejemplo n.º 1
0
 public static void addBlockBelowInfo(
     final StringBuilder builder, final PlayerLocation loc, final String tag) {
   addBlockInfo(
       builder,
       loc.getBlockCache(),
       loc.getBlockX(),
       loc.getBlockY() - 1,
       loc.getBlockZ(),
       tag + " below");
 }
Ejemplo n.º 2
0
 public static void addBlockBelowInfo(
     final StringBuilder builder, final PlayerLocation loc, final String tag) {
   builder.append(
       tag
           + " below id="
           + loc.getTypeIdBelow()
           + " data="
           + loc.getData(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())
           + " shape="
           + Arrays.toString(
               loc.getBlockCache()
                   .getBounds(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())));
 }
Ejemplo n.º 3
0
 /**
  * Set cached info according to other.<br>
  * Minimal optimizations: take block flags directly, on-ground max/min bounds, only set stairs if
  * not on ground and not reset-condition.
  *
  * @param other
  */
 public void prepare(final PlayerLocation other) {
   this.onGround = other.isOnGround();
   this.inWater = other.isInWater();
   this.inLava = other.isInLava();
   this.inWeb = other.isInWeb();
   this.onClimbable = other.isOnClimbable();
   if (!onGround && !isResetCond()) {
     this.aboveStairs = other.isAboveStairs();
   }
   this.onIce = other.isOnIce();
   this.typeId = other.getTypeId();
   this.typeIdBelow = other.getTypeIdBelow();
   this.notOnGroundMaxY = other.notOnGroundMaxY;
   this.onGroundMinY = other.onGroundMinY;
   this.blockFlags = other.blockFlags; //  Assume set.
 }
Ejemplo n.º 4
0
 /**
  * Add exact coordinates, multiple lines. No leading new line.
  *
  * @param from
  * @param to
  * @param loc Reference location for from, usually Player.getLocation().
  * @param builder
  */
 public static void addMove(
     final PlayerLocation from,
     final PlayerLocation to,
     final Location loc,
     final StringBuilder builder) {
   if (loc != null && !from.isSamePos(loc)) {
     builder.append("Location: ");
     addLocation(loc, builder);
     builder.append("\n");
   }
   addMove(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), builder);
 }
Ejemplo n.º 5
0
  private Location potentialViolation(
      final Player player,
      final Location loc,
      final PlayerLocation from,
      final PlayerLocation to,
      final int manhattan,
      String tags,
      final MovingData data,
      final MovingConfig cc) {
    // Moving into a block, possibly a violation.

    // Check the players location if different from others.
    // (It provides a better set-back for some exploits.)
    final int lbX = loc.getBlockX();
    final int lbY = loc.getBlockY();
    final int lbZ = loc.getBlockZ();
    Location setBackLoc = null; // Alternative to from.getLocation().
    // First check if the player is moving from a passable location.
    // If not, the move might still be allowed, if moving inside of the same block, or from and to
    // have head position passable.
    if (from.isPassable()) {
      // Put one workaround for 1.5 high blocks here:
      if (from.isBlockAbove(to)
          && (BlockProperties.getBlockFlags(to.getTypeId()) & BlockProperties.F_HEIGHT150) != 0) {
        // Check if the move went from inside of the block.
        if (BlockProperties.collidesBlock(
            to.getBlockCache(),
            from.getX(),
            from.getY(),
            from.getZ(),
            from.getX(),
            from.getY(),
            from.getZ(),
            to.getBlockX(),
            to.getBlockY(),
            to.getBlockZ(),
            to.getTypeId())) {
          // Allow moving inside of 1.5 high blocks.
          return null;
        }
      }
      // From should be the set-back.
      tags += "into";
    } else if (BlockProperties.isPassable(
        from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) {
      // Keep loc, because it it is passable.
      tags += "into_shift";
      setBackLoc = loc;
    }
    //				} else if (BlockProperties.isPassableExact(from.getBlockCache(), loc.getX(), loc.getY(),
    // loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) {
    // (Mind that this can be the case on the same block theoretically.)
    // Keep loc as set-back.
    //				}
    else if (!from.isSameBlock(lbX, lbY, lbZ)) {
      // Both loc and from are not passable. Use from as set.back (earliest).
      tags += "cross_shift";
    } else if (manhattan == 1
        && to.isBlockAbove(from)
        && BlockProperties.isPassable(
            from.getBlockCache(),
            from.getX(),
            from.getY() + player.getEyeHeight(),
            from.getZ(),
            from.getTypeId(
                from.getBlockX(),
                Location.locToBlock(from.getY() + player.getEyeHeight()),
                from.getBlockZ()))) {
      //				else if (to.isBlockAbove(from) && BlockProperties.isPassableExact(from.getBlockCache(),
      // from.getX(), from.getY() + player.getEyeHeight(), from.getZ(),
      // from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()),
      // from.getBlockZ()))) {
      // Allow the move up if the head is free.
      // TODO: Better distinguish ray-tracing (through something thin) or check to-head-passable
      // too?
      return null;
    } else if (manhattan > 0) {
      // Otherwise keep from as set-back.
      tags += "cross";
    } else {
      // All blocks are the same, allow the move.
      return null;
    }

    // Discard inconsistent locations.
    // TODO: Might get rid of using the in-between loc - needs use-case checking.
    if (setBackLoc != null
        && (TrigUtil.distance(from, to) > 0.75 || TrigUtil.distance(from, setBackLoc) > 0.125)) {
      setBackLoc = null;
    }

    // Prefer the set-back location from the data.
    if (data.hasSetBack()) {
      // TODO: Review or make configurable.
      final Location ref = data.getSetBack(to);
      if (BlockProperties.isPassable(from.getBlockCache(), ref)
          || setBackLoc == null
          || TrigUtil.distance(from, setBackLoc) > 0.13) {
        //					if (BlockProperties.isPassableExact(from.getBlockCache(), ref)) {
        setBackLoc = ref;
        if (data.debug) {
          NCPAPIProvider.getNoCheatPlusAPI()
              .getLogManager()
              .debug(
                  Streams.TRACE_FILE, player.getName() + " Using set-back location for passable.");
        }
      } else if (data.debug) {
        NCPAPIProvider.getNoCheatPlusAPI()
            .getLogManager()
            .debug(Streams.TRACE_FILE, player.getName() + " Ignoring set-back for passable.");
      }
    }

    // TODO: set data.set-back ? or something: still some aji here.

    // Return the reset position.
    data.passableVL += 1d;
    final ViolationData vd =
        new ViolationData(this, player, data.passableVL, 1, cc.passableActions);
    if (data.debug || vd.needsParameters()) {
      vd.setParameter(
          ParameterName.LOCATION_FROM,
          String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
      vd.setParameter(
          ParameterName.LOCATION_TO,
          String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
      vd.setParameter(
          ParameterName.DISTANCE, String.format(Locale.US, "%.2f", TrigUtil.distance(from, to)));
      // TODO: Consider adding from.getTypeId() too, if blocks differ and non-air.
      vd.setParameter(ParameterName.BLOCK_ID, "" + to.getTypeId());
      if (!tags.isEmpty()) {
        vd.setParameter(ParameterName.TAGS, tags);
      }
    }
    if (executeActions(vd)) {
      // TODO: Consider another set back position for this, also keeping track of players moving
      // around in blocks.
      final Location newTo;
      if (setBackLoc != null) {
        // Ensure the given location is cloned.
        newTo = LocUtil.clone(setBackLoc);
      } else {
        newTo = from.getLocation();
        if (data.debug) {
          NCPAPIProvider.getNoCheatPlusAPI()
              .getLogManager()
              .debug(Streams.TRACE_FILE, player.getName() + " Using from location for passable.");
        }
      }
      newTo.setYaw(to.getYaw());
      newTo.setPitch(to.getPitch());
      return newTo;
    } else {
      // No cancel action set.
      return null;
    }
  }
Ejemplo n.º 6
0
  public Location check(
      final Player player,
      Location loc,
      final PlayerLocation from,
      final PlayerLocation to,
      final MovingData data,
      final MovingConfig cc) {
    // TODO: if (!from.isSameCoords(loc)) {...check passable for loc -> from !?... + sf etc too?}
    // TODO: Future: Account for the players bounding box? [test very-strict setting for at least
    // the end points...]
    String tags = "";
    // Block distances (sum, max) for from-to (not for loc!).
    final int manhattan = from.manhattan(to);
    // Skip moves inside of ignored blocks right away [works as long as we only check between
    // foot-locations].
    if (manhattan <= 1 && BlockProperties.isPassable(from.getTypeId())) {
      // TODO: Monitor: BlockProperties.isPassable checks slightly different than before.
      if (manhattan == 0) {
        return null;
      } else {
        // manhattan == 1
        if (BlockProperties.isPassable(to.getTypeId())) {
          return null;
        }
      }
    }
    boolean toPassable = to.isPassable();
    // General condition check for using ray-tracing.
    if (toPassable
        && cc.passableRayTracingCheck
        && (!cc.passableRayTracingBlockChangeOnly || manhattan > 0)) {
      rayTracing.set(from, to);
      rayTracing.loop();
      if (rayTracing.collides() || rayTracing.getStepsDone() >= rayTracing.getMaxSteps()) {
        final int maxBlockDist = manhattan <= 1 ? manhattan : from.maxBlockDist(to);
        if (maxBlockDist <= 1 && rayTracing.getStepsDone() == 1 && !from.isPassable()) {
          // Redo ray-tracing for moving out of blocks.
          if (collidesIgnoreFirst(from, to)) {
            toPassable = false;
            tags = "raytracing_2x_";
          } else if (data.debug) {
            NCPAPIProvider.getNoCheatPlusAPI()
                .getLogManager()
                .debug(
                    Streams.TRACE_FILE,
                    player.getName() + " passable: allow moving out of a block.");
          }
        } else {
          if (!allowsSplitMove(from, to, manhattan)) {
            toPassable = false;
            tags = "raytracing_";
          }
        }
      }
      // TODO: Future: If accuracy is demanded, also check the head position (or bounding box right
      // away).
      rayTracing.cleanup();
    }

    // TODO: Checking order: If loc is not the same as from, a quick return here might not be
    // wanted.
    if (toPassable) {
      // Quick return.
      // (Might consider if vl>=1: only decrease if from and loc are passable too, though micro...)
      data.passableVL *= 0.99;
      return null;
    } else {
      return potentialViolation(player, loc, from, to, manhattan, tags, data, cc);
    }
  }
Ejemplo n.º 7
0
 /**
  * Test the move split into y-move and horizontal move, provided some pre-conditions are met.
  *
  * @param from
  * @param to
  * @param manhattan
  * @return
  */
 private boolean allowsSplitMove(
     final PlayerLocation from, final PlayerLocation to, int manhattan) {
   final double yDiff = to.getY() - from.getY();
   if (manhattan <= 3 && yDiff > 0.0 && Math.abs(yDiff) < 1.0) {
     // Workaround for client-side calculations not being possible (y vs. horizontal move).
     // TODO: Alternative: Test if "real" ray-tracing would fix it (might not!).
     if (yDiff > 0.0) {
       // y first.
       rayTracing.set(from.getX(), from.getY(), from.getZ(), from.getX(), to.getY(), from.getZ());
       rayTracing.loop();
       if (!rayTracing.collides()) {
         // horizontal second.
         rayTracing.set(from.getX(), to.getY(), from.getZ(), to.getX(), to.getY(), to.getZ());
         rayTracing.loop();
         if (!rayTracing.collides()) {
           return true;
         }
       }
     } else {
       // horizontal first.
       rayTracing.set(from.getX(), from.getY(), from.getZ(), to.getX(), from.getY(), to.getZ());
       rayTracing.loop();
       if (!rayTracing.collides()) {
         // y second.
         rayTracing.set(to.getX(), from.getY(), to.getZ(), to.getX(), to.getY(), to.getZ());
         rayTracing.loop();
         if (!rayTracing.collides()) {
           return true;
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 8
0
 /**
  * Compares exact coordinates (not the world).
  *
  * @param loc
  * @return
  */
 public boolean isSamePos(final PlayerLocation loc) {
   return x == loc.getX() && z == loc.getZ() && y == loc.getY();
 }
Ejemplo n.º 9
0
 /**
  * Check if this location is above the given one (blockY + 1).
  *
  * @param loc
  * @return
  */
 public boolean isBlockAbove(final PlayerLocation loc) {
   return blockY == loc.getBlockY() + 1 && blockX == loc.getBlockX() && blockZ == loc.getBlockZ();
 }
Ejemplo n.º 10
0
 /**
  * Compares block coordinates (not the world).
  *
  * @param other
  * @return
  */
 public final boolean isSameBlock(final PlayerLocation other) {
   return blockX == other.getBlockX()
       && blockZ == other.getBlockZ()
       && blockY == other.getBlockY();
 }
Ejemplo n.º 11
0
 public static void addFormattedLocation(final PlayerLocation loc, final StringBuilder builder) {
   addFormattedLocation(loc.getX(), loc.getY(), loc.getZ(), builder);
 }
Ejemplo n.º 12
0
 /**
  * Output information specific to player-move events.
  *
  * @param player
  * @param from
  * @param to
  * @param mcAccess
  */
 public static void outputMoveDebug(
     final Player player,
     final PlayerLocation from,
     final PlayerLocation to,
     final double maxYOnGround,
     final MCAccess mcAccess) {
   final StringBuilder builder = new StringBuilder(250);
   final Location loc = player.getLocation();
   // TODO: Differentiate debug levels (needs setting up some policy + document in
   // BuildParamteres)?
   if (BuildParameters.debugLevel > 0) {
     builder.append("\n-------------- MOVE --------------\n");
     builder.append(player.getName() + " " + from.getWorld().getName() + ":\n");
     addMove(from, to, loc, builder);
   } else {
     builder.append(player.getName() + " " + from.getWorld().getName() + " ");
     addFormattedMove(from, to, loc, builder);
   }
   final double jump = mcAccess.getJumpAmplifier(player);
   final double speed = mcAccess.getFasterMovementAmplifier(player);
   final double strider = BridgeEnchant.getDepthStriderLevel(player);
   if (BuildParameters.debugLevel > 0) {
     try {
       // TODO: Check backwards compatibility (1.4.2). Remove try-catch
       builder.append(
           "\n(walkspeed=" + player.getWalkSpeed() + " flyspeed=" + player.getFlySpeed() + ")");
     } catch (Throwable t) {
     }
     if (player.isSprinting()) {
       builder.append("(sprinting)");
     }
     if (player.isSneaking()) {
       builder.append("(sneaking)");
     }
     if (player.isBlocking()) {
       builder.append("(blocking)");
     }
     final Vector v = player.getVelocity();
     if (v.lengthSquared() > 0.0) {
       builder.append("(svel=" + v.getX() + "," + v.getY() + "," + v.getZ() + ")");
     }
   }
   if (speed != Double.NEGATIVE_INFINITY) {
     builder.append("(e_speed=" + (speed + 1) + ")");
   }
   final double slow = PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.SLOW);
   if (slow != Double.NEGATIVE_INFINITY) {
     builder.append("(e_slow=" + (slow + 1) + ")");
   }
   if (jump != Double.NEGATIVE_INFINITY) {
     builder.append("(e_jump=" + (jump + 1) + ")");
   }
   if (strider != 0) {
     builder.append("(e_depth_strider=" + strider + ")");
   }
   // Print basic info first in order
   NCPAPIProvider.getNoCheatPlusAPI()
       .getLogManager()
       .debug(Streams.TRACE_FILE, builder.toString());
   // Extended info.
   if (BuildParameters.debugLevel > 0) {
     builder.setLength(0);
     // Note: the block flags are for normal on-ground checking, not with yOnGrond set to 0.5.
     from.collectBlockFlags(maxYOnGround);
     if (from.getBlockFlags() != 0)
       builder.append(
           "\nfrom flags: "
               + StringUtil.join(BlockProperties.getFlagNames(from.getBlockFlags()), "+"));
     if (from.getTypeId() != 0) addBlockInfo(builder, from, "\nfrom");
     if (from.getTypeIdBelow() != 0) addBlockBelowInfo(builder, from, "\nfrom");
     if (!from.isOnGround() && from.isOnGround(0.5)) builder.append(" (ground within 0.5)");
     to.collectBlockFlags(maxYOnGround);
     if (to.getBlockFlags() != 0)
       builder.append(
           "\nto flags: "
               + StringUtil.join(BlockProperties.getFlagNames(to.getBlockFlags()), "+"));
     if (to.getTypeId() != 0) addBlockInfo(builder, to, "\nto");
     if (to.getTypeIdBelow() != 0) addBlockBelowInfo(builder, to, "\nto");
     if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)");
     NCPAPIProvider.getNoCheatPlusAPI()
         .getLogManager()
         .debug(Streams.TRACE_FILE, builder.toString());
   }
 }
Ejemplo n.º 13
0
  private Location potentialViolation(
      final Player player,
      Location loc,
      final PlayerLocation from,
      final PlayerLocation to,
      final int manhattan,
      String tags,
      final MovingData data,
      final MovingConfig cc) {
    // Moving into a block, possibly a violation.

    // Check the players location if different from others.
    // (It provides a better set-back for some exploits.)
    final int lbX = loc.getBlockX();
    final int lbY = loc.getBlockY();
    final int lbZ = loc.getBlockZ();
    // First check if the player is moving from a passable location.
    // If not, the move might still be allowed, if moving inside of the same block, or from and to
    // have head position passable.
    if (from.isPassable()) {
      // Put one workaround for 1.5 high blocks here:
      if (from.isBlockAbove(to)
          && (BlockProperties.getBlockFlags(to.getTypeId()) & BlockProperties.F_HEIGHT150) != 0) {
        // Check if the move went from inside of the block.
        if (BlockProperties.collidesBlock(
            to.getBlockCache(),
            from.getX(),
            from.getY(),
            from.getZ(),
            from.getX(),
            from.getY(),
            from.getZ(),
            to.getBlockX(),
            to.getBlockY(),
            to.getBlockZ(),
            to.getTypeId())) {
          // Allow moving inside of 1.5 high blocks.
          return null;
        }
      }
      // From should be the set-back.
      loc = null;
      tags += "into";
    } else if (BlockProperties.isPassable(
        from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) {
      tags += "into_shift";
    }
    //				} else if (BlockProperties.isPassableExact(from.getBlockCache(), loc.getX(), loc.getY(),
    // loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) {
    // (Mind that this can be the case on the same block theoretically.)
    // Keep loc as set-back.
    //				}
    else if (!from.isSameBlock(lbX, lbY, lbZ)) {
      // Otherwise keep loc as set-back.
      tags += "cross_shift";
    } else if (manhattan == 1
        && to.isBlockAbove(from)
        && BlockProperties.isPassable(
            from.getBlockCache(),
            from.getX(),
            from.getY() + player.getEyeHeight(),
            from.getZ(),
            from.getTypeId(
                from.getBlockX(),
                Location.locToBlock(from.getY() + player.getEyeHeight()),
                from.getBlockZ()))) {
      //				else if (to.isBlockAbove(from) && BlockProperties.isPassableExact(from.getBlockCache(),
      // from.getX(), from.getY() + player.getEyeHeight(), from.getZ(),
      // from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()),
      // from.getBlockZ()))) {
      // Allow the move up if the head is free.
      return null;
    } else if (manhattan > 0) {
      // Otherwise keep from as set-back.
      loc = null;
      tags += "cross";
    } else {
      // All blocks are the same, allow the move.
      return null;
    }

    // Discard inconsistent locations.
    // TODO: Might get rid of using the in-between loc - needs use-case checking.
    if (loc != null
        && (TrigUtil.distance(from, to) > 0.75 || TrigUtil.distance(from, loc) > 0.125)) {
      loc = null;
    }

    // Prefer the set-back location from the data.
    if (data.hasSetBack()) {
      final Location ref = data.getSetBack(to);
      if (BlockProperties.isPassable(from.getBlockCache(), ref)
          || loc == null
          || TrigUtil.distance(from, loc) > 0.13) {
        //					if (BlockProperties.isPassableExact(from.getBlockCache(), ref)) {
        loc = ref;
        if (cc.debug) {
          System.out.println(player.getName() + " Using set-back location for passable.");
        }
      } else if (cc.debug) {
        System.out.println(player.getName() + " Ignoring set-back for passable.");
      }
    }

    // TODO: set data.set-back ? or something: still some aji here.

    // Return the reset position.
    data.passableVL += 1d;
    final ViolationData vd =
        new ViolationData(this, player, data.passableVL, 1, cc.passableActions);
    if (cc.debug || vd.needsParameters()) {
      vd.setParameter(ParameterName.BLOCK_ID, "" + to.getTypeId());
      if (!tags.isEmpty()) {
        vd.setParameter(ParameterName.TAGS, tags);
      }
    }
    if (executeActions(vd)) {
      // TODO: Consider another set back position for this, also keeping track of players moving
      // around in blocks.
      final Location newTo;
      if (loc != null) {
        // Ensure the given location is cloned.
        newTo = LocUtil.clone(loc);
      } else {
        newTo = from.getLocation();
        if (cc.debug) {
          System.out.println(player.getName() + " Using from location for passable.");
        }
      }
      newTo.setYaw(to.getYaw());
      newTo.setPitch(to.getPitch());
      return newTo;
    } else {
      // No cancel action set.
      return null;
    }
  }