public boolean tooFast(String ip) {
   String[] exclIps = Config.EXCLUDED_IP.split(",");
   for (String exclIp : exclIps) {
     if (ip.equals(exclIp)) return false;
   }
   Long banned = ban.get(ip);
   if (banned != null) {
     if (System.currentTimeMillis() < banned) return true;
     else {
       ban.remove(ip);
       return false;
     }
   }
   Long time = flood.get(ip);
   if (time == null) {
     flood.put(ip, System.currentTimeMillis() + Config.FAST_RECONNECTION_TIME * 1000);
     return false;
   } else {
     if (time > System.currentTimeMillis()) {
       log.info(
           "[AUDIT]FloodProtector:"
               + ip
               + " IP too fast connection attemp. blocked for "
               + Config.WRONG_LOGIN_BAN_TIME
               + " min");
       ban.put(ip, System.currentTimeMillis() + Config.WRONG_LOGIN_BAN_TIME * 60000);
       return true;
     } else return false;
   }
 }
示例#2
0
文件: Fort.java 项目: rean1m5/lucera2
 public boolean updateFunctions(
     L2PcInstance player, int type, int lvl, int lease, long rate, boolean addNew) {
   if (player == null) return false;
   if (_log.isDebugEnabled())
     _log.warn(
         "Called Fort.updateFunctions(int type, int lvl, int lease, long rate, boolean addNew) Owner : "
             + getOwnerId());
   if (lease > 0) {
     if (!player.destroyItemByItemId("Consume", 57, lease, null, true)) return false;
   }
   if (addNew) _function.put(type, new FortFunction(type, lvl, lease, 0, rate, 0, false));
   else {
     if (lvl == 0 && lease == 0) removeFunction(type);
     else {
       int diffLease = lease - _function.get(type).getLease();
       if (_log.isDebugEnabled())
         _log.warn("Called Fort.updateFunctions diffLease : " + diffLease);
       if (diffLease > 0) {
         _function.remove(type);
         _function.put(type, new FortFunction(type, lvl, lease, 0, rate, -1, false));
       } else {
         _function.get(type).setLease(lease);
         _function.get(type).setLvl(lvl);
         _function.get(type).dbSave(false);
       }
     }
   }
   return true;
 }
示例#3
0
文件: Fort.java 项目: rean1m5/lucera2
 /** Load All Functions */
 private void loadFunctions() {
   Connection con = null;
   try {
     PreparedStatement statement;
     ResultSet rs;
     con = L2DatabaseFactory.getInstance().getConnection(con);
     statement = con.prepareStatement("SELECT * FROM fort_functions WHERE fortId = ?");
     statement.setInt(1, getFortId());
     rs = statement.executeQuery();
     while (rs.next()) {
       _function.put(
           rs.getInt("type"),
           new FortFunction(
               rs.getInt("type"),
               rs.getInt("lvl"),
               rs.getInt("lease"),
               0,
               rs.getLong("rate"),
               rs.getLong("endTime"),
               true));
     }
     statement.close();
   } catch (Exception e) {
     _log.fatal("Exception: Fort.loadFunctions(): " + e.getMessage(), e);
   } finally {
     try {
       con.close();
     } catch (Exception e) {
     }
   }
 }
  @Override
  public void loadCraftCooldowns(final Player player) {
    Connection con = null;
    FastMap<Integer, Long> craftCoolDowns = new FastMap<Integer, Long>();
    try {
      con = DatabaseFactory.getConnection();
      PreparedStatement stmt = con.prepareStatement(SELECT_QUERY);

      stmt.setInt(1, player.getObjectId());
      ResultSet rset = stmt.executeQuery();

      while (rset.next()) {
        int delayId = rset.getInt("delay_id");
        long reuseTime = rset.getLong("reuse_time");
        int delay = (int) ((reuseTime - System.currentTimeMillis()) / 1000);

        if (delay > 0) {
          craftCoolDowns.put(delayId, reuseTime);
        }
      }
      player.getCraftCooldownList().setCraftCoolDowns(craftCoolDowns);
      rset.close();
      stmt.close();
    } catch (SQLException e) {
      log.error("LoadcraftCoolDowns", e);
    } finally {
      DatabaseFactory.close(con);
    }
  }
  /**
   * Add VisibleObject to this KnownList.
   *
   * @param object
   */
  protected boolean add(VisibleObject object) {
    if (!isAwareOf(object)) {
      return false;
    }

    if (knownObjects.put(object.getObjectId(), object) == null) {
      if (object instanceof Player) {
        checkKnownPlayersInitialized();
        knownPlayers.put(object.getObjectId(), (Player) object);
      }

      addVisualObject(object);
      return true;
    }

    return false;
  }
