public static CommandOutputContent runOnNode(Node node, String name, String... command) {
    String content = "Exception occurred while retrieving command content";

    VirtualChannel chan = node.getChannel();
    if (chan == null) {
      content = "No connection to node";
    } else {
      try {
        content = chan.call(new CommandLauncher(command));
      } catch (IOException e) {
        final LogRecord lr =
            new LogRecord(Level.FINE, "Could not retrieve command content from {0}");
        lr.setParameters(new Object[] {getNodeName(node)});
        lr.setThrown(e);
        LOGGER.log(lr);
      } catch (InterruptedException e) {
        final LogRecord lr =
            new LogRecord(Level.FINE, "Could not retrieve command content from {0}");
        lr.setParameters(new Object[] {getNodeName(node)});
        lr.setThrown(e);
        LOGGER.log(lr);
      }
    }

    return new CommandOutputContent(name, content);
  }
    public SVNNodeKind checkRepositoryPath(
        SCMSourceOwner context, SVNURL repoURL, StandardCredentials credentials)
        throws SVNException {
      SVNRepository repository = null;

      try {
        repository =
            getRepository(
                context, repoURL, credentials, Collections.<String, Credentials>emptyMap(), null);
        repository.testConnection();

        long rev = repository.getLatestRevision();
        String repoPath = getRelativePath(repoURL, repository);
        return repository.checkPath(repoPath, rev);
      } catch (SVNException e) {
        if (LOGGER.isLoggable(Level.FINE)) {
          LogRecord lr =
              new LogRecord(
                  Level.FINE, "Could not check repository path {0} using credentials {1} ({2})");
          lr.setThrown(e);
          lr.setParameters(
              new Object[] {
                repoURL,
                credentials == null ? null : CredentialsNameProvider.name(credentials),
                credentials
              });
          LOGGER.log(lr);
        }
        throw e;
      } finally {
        if (repository != null) repository.closeSession();
      }
    }
Example #3
0
  public final Client performLogin(final ServerLogin login) throws RjException, LoginException {
    String client = null;
    try {
      client = getCallingClient();
      if (login.getId() != this.pendingLoginId || !client.equals(this.pendingLoginClient)) {
        throw new FailedLoginException("Login process was interrupted by another client.");
      }

      login.readAnswer(this.usePubkeyExchange ? this.pendingLoginKeyPair.getPrivate() : null);
      this.pendingLoginKeyPair = null;
      final String name = doPerformLogin(login.getCallbacks());

      LOGGER.log(
          Level.INFO,
          "{0} performing login completed successfull: {1} ({2}).",
          new Object[] {this.logPrefix, name, client});
      return new Client(name, getCallingClient(), (byte) 0);
    } catch (final Exception e) {
      if (e instanceof LoginException) {
        final LogRecord log = new LogRecord(Level.INFO, "{0} performing login failed ({1}).");
        log.setParameters(new Object[] {this.logPrefix, client});
        log.setThrown(e);
        LOGGER.log(log);
        throw (LoginException) e;
      }
      if (e instanceof RjException) {
        throw (RjException) e;
      }
      throw new RjException(
          "An unexpected error occurred when validating the login credential.", e);
    } finally {
      System.gc();
    }
  }
 /**
  * Creates a pooled connection object with the properties specified.
  *
  * @param props properties for the Type 4 connection
  * @see #HPT4ConnectionPoolDataSource()
  * @link T4Properties
  */
 public HPT4ConnectionPoolDataSource(Properties props) {
   super(props);
   if (getT4LogLevel() != Level.OFF) setupLogFileHandler();
   if (t4Logger_.isLoggable(Level.FINE) == true) {
     Object p[] = T4LoggingUtilities.makeParams(null, props);
     t4Logger_.logp(
         Level.FINE,
         "HPT4ConnectionPoolDataSource",
         "HPT4ConnectionPoolDataSource",
         "Note, super called before this.",
         p);
   }
   try {
     if (getLogWriter() != null) {
       LogRecord lr = new LogRecord(Level.FINE, "");
       Object p[] = T4LoggingUtilities.makeParams(null, props);
       lr.setParameters(p);
       lr.setSourceClassName("HPT4ConnectionPoolDataSource");
       lr.setSourceMethodName("");
       T4LogFormatter lf = new T4LogFormatter();
       String temp = lf.format(lr);
       getLogWriter().println(temp);
     }
   } catch (SQLException se) {
     // ignore
   }
 }
  /**
   * Returns all the properties associated with this <code>ConnectionPoolDataSource</code>.
   *
   * @return Reference Object containing all the Type 4 property references.
   * @throws NamingException
   */
  public Reference getReference() throws NamingException {
    if (t4Logger_ != null && t4Logger_.isLoggable(Level.FINE) == true) {
      Object p[] = T4LoggingUtilities.makeParams(null);
      t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getReference", "", p);
    }
    try {
      if (getLogWriter() != null) {
        LogRecord lr = new LogRecord(Level.FINE, "");
        Object p[] = T4LoggingUtilities.makeParams(null);
        lr.setParameters(p);
        lr.setSourceClassName("HPT4ConnectionPoolDataSource");
        lr.setSourceMethodName("getReference");
        T4LogFormatter lf = new T4LogFormatter();
        String temp = lf.format(lr);
        getLogWriter().println(temp);
      }
    } catch (SQLException se) {
      // ignore
    }

    Reference ref =
        new Reference(
            this.getClass().getName(),
            "org.trafodion.jdbc.t4.HPT4ConnectionPoolDataSourceFactory",
            null);
    ref = addReferences(ref);
    ref.add(new StringRefAddr("propertyCycle", Integer.toString(propertyCycle_)));
    return ref;
  }
 protected void log(Level level, String message, Object[] params, Throwable cause) {
   if (logger.isLoggable(level)) {
     LogRecord record = new LogRecord(level, message);
     record.setParameters(params);
     record.setThrown(cause);
     logger.log(record);
   }
 }
