Esempio n. 1
0
 public void NewAccount(String[] name) {
   Player player = getSelf();
   if (player == null) return;
   if (player.getInventory().getCountOf(ACC_MOVE_ITEM) < ACC_MOVE_PRICE) {
     player.sendMessage(
         "У вас нету "
             + ACC_MOVE_PRICE
             + " "
             + ItemHolder.getInstance().getTemplate(ACC_MOVE_ITEM));
     CharToAcc();
     return;
   }
   String _name = name[0];
   Connection con = null;
   Connection conGS = null;
   PreparedStatement offline = null;
   Statement statement = null;
   ResultSet rs = null;
   try {
     con = DatabaseFactory.getInstance().getConnection();
     offline = con.prepareStatement("SELECT `login` FROM `accounts` WHERE `login` = ?");
     offline.setString(1, _name);
     rs = offline.executeQuery();
     if (rs.next()) {
       removeItem(player, ACC_MOVE_ITEM, ACC_MOVE_PRICE);
       conGS = DatabaseFactory.getInstance().getConnection();
       statement = conGS.createStatement();
       statement.executeUpdate(
           "UPDATE `characters` SET `account_name` = '"
               + _name
               + "' WHERE `char_name` = '"
               + player.getName()
               + "'");
       player.sendMessage("Персонаж успешно перенесен.");
       player.logout();
     } else {
       player.sendMessage("Введенный аккаунт не найден.");
       CharToAcc();
     }
   } catch (Exception e) {
     e.printStackTrace();
     return;
   } finally {
     DbUtils.closeQuietly(con, offline, rs);
     DbUtils.closeQuietly(conGS, statement);
   }
 }
Esempio n. 2
0
  public void showStat() {
    Player player = getSelf();
    String html = HtmCache.getInstance().getNotNull("scripts/events/TVTArena/stat.htm", player);
    String playersTopList = "";

    playersTopList += "<table width=285>";
    playersTopList += "<tr>";
    playersTopList += "<td valign=\"top\" width=10></td>";
    playersTopList += "<td valign=\"top\" width=165><center>Игрок</center></td>";
    playersTopList += "<td valign=\"top\" width=50><center>Уровень</center></td>";
    playersTopList += "<td valign=\"top\" width=50><center>Рейтинг</center></td>";
    playersTopList += "<td valign=\"top\" width=10></td>";
    playersTopList += "</tr>";

    Connection conSelect = null;
    PreparedStatement statementSelect = null;
    ResultSet rsetSelect = null;

    try {
      conSelect = DatabaseFactory.getInstance().getConnection();
      statementSelect =
          conSelect.prepareStatement(
              "SELECT char_name, char_level, char_points FROM event_tvt_arena WHERE arena_id=? ORDER BY char_points DESC LIMIT 0,9");
      statementSelect.setInt(1, 5);
      rsetSelect = statementSelect.executeQuery();
      while (rsetSelect.next()) {
        playersTopList += "<tr>";
        playersTopList += "<td valign=\"top\" width=10></td>";
        playersTopList +=
            "<td valign=\"top\" width=165>" + rsetSelect.getString("char_name") + "</td>";
        playersTopList +=
            "<td valign=\"top\" width=50><center>"
                + rsetSelect.getInt("char_level")
                + "</center></td>";
        playersTopList +=
            "<td valign=\"top\" width=50><center>"
                + rsetSelect.getInt("char_points")
                + "</center></td>";
        playersTopList += "<td valign=\"top\" width=10></td>";
        playersTopList += "</tr>";
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      DbUtils.closeQuietly(conSelect, statementSelect, rsetSelect);
    }

    playersTopList += "</table>";
    html = html.replace("%top_list%", playersTopList);
    show(html, player);
  }
Esempio n. 3
0
  private void teleportCharacter_offline(int obj_id, Location loc) {
    if (obj_id == 0) return;

    Connection con = null;
    PreparedStatement st = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      st = con.prepareStatement("UPDATE characters SET x=?,y=?,z=? WHERE obj_Id=? LIMIT 1");
      st.setInt(1, loc.x);
      st.setInt(2, loc.y);
      st.setInt(3, loc.z);
      st.setInt(4, obj_id);
      st.executeUpdate();
    } catch (Exception e) {

    } finally {
      DbUtils.closeQuietly(con, st);
    }
  }