示例#6
0
  public Map<K, V> getAll(Collection<K> keys) {
    FastMap<K, V> m = new FastMap<K, V>();
    for (K key : keys) {
      m.put(key, get(key));
    }

    return m;
  }
示例#7
0
  /**
   * @param cooldownId
   * @param time
   */
  public void setSkillCoolDown(int cooldownId, long time) {

    if (cooldownId == 0) {
      return;
    }

    if (skillCoolDowns == null) skillCoolDowns = new FastMap<Integer, Long>().shared();
    skillCoolDowns.put(cooldownId, time);
  }
示例#8
0
  /**
   * This function saves the currentMillis of skill that generated the cooldown of an entire
   * cooldownGroup
   *
   * @param cooldownId
   * @param baseTime
   */
  public void setSkillCoolDownBase(int cooldownId, long baseTime) {

    if (cooldownId == 0) {
      return;
    }

    if (skillCoolDownsBase == null) skillCoolDownsBase = new FastMap<Integer, Long>().shared();
    skillCoolDownsBase.put(cooldownId, baseTime);
  }
示例#9
0
  private void loadData(String SQL) {
    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection(con);
      // L2EMU_EDIT
      PreparedStatement statement = con.prepareStatement(SQL);
      // L2EMU_EDIT
      ResultSet rset = statement.executeQuery();

      while (rset.next()) {
        int chest = rset.getInt("chest");
        int legs = rset.getInt("legs");
        int head = rset.getInt("head");
        int gloves = rset.getInt("gloves");
        int feet = rset.getInt("feet");
        int skill_id = rset.getInt("skill_id");
        int skill_lvl = rset.getInt("skill_lvl");

        // L2EMU_ADD
        int skillset_id = rset.getInt("skillset_id");
        // L2EMU_ADD

        int shield = rset.getInt("shield");
        int shield_skill_id = rset.getInt("shield_skill_id");
        int enchant6skill = rset.getInt("enchant6skill");

        // L2EMU_EDIT
        _armorSets.put(
            chest,
            new L2ArmorSet(
                chest,
                legs,
                head,
                gloves,
                feet,
                skill_id,
                skill_lvl,
                skillset_id,
                shield,
                shield_skill_id,
                enchant6skill));
        // L2EMU_EDIT
      }

      _log.info("ArmorSetsTable: Loaded " + _armorSets.size() + " armor sets.");

      rset.close();
      statement.close();
    } catch (Exception e) {
      _log.warn("Error while loading armor sets " + e.getMessage());
    } finally {
      try {
        if (con != null) con.close();
      } catch (Exception e) {
      }
    }
  }
示例#10
0
 public Object get() {
   FastMap localMap = getLocalMap();
   Object value = localMap.get(this);
   if ((value == null) && !(localMap.containsKey(this))) {
     value = initialValue();
     localMap.put(this, value);
   }
   return value;
 }
  public void addVisualObject(VisibleObject object) {
    if (object instanceof Creature) {
      if (SecurityConfig.INVIS && object instanceof Player) {
        if (!owner.canSee((Player) object)) {
          return;
        }
      }

      if (visualObjects.put(object.getObjectId(), object) == null) {
        if (object instanceof Player) {
          checkVisiblePlayersInitialized();
          visualPlayers.put(object.getObjectId(), (Player) object);
        }
        owner.getController().see(object);
      }
    } else if (visualObjects.put(object.getObjectId(), object) == null) {
      owner.getController().see(object);
    }
  }
示例#12
0
 @Override
 public void updateData(String name) {
   synchronized (this) {
     LongValue val = data.get(name);
     if (val == null) {
       val = new LongValue();
       data.put(name, val);
     }
     val.updateValue();
   }
 }