Example #7
0
 protected void log(Throwable t, Level level, String msg, Object[] objs) {
   LogRecord lr = createLogRecord(level, msg);
   if (t != null) {
     lr.setThrown(t);
   }
   if (objs != null) {
     // serializeCheck(objs);
     lr.setParameters(objs);
   }
   getLogger().log(lr);
 }
Example #8
0
  private void logImpl(
      Level level, String sourceClass, String sourceMethod, String message, Object[] params) {
    synchronized (lock) {
      LogRecord rec = new LogRecord(level, message);

      rec.setResourceBundle(findResourceBundle());
      rec.setSourceClassName(sourceClass);
      rec.setSourceMethodName(sourceMethod);
      rec.setParameters(params);

      log(rec);
    }
  }
Example #9
0
  public static void main(String[] args) {
    for (int i = 1; i <= 5; i++) {
      LogRecord logRecord = new LogRecord(Level.SEVERE, "This is a severe message #" + i + "!");

      logRecord.setLoggerName("test app");
      logRecord.setMillis(System.currentTimeMillis());
      logRecord.setParameters(new Object[] {Thread.currentThread().getName()});
      logRecord.setSourceClassName(HTMLFormatter.class.getName());
      logRecord.setSourceMethodName("SourceMethodName");

      System.out.print(new HTMLFormatter().format(logRecord));

      logRecord = new LogRecord(Level.WARNING, "This is a warning message #" + i + "!");

      logRecord.setLoggerName("test app");
      logRecord.setMillis(System.currentTimeMillis());
      logRecord.setParameters(new Object[] {Thread.currentThread().getName()});
      logRecord.setSourceClassName(HTMLFormatter.class.getName());
      logRecord.setSourceMethodName("SourceMethodName");

      System.out.print(new HTMLFormatter().format(logRecord));
    }
  }
Example #10
0
 public synchronized void run(boolean includeSubdir) {
   markInProgress();
   try {
     deployAll(directory, includeSubdir);
     undeployAll(directory, includeSubdir);
   } catch (AutoDeploymentException e) {
     // print and continue
     LogRecord lr = new LogRecord(Level.SEVERE, EXCEPTION_CAUGHT);
     Object args[] = {e.getMessage()};
     lr.setParameters(args);
     lr.setThrown(e);
     deplLogger.log(lr);
   } finally {
     clearInProgress();
   }
 }