Esempio n. 4
0
  public String getNameByObjectId(int objectId) {
    String result = StringUtils.EMPTY;

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement("SELECT char_name FROM characters WHERE obj_Id=?");
      statement.setInt(1, objectId);
      rset = statement.executeQuery();
      if (rset.next()) result = rset.getString(1);
    } catch (Exception e) {
      _log.error("CharNameTable.getObjectIdByName(int): " + e, e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }

    return result;
  }
Esempio n. 5
0
 public boolean insert(Player player) {
   Connection con = null;
   PreparedStatement statement = null;
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement =
         con.prepareStatement(
             "INSERT INTO `characters` (account_name, obj_Id, char_name, face, hairStyle, hairColor, sex, karma, pvpkills, pkkills, clanid, createtime, deletetime, title, accesslevel, online, leaveclan, deleteclan, nochannel, pledge_type, pledge_rank, lvl_joined_academy, apprentice) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
     statement.setString(1, player.getAccountName());
     statement.setInt(2, player.getObjectId());
     statement.setString(3, player.getName());
     statement.setInt(4, player.getFace());
     statement.setInt(5, player.getHairStyle());
     statement.setInt(6, player.getHairColor());
     statement.setInt(7, player.getSex());
     statement.setInt(8, player.getKarma());
     statement.setInt(9, player.getPvpKills());
     statement.setInt(10, player.getPkKills());
     statement.setInt(11, player.getClanId());
     statement.setLong(12, player.getCreateTime() / 1000);
     statement.setInt(13, player.getDeleteTimer());
     statement.setString(14, player.getTitle());
     statement.setInt(15, player.getAccessLevel());
     statement.setInt(16, player.isOnline() ? 1 : 0);
     statement.setLong(17, player.getLeaveClanTime() / 1000);
     statement.setLong(18, player.getDeleteClanTime() / 1000);
     statement.setLong(
         19, player.getNoChannel() > 0 ? player.getNoChannel() / 1000 : player.getNoChannel());
     statement.setInt(20, player.getPledgeType());
     statement.setInt(21, player.getPowerGrade());
     statement.setInt(22, player.getLvlJoinedAcademy());
     statement.setInt(23, player.getApprentice());
     statement.executeUpdate();
   } catch (final Exception e) {
     _log.error("", e);
     return false;
   } finally {
     DbUtils.closeQuietly(con, statement);
   }
   return true;
 }
Esempio n. 6
0
  public int accountCharNumber(String account) {
    int number = 0;

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement =
          con.prepareStatement("SELECT COUNT(char_name) FROM characters WHERE account_name=?");
      statement.setString(1, account);
      rset = statement.executeQuery();
      if (rset.next()) number = rset.getInt(1);
    } catch (Exception e) {
      _log.error("", e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }

    return number;
  }
Esempio n. 7
0
  public void updateRentTime(boolean inDebt) {
    setEndTimeInMillis(System.currentTimeMillis() + 86400000);

    Connection con = null;
    PreparedStatement statement = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement =
          con.prepareStatement(
              "UPDATE residence_functions SET endTime=?, inDebt=? WHERE type=? AND id=?");
      statement.setInt(1, (int) (getEndTimeInMillis() / 1000));
      statement.setInt(2, inDebt ? 1 : 0);
      statement.setInt(3, getType());
      statement.setInt(4, getResidenceId());
      statement.executeUpdate();
    } catch (Exception e) {
      _log.error("", e);
    } finally {
      DbUtils.closeQuietly(con, statement);
    }
  }
Esempio n. 8
0
 public void deleteCharByObjId(int objid) {
   if (objid < 0) return;
   Connection con = null;
   PreparedStatement statement = null;
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM characters WHERE obj_Id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM world_statistic_winners_monthly WHERE objId=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM world_statistic_winners WHERE objId=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_skills WHERE char_obj_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_variables WHERE obj_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM world_statistic_monthly WHERE objId=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM world_statistic WHERE objId=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM servitors WHERE objId=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM bbs_favorites WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM items WHERE owner_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_effects_save WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_group_reuse WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_minigame_score WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_post_friends WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM dominion_rewards WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM item_attributes WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM siege_players WHERE object_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_recipebook WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM bbs_buffs WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_bookmarks WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_friends WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_quests WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM heroes WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM character_mail WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   }
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement("DELETE FROM olympiad_nobles WHERE char_id=?");
     statement.setInt(1, objid);
     statement.execute();
   } catch (Exception e) {
     _log.error("", e);
   } finally {
     DbUtils.closeQuietly(con, statement);
   }
 }