示例#13
0
 private FastMap newLocalMap() {
   // First, do some cleanup (remove dead threads).
   for (FastMap.Entry e = THREAD_TO_LOCAL_MAP.head(), end = THREAD_TO_LOCAL_MAP.tail();
       (e = (FastMap.Entry) e.getNext()) != end; ) {
     Thread thread = (Thread) e.getKey();
     if (!thread.isAlive()) {
       THREAD_TO_LOCAL_MAP.remove(thread);
     }
   }
   FastMap localMap = new FastMap();
   THREAD_TO_LOCAL_MAP.put(Thread.currentThread(), localMap);
   return localMap;
 }
  @Deprecated
  public boolean addIp_nn(String ip) {
    Long time = flood.get(ip);
    if (time == null || System.currentTimeMillis() - time > Config.FAST_RECONNECTION_TIME) {
      flood.put(ip, System.currentTimeMillis());
      return false;
    }
    Timestamp newTime =
        new Timestamp(System.currentTimeMillis() + Config.WRONG_LOGIN_BAN_TIME * 60000);
    if (!BannedIpController.isBanned(ip)) {
      log.info(
          "[AUDIT]FloodProtector:" + ip + " IP banned for " + Config.WRONG_LOGIN_BAN_TIME + " min");
      return BannedIpController.banIp(ip, newTime);
    }
    // in this case this ip is already banned

    return true;
  }
package isola.helpers;
示例#16
0
  private void loadTable() {

    java.sql.Connection con = null;
    PreparedStatement pstm = null;
    ResultSet rs = null;
    try {

      con = L1DatabaseFactory.getInstance().getConnection();
      pstm = con.prepareStatement("SELECT * FROM ub_settings");
      rs = pstm.executeQuery();
      L1UltimateBattle ub = null;
      while (rs.next()) {

        ub = new L1UltimateBattle();
        ub.setUbId(rs.getInt("ub_id"));
        ub.setMapId(rs.getShort("ub_mapid"));
        ub.setLocX1(rs.getInt("ub_area_x1"));
        ub.setLocY1(rs.getInt("ub_area_y1"));
        ub.setLocX2(rs.getInt("ub_area_x2"));
        ub.setLocY2(rs.getInt("ub_area_y2"));
        ub.setMinLevel(rs.getInt("min_lvl"));
        ub.setMaxLevel(rs.getInt("max_lvl"));
        ub.setMaxPlayer(rs.getInt("max_player"));
        ub.setEnterRoyal(rs.getBoolean("enter_royal"));
        ub.setEnterKnight(rs.getBoolean("enter_knight"));
        ub.setEnterMage(rs.getBoolean("enter_mage"));
        ub.setEnterElf(rs.getBoolean("enter_elf"));
        ub.setEnterDarkelf(rs.getBoolean("enter_darkelf"));
        ub.setEnterDragonknight(rs.getBoolean("enter_dragonknight"));
        ub.setEnterBlackwizard(rs.getBoolean("enter_blackwizard"));
        ub.setEnterMale(rs.getBoolean("enter_male"));
        ub.setEnterFemale(rs.getBoolean("enter_female"));
        ub.setUsePot(rs.getBoolean("use_pot"));
        ub.setHpr(rs.getInt("hpr_bonus"));
        ub.setMpr(rs.getInt("mpr_bonus"));
        ub.resetLoc();

        _ub.put(ub.getUbId(), ub);
      }
    } catch (SQLException e) {
      _log.warning("ubsettings couldnt be initialized:" + e);
    } finally {
      SQLUtil.close(rs);
      SQLUtil.close(pstm);
    }

    // ub_managers load
    try {
      pstm = con.prepareStatement("SELECT * FROM ub_managers");
      rs = pstm.executeQuery();
      L1UltimateBattle ub = null;
      while (rs.next()) {
        ub = getUb(rs.getInt("ub_id"));
        if (ub != null) {
          ub.addManager(rs.getInt("ub_manager_npc_id"));
        }
      }
    } catch (SQLException e) {
      _log.warning("ub_managers couldnt be initialized:" + e);
    } finally {
      SQLUtil.close(rs);
      SQLUtil.close(pstm);
    }

    // ub_times load
    try {
      pstm = con.prepareStatement("SELECT * FROM ub_times");
      rs = pstm.executeQuery();
      L1UltimateBattle ub = null;
      while (rs.next()) {
        ub = getUb(rs.getInt("ub_id"));
        if (ub != null) {
          ub.addUbTime(rs.getInt("ub_time"));
        }
      }
    } catch (SQLException e) {
      _log.warning("ub_times couldnt be initialized:" + e);
    } finally {
      SQLUtil.close(rs, pstm, con);
    }
    _log.config("UB리스트 " + _ub.size() + "건 로드");
  }
