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;
   }
 }
Esempio n. 2
0
  /**
   * @param cooldownId
   * @return
   */
  public boolean isSkillDisabled(SkillTemplate template) {

    if (skillCoolDowns == null) return false;

    int cooldownId = template.getCooldownId();
    Long coolDown = skillCoolDowns.get(cooldownId);
    if (coolDown == null) {
      return false;
    }

    if (coolDown < System.currentTimeMillis()) {
      removeSkillCoolDown(cooldownId);
      return false;
    }

    /*
     * Some shared cooldown skills have indipendent and different cooldown they must not be blocked
     */
    if (skillCoolDownsBase != null && skillCoolDownsBase.get(cooldownId) != null) {
      if ((template.getDuration()
              + template.getCooldown() * 100
              + skillCoolDownsBase.get(cooldownId))
          < System.currentTimeMillis()) return false;
    }

    return true;
  }
Esempio n. 3
0
 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;
 }
Esempio n. 4
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;
 }
Esempio n. 5
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();
   }
 }
  @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;
  }
Esempio n. 7
0
 public L2ArmorSet getSet(int chestId) {
   return _armorSets.get(chestId);
 }
Esempio n. 8
0
 public L1UltimateBattle getUb(int ubId) {
   return _ub.get(ubId);
 }
Esempio n. 9
0
 private FastMap getLocalMap() {
   FastMap localMap = (FastMap) THREAD_TO_LOCAL_MAP.get(Thread.currentThread());
   return (localMap != null) ? localMap : newLocalMap();
 }
Esempio n. 10
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;
  }
Esempio n. 11
0
  /**
   * @param cooldownId
   * @return
   */
  public long getSkillCoolDown(int cooldownId) {
    if (skillCoolDowns == null || !skillCoolDowns.containsKey(cooldownId)) return 0;

    return skillCoolDowns.get(cooldownId);
  }
Esempio n. 12
0
 /**
  * Equivalent to {@link #valueOf(CharSequence)} (for J2ME compatibility).
  *
  * @param name the qualified name lexical representation.
  * @see #toString()
  */
 public static QName valueOf(String name) {
   QName qName = (QName) FULL_NAME_TO_QNAME.get(name);
   return (qName != null) ? qName : QName.createNoNamespace(name);
 }
Esempio n. 13
0
 /** Return function with id */
 public FortFunction getFunction(int type) {
   return _function.get(type);
 }
Esempio n. 14
0
  /*
   * (non-Javadoc)
   *
   * @see wblut.hemesh.HE_Modifier#apply(wblut.hemesh.HE_Mesh)
   */
  @Override
  public HE_Mesh apply(final HE_Selection selection) {
    cut = new HE_Selection(selection.parent);
    cutEdges = new HE_Selection(selection.parent);
    // no plane defined
    if (P == null) {
      return selection.parent;
    }

    // empty mesh
    if (selection.parent.getNumberOfVertices() == 0) {
      return selection.parent;
    }
    final WB_Plane lP = new WB_Plane(P.getNormal(), P.d() + offset);
    final WB_AABBTree tree = new WB_AABBTree(selection.parent, 64);
    final HE_Selection faces = new HE_Selection(selection.parent);
    faces.addFaces(HE_Intersection.getPotentialIntersectedFaces(tree, lP));

    final HE_Selection lsel = selection.get();
    lsel.intersect(faces);

    lsel.collectEdgesByFace();
    lsel.collectVertices();
    // empty mesh
    if (lsel.getNumberOfVertices() == 0) {
      return lsel.parent;
    }

    // check if plane intersects mesh
    boolean positiveVertexExists = false;
    boolean negativeVertexExists = false;
    WB_Classification tmp;
    final FastMap<Long, WB_Classification> vertexClass = new FastMap<Long, WB_Classification>();
    HE_Vertex v;
    final Iterator<HE_Vertex> vItr = lsel.vItr();
    while (vItr.hasNext()) {
      v = vItr.next();
      tmp = lP.classifyPointToPlane(v);
      vertexClass.put(v.key(), tmp);
      if (tmp == WB_Classification.FRONT) {
        positiveVertexExists = true;
      }
      if (tmp == WB_Classification.BACK) {
        negativeVertexExists = true;
      }
    }

    if (positiveVertexExists && negativeVertexExists) {
      List<HE_Vertex> faceVertices = new ArrayList<HE_Vertex>();
      final HE_Selection split = new HE_Selection(lsel.parent);

      final HashMap<Long, Double> edgeInt = new HashMap<Long, Double>();
      final Iterator<HE_Halfedge> eItr = lsel.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);
          } 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 = lsel.parent.getHalfedgeByKey(en.getKey());
        final double u = en.getValue();
        if (lsel.contains(ce.getFace())) {
          split.add(ce.getFace());
        }
        if (lsel.contains(ce.getPair().getFace())) {
          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(lsel.parent.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 =
              lsel.parent.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 lsel.parent;
  }