Example #1
0
  private static void showHtml(L2PcInstance activeChar) {
    int worldX = activeChar.getX();
    int worldY = activeChar.getY();
    int geoX = ((((worldX - (-327680)) >> 4) >> 11) + 10);
    int geoY = ((((worldY - (-262144)) >> 4) >> 11) + 10);

    NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
    adminReply.setFile("data/html/admin/zone.htm");

    adminReply.replace(
        "%MAPREGION%",
        "[x:"
            + MapRegionTable.getMapRegionX(activeChar.getX())
            + " y:"
            + MapRegionTable.getMapRegionX(activeChar.getY())
            + "]");
    adminReply.replace("%GEOREGION%", "" + geoX + "_" + geoY);
    adminReply.replace(
        "%CLOSESTTOWN%", MapRegionTable.getInstance().getClosestTownName(activeChar));
    adminReply.replace(
        "%CURRENTLOC%",
        "" + activeChar.getX() + ", " + activeChar.getY() + ", " + activeChar.getZ());

    adminReply.replace(
        "%PVP%", (activeChar.isInsideZone(ZoneId.PVP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%PEACE%",
        (activeChar.isInsideZone(ZoneId.PEACE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%SIEGE%",
        (activeChar.isInsideZone(ZoneId.SIEGE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%MOTHERTREE%",
        (activeChar.isInsideZone(ZoneId.MOTHER_TREE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%CLANHALL%",
        (activeChar.isInsideZone(ZoneId.CLAN_HALL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%NOLANDING%",
        (activeChar.isInsideZone(ZoneId.NO_LANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%WATER%",
        (activeChar.isInsideZone(ZoneId.WATER) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%JAIL%",
        (activeChar.isInsideZone(ZoneId.JAIL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%MONSTERTRACK%",
        (activeChar.isInsideZone(ZoneId.MONSTER_TRACK)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%CASTLE%",
        (activeChar.isInsideZone(ZoneId.CASTLE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%SWAMP%",
        (activeChar.isInsideZone(ZoneId.SWAMP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%NOSUMMONFRIEND%",
        (activeChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%NOSTORE%",
        (activeChar.isInsideZone(ZoneId.NO_STORE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%TOWN%",
        (activeChar.isInsideZone(ZoneId.TOWN) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%HQ%", (activeChar.isInsideZone(ZoneId.HQ) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%DANGERAREA%",
        (activeChar.isInsideZone(ZoneId.DANGER_AREA) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%CASTONARTIFACT%",
        (activeChar.isInsideZone(ZoneId.CAST_ON_ARTIFACT)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%NORESTART%",
        (activeChar.isInsideZone(ZoneId.NO_RESTART) ? "<font color=\"LEVEL\">YES</font>" : "NO"));

    StringBuilder zones = new StringBuilder(100);
    L2WorldRegion region = L2World.getInstance().getRegion(activeChar.getX(), activeChar.getY());
    for (L2ZoneType zone : region.getZones()) {
      if (zone.isCharacterInZone(activeChar)) {
        StringUtil.append(zones, String.valueOf(zone.getId()));
        StringUtil.append(zones, " ");
      }
    }
    adminReply.replace("%ZLIST%", zones.toString());
    activeChar.sendPacket(adminReply);
  }
Example #2
0
  @Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null || activeChar.isTeleporting() || activeChar.inObserverMode()) return;

    final int realX = activeChar.getX();
    final int realY = activeChar.getY();
    int realZ = activeChar.getZ();

    if (Config.DEVELOPER)
      _log.fine(
          "C(S) pos: "
              + _x
              + "("
              + realX
              + ") "
              + _y
              + "("
              + realY
              + ") "
              + _z
              + "("
              + realZ
              + ") / "
              + _heading
              + "("
              + activeChar.getHeading()
              + ")");

    if (_x == 0 && _y == 0) {
      if (realX != 0) // in this case this seems like a client error
      return;
    }

    int dx, dy, dz;
    double diffSq;

    if (activeChar.isInBoat()) {
      if (Config.COORD_SYNCHRONIZE == 2) {
        dx = _x - activeChar.getInVehiclePosition().getX();
        dy = _y - activeChar.getInVehiclePosition().getY();
        dz = _z - activeChar.getInVehiclePosition().getZ();
        diffSq = (dx * dx + dy * dy);
        if (diffSq > 250000)
          sendPacket(
              new GetOnVehicle(activeChar.getObjectId(), _data, activeChar.getInVehiclePosition()));
      }
      return;
    }

    if (activeChar.isFalling(_z)) return; // disable validations during fall to avoid "jumping"

    dx = _x - realX;
    dy = _y - realY;
    dz = _z - realZ;
    diffSq = (dx * dx + dy * dy);

    if (activeChar.isFlying() || activeChar.isInsideZone(ZoneId.WATER)) {
      activeChar.setXYZ(realX, realY, _z);
      if (diffSq > 90000) // validate packet, may also cause z bounce if close to land
      activeChar.sendPacket(new ValidateLocation(activeChar));
    } else if (diffSq < 360000) // if too large, messes observation
    {
      if (Config.COORD_SYNCHRONIZE == -1) // Only Z coordinate synched to server,
      // mainly used when no geodata but can be used also with geodata
      {
        activeChar.setXYZ(realX, realY, _z);
        return;
      }
      if (Config.COORD_SYNCHRONIZE
          == 1) // Trusting also client x,y coordinates (should not be used with geodata)
      {
        // Heading changed on client = possible obstacle
        if (!activeChar.isMoving() || !activeChar.validateMovementHeading(_heading)) {
          // character is not moving, take coordinates from client
          if (diffSq
              < 2500) // 50*50 - attack won't work fluently if even small differences are corrected
          activeChar.setXYZ(realX, realY, _z);
          else activeChar.setXYZ(_x, _y, _z);
        } else activeChar.setXYZ(realX, realY, _z);

        activeChar.setHeading(_heading);
        return;
      }
      // Sync 2 (or other),
      // intended for geodata. Sends a validation packet to client
      // when too far from server calculated true coordinate.
      // Due to geodata/zone errors, some Z axis checks are made. (maybe a temporary solution)
      // Important: this code part must work together with L2Character.updatePosition
      if (Config.GEODATA > 0 && (diffSq > 250000 || Math.abs(dz) > 200)) {
        if (Math.abs(dz) > 200
            && Math.abs(dz) < 1500
            && Math.abs(_z - activeChar.getClientZ()) < 800) {
          activeChar.setXYZ(realX, realY, _z);
          realZ = _z;
        } else {
          if (Config.DEVELOPER)
            _log.info(activeChar.getName() + ": Synchronizing position Server --> Client");

          activeChar.sendPacket(new ValidateLocation(activeChar));
        }
      }
    }

    activeChar.setClientX(_x);
    activeChar.setClientY(_y);
    activeChar.setClientZ(_z);
    activeChar.setClientHeading(_heading); // No real need to validate heading.
    activeChar.setLastServerPosition(realX, realY, realZ);
  }