private static boolean isValidJob(MapleJob thejob, int jobs) { int jobid = thejob.getId(); if (jobid == 0) { return ((jobs & 2) > 0); } else if (jobid == 100) { return ((jobs & 4) > 0); } else if (jobid > 100 && jobid < 113) { return ((jobs & 8) > 0); } else if (jobid > 110 && jobid < 123) { return ((jobs & 16) > 0); } else if (jobid > 120 && jobid < 133) { return ((jobs & 32) > 0); } else if (jobid == 200) { return ((jobs & 64) > 0); } else if (jobid > 209 && jobid < 213) { return ((jobs & 128) > 0); } else if (jobid > 219 && jobid < 223) { return ((jobs & 256) > 0); } else if (jobid > 229 && jobid < 233) { return ((jobs & 512) > 0); } else if (jobid == 500) { return ((jobs & 1024) > 0); } else if (jobid > 509 && jobid < 513) { return ((jobs & 2048) > 0); } else if (jobid > 519 && jobid < 523) { return ((jobs & 4096) > 0); } else if (jobid == 400) { return ((jobs & 8192) > 0); } else if (jobid > 400 && jobid < 413) { return ((jobs & 16384) > 0); } else if (jobid > 419 && jobid < 423) { return ((jobs & 32768) > 0); } else if (jobid == 300) { return ((jobs & 65536) > 0); } else if (jobid > 300 && jobid < 313) { return ((jobs & 131072) > 0); } else if (jobid > 319 && jobid < 323) { return ((jobs & 262144) > 0); } return false; }
public void run() { try { con = DatabaseConnection.getConnection(); con.setAutoCommit(false); updateRanking(null); for (int i = 0; i < 3; i += 2) { for (int j = 1; j < 6; j++) { updateRanking(MapleJob.getById(i * 500 + 100 * j)); } } con.commit(); con.setAutoCommit(true); lastUpdate = System.currentTimeMillis(); } catch (SQLException ex) { try { con.rollback(); con.setAutoCommit(true); } catch (SQLException ex2) { } } }
private void updateRanking(MapleJob job) throws SQLException { String sqlCharSelect = "SELECT c.id, " + (job != null ? "c.jobRank, c.jobRankMove" : "c.rank, c.rankMove") + ", a.lastlogin AS lastlogin, a.loggedin FROM characters AS c LEFT JOIN accounts AS a ON c.accountid = a.id WHERE c.gm = 0 "; if (job != null) { sqlCharSelect += "AND c.job DIV 100 = ? "; } sqlCharSelect += "ORDER BY c.level DESC , c.exp DESC , c.fame DESC , c.meso DESC"; PreparedStatement charSelect = con.prepareStatement(sqlCharSelect); if (job != null) { charSelect.setInt(1, job.getId() / 100); } ResultSet rs = charSelect.executeQuery(); PreparedStatement ps = con.prepareStatement( "UPDATE characters SET " + (job != null ? "jobRank = ?, jobRankMove = ? " : "rank = ?, rankMove = ? ") + "WHERE id = ?"); int rank = 0; while (rs.next()) { int rankMove = 0; rank++; if (rs.getLong("lastlogin") < lastUpdate || rs.getInt("loggedin") > 0) { rankMove = rs.getInt((job != null ? "jobRankMove" : "rankMove")); } rankMove += rs.getInt((job != null ? "jobRank" : "rank")) - rank; ps.setInt(1, rank); ps.setInt(2, rankMove); ps.setInt(3, rs.getInt("id")); ps.executeUpdate(); } rs.close(); charSelect.close(); ps.close(); }