Example #11
0
 protected void logp(
     Object clazz, String methodName, Throwable t, Level level, String msg, Object[] objs) {
   LogRecord lr = createLogRecord(level, msg);
   if (t != null) {
     lr.setThrown(t);
   }
   if (clazz != null) {
     lr.setSourceClassName(toClassName(clazz));
   }
   if (methodName != null) {
     lr.setSourceMethodName(methodName);
   }
   if (objs != null) {
     // serializeCheck(objs);
     lr.setParameters(objs);
   }
   getLogger().log(lr);
 }
Example #12
0
  public void logrb(
      Level level,
      String sourceClass,
      String sourceMethod,
      String bundleName,
      String message,
      Object[] params) {
    synchronized (lock) {
      LogRecord rec = new LogRecord(level, message);

      rec.setResourceBundleName(bundleName);
      rec.setSourceClassName(sourceClass);
      rec.setSourceMethodName(sourceMethod);
      rec.setParameters(params);

      log(rec);
    }
  }
  public static CommandOutputContent runOnNodeAndCache(
      WeakHashMap<Node, String> cache, Node node, String name, String... command) {
    String content = "Exception occurred while retrieving command content";

    try {
      content =
          AsyncResultCache.get(
              node,
              cache,
              new CommandLauncher(command),
              "sysctl info",
              "N/A: Either no connection to node or no cached result");
    } catch (IOException e) {
      final LogRecord lr = new LogRecord(Level.FINE, "Could not retrieve sysctl content from {0}");
      lr.setParameters(new Object[] {getNodeName(node)});
      lr.setThrown(e);
      LOGGER.log(lr);
    }

    return new CommandOutputContent(name, content);
  }
 /**
  * Returns the Property cycle property. This property is not supprted by the Type 4 driver. This
  * property is ignored by the Type 4 driver.
  *
  * @return propertyCycle
  */
 public int getPropertyCycle() {
   if (t4Logger_.isLoggable(Level.FINE) == true) {
     Object p[] = T4LoggingUtilities.makeParams(null);
     t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPropertyCycle", "", p);
   }
   try {
     if (getLogWriter() != null) {
       LogRecord lr = new LogRecord(Level.FINE, "");
       Object p[] = T4LoggingUtilities.makeParams(null);
       lr.setParameters(p);
       lr.setSourceClassName("HPT4ConnectionPoolDataSource");
       lr.setSourceMethodName("getPropertyCycle");
       T4LogFormatter lf = new T4LogFormatter();
       String temp = lf.format(lr);
       getLogWriter().println(temp);
     }
   } catch (SQLException se) {
     // ignore
   }
   return propertyCycle_;
 }
  /**
   * Attempts to establish a physical database connection that can be used as a pooled connection.
   *
   * @param username Safeguard user name.
   * @param password Safeguard user password.
   * @return A <code>PooledConnection</code> object that is a physical connection to the NDCS server
   *     that this <code>HPT4ConnectionPoolDataSource</code> object represents.
   * @throws SQLException If any NDCS error occurs.
   */
  public PooledConnection getPooledConnection(String username, String password)
      throws SQLException {
    if (t4Logger_.isLoggable(Level.FINE) == true) {
      Object p[] = T4LoggingUtilities.makeParams(null, username);
      t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPooledConnection", "", p);
    }
    if (getLogWriter() != null) {
      LogRecord lr = new LogRecord(Level.FINE, "");
      Object p[] = T4LoggingUtilities.makeParams(null, username);
      lr.setParameters(p);
      lr.setSourceClassName("HPT4ConnectionPoolDataSource");
      lr.setSourceMethodName("getPooledConnection");
      T4LogFormatter lf = new T4LogFormatter();
      String temp = lf.format(lr);
      getLogWriter().println(temp);
    }
    HPT4PooledConnection connect;

    setUser(username);
    setPassword(password);
    return getPooledConnection();
  }
  /**
   * Attempts to establish a physical database connection that can be used as a pooled connection.
   *
   * @return A <code>PooledConnection</code> object that is a physical connection to the NDCS server
   *     that this <code>HPT4ConnectionPoolDataSource</code> object represents.
   * @throws SQLException If any NDCS error occurs.
   */
  public PooledConnection getPooledConnection() throws SQLException {
    if (t4Logger_.isLoggable(Level.FINE) == true) {
      Object p[] = T4LoggingUtilities.makeParams(null);
      t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPooledConnection", "", p);
    }
    if (getLogWriter() != null) {
      LogRecord lr = new LogRecord(Level.FINE, "");
      Object p[] = T4LoggingUtilities.makeParams(null);
      lr.setParameters(p);
      lr.setSourceClassName("HPT4ConnectionPoolDataSource");
      lr.setSourceMethodName("getPooledConnection");
      T4LogFormatter lf = new T4LogFormatter();
      String temp = lf.format(lr);
      getLogWriter().println(temp);
    }
    HPT4PooledConnection connect;

    Properties l_props = super.getProperties();
    T4Properties l_t4props = new T4Properties(l_props);
    connect = new HPT4PooledConnection(this, l_t4props);

    return connect;
  }
  @Override
  protected void runImpl() {
    // Last Verified: May 30, 2009 - Gracia Final - Players are able to create characters with names
    // consisting of as little as 1,2,3 letter/number combinations.
    if ((_name.length() < 1) || (_name.length() > 16)) {
      if (Config.DEBUG)
        _log.fine(
            "Character Creation Failure: Character name "
                + _name
                + " is invalid. Message generated: Your title cannot exceed 16 characters in length. Please try again.");

      sendPacket(new CharCreateFail(CharCreateFail.REASON_16_ENG_CHARS));
      return;
    }

    if (Config.FORBIDDEN_NAMES.length > 1) {
      for (String st : Config.FORBIDDEN_NAMES) {
        if (_name.toLowerCase().contains(st.toLowerCase())) {
          sendPacket(new CharCreateFail(CharCreateFail.REASON_INCORRECT_NAME));
          return;
        }
      }
    }

    // Last Verified: May 30, 2009 - Gracia Final
    if (!Util.isAlphaNumeric(_name) || !isValidName(_name)) {
      if (Config.DEBUG)
        _log.fine(
            "Character Creation Failure: Character name "
                + _name
                + " is invalid. Message generated: Incorrect name. Please try again.");

      sendPacket(new CharCreateFail(CharCreateFail.REASON_INCORRECT_NAME));
      return;
    }

    if (_face > 2 || _face < 0) {
      _log.warning(
          "Character Creation Failure: Character face "
              + _face
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    if (_hairStyle < 0 || (_sex == 0 && _hairStyle > 4) || (_sex != 0 && _hairStyle > 6)) {
      _log.warning(
          "Character Creation Failure: Character hair style "
              + _hairStyle
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    if (_hairColor > 3 || _hairColor < 0) {
      _log.warning(
          "Character Creation Failure: Character hair color "
              + _hairColor
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    L2PcInstance newChar = null;
    L2PcTemplate template = null;

    /*
     * DrHouse: Since checks for duplicate names are done using SQL, lock must be held until data is written to DB as well.
     */
    synchronized (CharNameTable.getInstance()) {
      if (CharNameTable.getInstance().accountCharNumber(getClient().getAccountName())
              >= Config.MAX_CHARACTERS_NUMBER_PER_ACCOUNT
          && Config.MAX_CHARACTERS_NUMBER_PER_ACCOUNT != 0) {
        if (Config.DEBUG) _log.fine("Max number of characters reached. Creation failed.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_TOO_MANY_CHARACTERS));
        return;
      } else if (CharNameTable.getInstance().doesCharNameExist(_name)) {
        if (Config.DEBUG)
          _log.fine(
              "Character Creation Failure: Message generated: You cannot create another character. Please delete the existing character and try again.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_NAME_ALREADY_EXISTS));
        return;
      }

      template = CharTemplateTable.getInstance().getTemplate(_classId);

      if (template == null || template.classBaseLevel > 1) {
        if (Config.DEBUG)
          _log.fine(
              "Character Creation Failure: "
                  + _name
                  + " classId: "
                  + _classId
                  + " Template: "
                  + template
                  + " Message generated: Your character creation has failed.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
        return;
      }

      int objectId = IdFactory.getInstance().getNextId();
      newChar =
          L2PcInstance.create(
              objectId,
              template,
              getClient().getAccountName(),
              _name,
              _hairStyle,
              _hairColor,
              _face,
              _sex != 0);
    }

    newChar.setCurrentHp(template.baseHpMax);
    newChar.setCurrentCp(template.baseCpMax);
    newChar.setCurrentMp(template.baseMpMax);
    // newChar.setMaxLoad(template.baseLoad);

    CharCreateOk cco = new CharCreateOk();
    sendPacket(cco);

    initNewChar(getClient(), newChar);

    LogRecord record = new LogRecord(Level.INFO, "Created new character");
    record.setParameters(new Object[] {newChar, this.getClient()});
    _logAccounting.log(record);
  }
Example #18
0
  @Override
  public void useSkill(L2Character activeChar, L2Object[] targets) {
    if (activeChar.isAlikeDead()) {
      return;
    }

    boolean ss = useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
    boolean sps = useSpiritShot() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
    boolean bss = useSpiritShot() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);

    for (L2Character target : (L2Character[]) targets) {
      if (target.isAlikeDead() && (getTargetType() != L2TargetType.CORPSE_MOB)) {
        continue;
      }

      if ((activeChar != target) && target.isInvul()) {
        continue; // No effect on invulnerable chars unless they cast it themselves.
      }

      boolean mcrit = Formulas.calcMCrit(activeChar.getMCriticalHit(target, this));
      byte shld = Formulas.calcShldUse(activeChar, target, this);
      int damage =
          isStaticDamage()
              ? (int) getPower()
              : (int) Formulas.calcMagicDam(activeChar, target, this, shld, sps, bss, mcrit);

      int _drain = 0;
      int _cp = (int) target.getCurrentCp();
      int _hp = (int) target.getCurrentHp();

      if (_cp > 0) {
        if (damage < _cp) {
          _drain = 0;
        } else {
          _drain = damage - _cp;
        }
      } else if (damage > _hp) {
        _drain = _hp;
      } else {
        _drain = damage;
      }

      double hpAdd = _absorbAbs + (_absorbPart * _drain);
      double hp =
          ((activeChar.getCurrentHp() + hpAdd) > activeChar.getMaxHp()
              ? activeChar.getMaxHp()
              : (activeChar.getCurrentHp() + hpAdd));

      activeChar.setCurrentHp(hp);

      StatusUpdate suhp = new StatusUpdate(activeChar);
      suhp.addAttribute(StatusUpdate.CUR_HP, (int) hp);
      activeChar.sendPacket(suhp);

      // Check to see if we should damage the target
      if ((damage > 0) && (!target.isDead() || (getTargetType() != L2TargetType.CORPSE_MOB))) {
        // Manage attack or cast break of the target (calculating rate, sending message...)
        if (!target.isRaid() && Formulas.calcAtkBreak(target, damage)) {
          target.breakAttack();
          target.breakCast();
        }

        activeChar.sendDamageMessage(target, damage, mcrit, false, false);

        if (Config.LOG_GAME_DAMAGE
            && activeChar.isPlayable()
            && (damage > Config.LOG_GAME_DAMAGE_THRESHOLD)) {
          LogRecord record = new LogRecord(Level.INFO, "");
          record.setParameters(
              new Object[] {activeChar, " did damage ", damage, this, " to ", target});
          record.setLoggerName("mdam");
          _logDamage.log(record);
        }

        if (hasEffects() && (getTargetType() != L2TargetType.CORPSE_MOB)) {
          // ignoring vengance-like reflections
          if ((Formulas.calcSkillReflect(target, this) & Formulas.SKILL_REFLECT_SUCCEED) > 0) {
            activeChar.stopSkillEffects(getId());
            getEffects(target, activeChar);
            SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
            sm.addSkillName(getId());
            activeChar.sendPacket(sm);
          } else {
            // activate attacked effects, if any
            target.stopSkillEffects(getId());
            if (Formulas.calcSkillSuccess(activeChar, target, this, shld, ss, sps, bss)) {
              getEffects(activeChar, target);
            } else {
              SystemMessage sm =
                  SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
              sm.addCharName(target);
              sm.addSkillName(this);
              activeChar.sendPacket(sm);
            }
          }
        }

        target.reduceCurrentHp(damage, activeChar, this);
      }

      // Check to see if we should do the decay right after the cast
      if (target.isDead() && (getTargetType() == L2TargetType.CORPSE_MOB) && target.isNpc()) {
        ((L2Npc) target).endDecayTask();
      }
    }
    // effect self :]
    L2Effect effect = activeChar.getFirstEffect(getId());
    if ((effect != null) && effect.isSelfEffect()) {
      // Replace old effect with new one.
      effect.exit();
    }
    // cast self effect if any
    getEffectsSelf(activeChar);
    // Consume shot
    activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  }
  @Override
  protected void runImpl() {
    if (_skillId <= 0 || _skillLvl <= 0) // minimal sanity check
    return;

    L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    if (player.getClassId().level() < 3) // requires to have 3rd class quest completed
    {
      player.sendPacket(SystemMessageId.YOU_CANNOT_USE_SKILL_ENCHANT_IN_THIS_CLASS);
      return;
    }

    if (player.getLevel() < 76) {
      player.sendPacket(SystemMessageId.YOU_CANNOT_USE_SKILL_ENCHANT_ON_THIS_LEVEL);
      return;
    }

    if (!player.isAllowedToEnchantSkills()) {
      player.sendPacket(SystemMessageId.YOU_CANNOT_USE_SKILL_ENCHANT_ATTACKING_TRANSFORMED_BOAT);
      return;
    }

    L2EnchantSkillLearn s = EnchantGroupsTable.getInstance().getSkillEnchantmentBySkillId(_skillId);
    if (s == null) return;

    if (_skillLvl % 100 == 0) {
      _skillLvl = s.getBaseLevel();
    }

    L2Skill skill = SkillTable.getInstance().getInfo(_skillId, _skillLvl);
    if (skill == null) return;

    int reqItemId = EnchantGroupsTable.UNTRAIN_ENCHANT_BOOK;

    final int beforeUntrainSkillLevel = player.getSkillLevel(_skillId);
    if (beforeUntrainSkillLevel - 1 != _skillLvl
        && (beforeUntrainSkillLevel % 100 != 1 || _skillLvl != s.getBaseLevel())) return;

    EnchantSkillDetail esd = s.getEnchantSkillDetail(beforeUntrainSkillLevel);

    int requiredSp = esd.getSpCost();
    int requireditems = esd.getAdenaCost();

    L2ItemInstance spb = player.getInventory().getItemByItemId(reqItemId);
    if (Config.ES_SP_BOOK_NEEDED) {
      if (spb == null) // Haven't spellbook
      {
        player.sendPacket(
            SystemMessageId.YOU_DONT_HAVE_ALL_OF_THE_ITEMS_NEEDED_TO_ENCHANT_THAT_SKILL);
        return;
      }
    }

    if (player.getInventory().getAdena() < requireditems) {
      player.sendPacket(
          SystemMessageId.YOU_DONT_HAVE_ALL_OF_THE_ITEMS_NEEDED_TO_ENCHANT_THAT_SKILL);
      return;
    }

    boolean check = true;
    if (Config.ES_SP_BOOK_NEEDED) {
      check &= player.destroyItem("Consume", spb.getObjectId(), 1, player, true);
    }

    check &=
        player.destroyItemByItemId("Consume", PcInventory.ADENA_ID, requireditems, player, true);

    if (!check) {
      player.sendPacket(
          SystemMessageId.YOU_DONT_HAVE_ALL_OF_THE_ITEMS_NEEDED_TO_ENCHANT_THAT_SKILL);
      return;
    }

    player.getStat().addSp((int) (requiredSp * 0.8));

    if (Config.LOG_SKILL_ENCHANTS) {
      LogRecord record = new LogRecord(Level.INFO, "Untrain");
      record.setParameters(new Object[] {player, skill, spb});
      record.setLoggerName("skill");
      _logEnchant.log(record);
    }

    player.addSkill(skill, true);
    player.sendPacket(ExEnchantSkillResult.valueOf(true));

    if (Config.DEBUG) {
      _log.fine(
          "Learned skill ID: "
              + _skillId
              + " Level: "
              + _skillLvl
              + " for "
              + requiredSp
              + " SP, "
              + requireditems
              + " Adena.");
    }

    player.sendPacket(new UserInfo(player));
    player.sendPacket(new ExBrExtraUserInfo(player));

    if (_skillLvl > 100) {
      SystemMessage sm =
          SystemMessage.getSystemMessage(
              SystemMessageId.UNTRAIN_SUCCESSFUL_SKILL_S1_ENCHANT_LEVEL_DECREASED_BY_ONE);
      sm.addSkillName(_skillId);
      player.sendPacket(sm);
    } else {
      SystemMessage sm =
          SystemMessage.getSystemMessage(
              SystemMessageId.UNTRAIN_SUCCESSFUL_SKILL_S1_ENCHANT_LEVEL_RESETED);
      sm.addSkillName(_skillId);
      player.sendPacket(sm);
    }
    player.sendSkillList();
    final int afterUntrainSkillLevel = player.getSkillLevel(_skillId);
    player.sendPacket(new ExEnchantSkillInfo(_skillId, afterUntrainSkillLevel));
    player.sendPacket(
        new ExEnchantSkillInfoDetail(2, _skillId, afterUntrainSkillLevel - 1, player));
    player.updateShortCuts(_skillId, afterUntrainSkillLevel);
  }
Example #20
0
  @Override
  protected void runImpl() {
    if (Config.DEBUG) _log.info("Say2: Msg Type = '" + _type + "' Text = '" + _text + "'.");

    L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) return;

    if (_type < 0 || _type >= CHAT_NAMES.length) {
      _log.warning(
          "Say2: Invalid type: "
              + _type
              + " Player : "
              + activeChar.getName()
              + " text: "
              + String.valueOf(_text));
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      activeChar.logout();
      return;
    }

    if (_text.isEmpty()) {
      _log.warning(activeChar.getName() + ": sending empty text. Possible packet hack!");
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      activeChar.logout();
      return;
    }

    // Even though the client can handle more characters than it's current limit allows, an overflow
    // (critical error) happens if you pass a huge (1000+) message.
    // July 11, 2011 - Verified on High Five 4 official client as 105.
    // Allow higher limit if player shift some item (text is longer then).
    if (!activeChar.isGM()
        && ((_text.indexOf(8) >= 0 && _text.length() > 500)
            || (_text.indexOf(8) < 0 && _text.length() > 105))) {
      activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DONT_SPAM));
      return;
    }

    if (Config.L2WALKER_PROTECTION && _type == TELL && checkBot(_text)) {
      Util.handleIllegalPlayerAction(
          activeChar,
          "Client Emulator Detect: Player " + activeChar.getName() + " using l2walker.",
          Config.DEFAULT_PUNISH);
      return;
    }

    if (activeChar.isCursedWeaponEquipped() && (_type == TRADE || _type == SHOUT)) {
      activeChar.sendPacket(
          SystemMessage.getSystemMessage(
              SystemMessageId.SHOUT_AND_TRADE_CHAT_CANNOT_BE_USED_WHILE_POSSESSING_CURSED_WEAPON));
      return;
    }

    if (activeChar.isChatBanned() && !_text.startsWith(".")) {
      for (int chatId : Config.BAN_CHAT_CHANNELS) {
        if (_type == chatId) {
          activeChar.sendPacket(
              SystemMessage.getSystemMessage(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED));
          return;
        }
      }
    }

    if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT) {
      if (_type == TELL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE) {
        activeChar.sendMessage("You can not chat with players outside of the jail.");
        return;
      }
    }

    if (_type == PETITION_PLAYER && activeChar.isGM()) _type = PETITION_GM;

    if (Config.LOG_CHAT) {
      LogRecord record = new LogRecord(Level.INFO, _text);
      record.setLoggerName("chat");

      if (_type == TELL)
        record.setParameters(
            new Object[] {CHAT_NAMES[_type], "[" + activeChar.getName() + " to " + _target + "]"});
      else record.setParameters(new Object[] {CHAT_NAMES[_type], "[" + activeChar.getName() + "]"});

      _logChat.log(record);
    }

    if (_text.indexOf(8) >= 0) if (!parseAndPublishItem(activeChar)) return;

    // Say Filter implementation
    if (Config.USE_SAY_FILTER) checkText();

    IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
    if (handler != null) handler.handleChat(_type, activeChar, _target, _text);
    else _log.info("No handler registered for ChatType: " + _type + " Player: " + getClient());
  }