示例#17
0
  public void reload() {
    FileFilter filter = new BmpFilter();

    File dir = new File(Config.DATAPACK_ROOT, "data/crests/");

    File[] files = dir.listFiles(filter);
    byte[] content;
    synchronized (this) {
      _loadedFiles = 0;
      _bytesBuffLen = 0;

      _cachePledge.clear();
      _cachePledgeLarge.clear();
      _cacheAlly.clear();
    }

    FastMap<Integer, byte[]> _mapPledge = _cachePledge.getContentMap();
    FastMap<Integer, byte[]> _mapPledgeLarge = _cachePledgeLarge.getContentMap();
    FastMap<Integer, byte[]> _mapAlly = _cacheAlly.getContentMap();

    for (File file : files) {
      RandomAccessFile f = null;
      synchronized (this) {
        try {
          f = new RandomAccessFile(file, "r");
          content = new byte[(int) f.length()];
          f.readFully(content);

          if (file.getName().startsWith("Crest_Large_")) {
            _mapPledgeLarge.put(
                Integer.valueOf(file.getName().substring(12, file.getName().length() - 4)),
                content);
          } else if (file.getName().startsWith("Crest_")) {
            _mapPledge.put(
                Integer.valueOf(file.getName().substring(6, file.getName().length() - 4)), content);
          } else if (file.getName().startsWith("AllyCrest_")) {
            _mapAlly.put(
                Integer.valueOf(file.getName().substring(10, file.getName().length() - 4)),
                content);
          }
          _loadedFiles++;
          _bytesBuffLen += content.length;
        } catch (Exception e) {
          _log.log(Level.WARNING, "Problem with crest bmp file " + e.getMessage(), e);
        } finally {
          try {
            f.close();
          } catch (Exception e1) {
          }
        }
      }
    }

    _log.info(
        "Cache[Crest]: "
            + String.format("%.3f", getMemoryUsage())
            + "MB on "
            + getLoadedFiles()
            + " files loaded. (Forget Time: "
            + (_cachePledge.getForgetTime() / 1000)
            + "s , Capacity: "
            + _cachePledge.capacity()
            + ")");
  }
