Exemple #1
0
  /**
   * 储存聊天
   *
   * @param pc
   * @param target
   * @param text
   * @param type
   */
  public void storeChat(
      final L1PcInstance pc, final L1PcInstance target, final String text, final int type) {
    if (!this.isLoggingTarget(type)) {
      return;
    }

    // type
    // 0:一般频道
    // 1:Whisper(密语频道)
    // 2:大喊频道
    // 3:广播频道
    // 4:血盟频道
    // 11:组队频道
    // 13:联盟频道
    // 14:聊天队伍频道
    Connection con = null;
    PreparedStatement pstm = null;
    try {

      con = L1DatabaseFactory.getInstance().getConnection();
      if (target != null) {
        pstm =
            con.prepareStatement(
                "INSERT INTO log_chat (account_name, char_id, name, clan_id, clan_name, locx, locy, mapid, type, target_account_name, target_id, target_name, target_clan_id, target_clan_name, target_locx, target_locy, target_mapid, content, datetime) VALUE (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE())");
        pstm.setString(1, pc.getAccountName());
        pstm.setInt(2, pc.getId());
        pstm.setString(3, pc.isGm() ? "******" : pc.getName());
        pstm.setInt(4, pc.getClanid());
        pstm.setString(5, pc.getClanname());
        pstm.setInt(6, pc.getX());
        pstm.setInt(7, pc.getY());
        pstm.setInt(8, pc.getMapId());
        pstm.setInt(9, type);
        pstm.setString(10, target.getAccountName());
        pstm.setInt(11, target.getId());
        pstm.setString(12, target.getName());
        pstm.setInt(13, target.getClanid());
        pstm.setString(14, target.getClanname());
        pstm.setInt(15, target.getX());
        pstm.setInt(16, target.getY());
        pstm.setInt(17, target.getMapId());
        pstm.setString(18, text);
      } else {
        pstm =
            con.prepareStatement(
                "INSERT INTO log_chat (account_name, char_id, name, clan_id, clan_name, locx, locy, mapid, type, content, datetime) VALUE (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE())");
        pstm.setString(1, pc.getAccountName());
        pstm.setInt(2, pc.getId());
        pstm.setString(3, pc.isGm() ? "******" : pc.getName());
        pstm.setInt(4, pc.getClanid());
        pstm.setString(5, pc.getClanname());
        pstm.setInt(6, pc.getX());
        pstm.setInt(7, pc.getY());
        pstm.setInt(8, pc.getMapId());
        pstm.setInt(9, type);
        pstm.setString(10, text);
      }
      pstm.execute();

    } catch (final SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    }
  }