示例#18
0
  @Override
  public HE_Mesh apply(final HE_Mesh mesh) {
    if (mesh.selectAllBoundaryEdges().numberOfEdges() > 0) {
      throw new IllegalArgumentException("HES_DooSabin only supports closed meshes at this time.");
    }
    Iterator<HE_Face> fItr = mesh.fItr();
    final FastMap<Integer, Integer> halfedgeCorrelation = new FastMap<Integer, Integer>();
    final ArrayList<WB_Point> newVertices = new ArrayList<WB_Point>();
    HE_Face f;
    HE_Halfedge he;
    WB_Point fc;
    int vertexCount = 0;
    double div = 1.0 + 2.0 * edgeFactor + faceFactor;

    if (WB_Epsilon.isZero(div)) {
      div = 1.0;
    }
    if (absolute) {
      div = 4.0;
    }
    while (fItr.hasNext()) {
      f = fItr.next();
      he = f.getHalfedge();
      fc = f.getFaceCenter();
      do {
        final WB_Point p = fc.multAndCopy(faceFactor);
        p.add(he.getVertex());
        p.add(he.getHalfedgeCenter().multAndCopy(edgeFactor));
        p.add(he.getPrevInFace().getHalfedgeCenter().multAndCopy(edgeFactor));
        p.div(div);
        if (absolute) {
          final double dcurrent = WB_Distance.distance(p, he.getVertex());
          p.sub(he.getVertex());
          p.mult(d / dcurrent);
          p.add(he.getVertex());
        }

        halfedgeCorrelation.put(he.key(), vertexCount);
        vertexCount++;

        newVertices.add(p);
        he = he.getNextInFace();
      } while (he != f.getHalfedge());
    }
    final int[][] faces =
        new int[mesh.numberOfFaces() + mesh.numberOfEdges() + mesh.numberOfVertices()][];
    final int[] labels =
        new int[mesh.numberOfFaces() + mesh.numberOfEdges() + mesh.numberOfVertices()];
    final int[] noe = {mesh.numberOfFaces(), mesh.numberOfEdges(), mesh.numberOfVertices()};
    int currentFace = 0;
    fItr = mesh.fItr();
    while (fItr.hasNext()) {
      f = fItr.next();
      faces[currentFace] = new int[f.getFaceOrder()];
      he = f.getHalfedge();
      int i = 0;
      labels[currentFace] = currentFace;
      do {
        faces[currentFace][i] = halfedgeCorrelation.get(he.key());
        he = he.getNextInFace();
        i++;
      } while (he != f.getHalfedge());
      currentFace++;
    }
    final Iterator<HE_Edge> eItr = mesh.eItr();
    HE_Edge e;
    int currentEdge = 0;
    while (eItr.hasNext()) {

      e = eItr.next();
      faces[currentFace] = new int[4];
      faces[currentFace][3] = halfedgeCorrelation.get(e.getHalfedge().key());
      faces[currentFace][2] = halfedgeCorrelation.get(e.getHalfedge().getNextInFace().key());
      faces[currentFace][1] = halfedgeCorrelation.get(e.getHalfedge().getPair().key());
      faces[currentFace][0] =
          halfedgeCorrelation.get(e.getHalfedge().getPair().getNextInFace().key());
      labels[currentFace] = currentEdge;
      currentEdge++;
      currentFace++;
    }
    final Iterator<HE_Vertex> vItr = mesh.vItr();
    HE_Vertex v;
    int currentVertex = 0;
    while (vItr.hasNext()) {
      v = vItr.next();
      faces[currentFace] = new int[v.getVertexOrder()];
      he = v.getHalfedge();
      int i = v.getVertexOrder() - 1;
      do {
        faces[currentFace][i] = halfedgeCorrelation.get(he.key());
        he = he.getNextInVertex();
        i--;
      } while (he != v.getHalfedge());
      labels[currentFace] = currentVertex;
      currentVertex++;
      currentFace++;
    }
    final HEC_FromFacelist fl =
        new HEC_FromFacelist().setFaces(faces).setVertices(newVertices).setDuplicate(false);
    mesh.set(fl.create());
    fItr = mesh.fItr();
    currentFace = 0;
    faceFaces = new HE_Selection(mesh);
    edgeFaces = new HE_Selection(mesh);
    vertexFaces = new HE_Selection(mesh);
    while (fItr.hasNext()) {
      f = fItr.next();
      f.setLabel(labels[currentFace]);
      if (currentFace < noe[0]) {
        faceFaces.add(f);
      } else if (currentFace < noe[0] + noe[1]) {
        edgeFaces.add(f);
      } else {
        vertexFaces.add(f);
      }
      currentFace++;
    }

    return mesh;
  }
示例#19
0
 /**
  * Add AionObject to this region objects list.
  *
  * @param object
  */
 void add(VisibleObject object) {
   objects.put(object.getObjectId(), object);
 }
示例#20
0
  /*
   * (non-Javadoc)
   *
   * @see wblut.hemesh.HE_Modifier#apply(wblut.hemesh.HE_Mesh)
   */
  @Override
  public HE_Mesh apply(final HE_Mesh mesh) {
    cut = new HE_Selection(mesh);
    cutEdges = new HE_Selection(mesh);
    // no plane defined
    if (P == null) {
      return mesh;
    }

    // empty mesh
    if (mesh.getNumberOfVertices() == 0) {
      return mesh;
    }

    // check if plane intersects mesh
    final WB_Plane lP = new WB_Plane(P.getNormal(), P.d() + offset);
    if (!WB_Intersection.checkIntersection3D(mesh.getAABB(), lP)) {
      return mesh;
    }
    final WB_AABBTree tree = new WB_AABBTree(mesh, 64);
    final HE_Selection faces = new HE_Selection(mesh);
    faces.addFaces(HE_Intersection.getPotentialIntersectedFaces(tree, lP));
    faces.collectVertices();
    faces.collectEdgesByFace();
    WB_Classification tmp;
    final HashMap<Long, WB_Classification> vertexClass = new HashMap<Long, WB_Classification>();
    HE_Vertex v;
    final Iterator<HE_Vertex> vItr = faces.vItr();
    while (vItr.hasNext()) {
      v = vItr.next();
      tmp = lP.classifyPointToPlane(v);
      vertexClass.put(v.key(), tmp);
    }

    List<HE_Vertex> faceVertices = new ArrayList<HE_Vertex>();
    final HE_Selection split = new HE_Selection(mesh);

    final FastMap<Long, Double> edgeInt = new FastMap<Long, Double>();
    final Iterator<HE_Halfedge> eItr = faces.eItr();
    HE_Halfedge e;
    while (eItr.hasNext()) {
      e = eItr.next();
      if (vertexClass.get(e.getStartVertex().key()) == WB_Classification.ON) {
        if (vertexClass.get(e.getEndVertex().key()) == WB_Classification.ON) {
          cutEdges.add(e);
          e.setInternalLabel(1);
          e.getPair().setInternalLabel(1);
        } else {
          edgeInt.put(e.key(), 0.0);
        }
      } else if (vertexClass.get(e.getStartVertex().key()) == WB_Classification.BACK) {
        if (vertexClass.get(e.getEndVertex().key()) == WB_Classification.ON) {
          edgeInt.put(e.key(), 1.0);
        } else if (vertexClass.get(e.getEndVertex().key()) == WB_Classification.FRONT) {
          edgeInt.put(e.key(), HE_Intersection.getIntersection(e, lP));
        }
      } else {
        if (vertexClass.get(e.getEndVertex().key()) == WB_Classification.ON) {
          edgeInt.put(e.key(), 1.0);
        } else if (vertexClass.get(e.getEndVertex().key()) == WB_Classification.BACK) {
          edgeInt.put(e.key(), HE_Intersection.getIntersection(e, lP));
        }
      }
    }

    for (final Map.Entry<Long, Double> en : edgeInt.entrySet()) {
      final HE_Halfedge ce = mesh.getHalfedgeByKey(en.getKey());
      final double u = en.getValue();
      if (ce.getFace() != null) {

        split.add(ce.getFace());
      }
      if (ce.getPair().getFace() != null) {

        split.add(ce.getPair().getFace());
      }
      if (u == 0.0) {

        split.add(ce.getStartVertex());

      } else if (u == 1.0) {

        split.add(ce.getEndVertex());

      } else {
        split.add(mesh.splitEdge(ce, u).vItr().next());
      }
    }
    HE_Face f;
    final Iterator<HE_Face> fItr = split.fItr();
    while (fItr.hasNext()) {
      f = fItr.next();
      faceVertices = f.getFaceVertices();
      int firstVertex = -1;
      int secondVertex = -1;
      final int n = faceVertices.size();
      for (int j = 0; j < n; j++) {
        v = faceVertices.get(j);
        if (split.contains(v)) {
          if (firstVertex == -1) {
            firstVertex = j;
            j++; // if one cut point is found, skip next point.
            // There should be at least one other vertex in
            // between for a proper cut.
          } else {
            secondVertex = j;
            break;
          }
        }
      }
      if ((firstVertex != -1) && (secondVertex != -1)) {
        cut.add(f);
        final HE_Selection out =
            mesh.splitFace(f, faceVertices.get(firstVertex), faceVertices.get(secondVertex));
        final HE_Face nf = out.fItr().next();
        cut.add(nf);
        final HE_Halfedge ne = out.eItr().next();
        ne.setInternalLabel(1);
        cutEdges.add(ne);
      }
    }

    return mesh;
  }