Experimental DB pool + fixed stat overflow on equips
Implemented EXPERIMENTAL DBCP (connection pool), trying to improve concorrent access to DB. Added door portals on Kerning Square. Fixed equipments getting stat overflow when upgrading stats. Fixed expiring pets crashing the client in some cases.
This commit is contained in:
@@ -23,6 +23,7 @@ package client;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
@@ -109,7 +110,9 @@ public class BuddyList {
|
||||
|
||||
public void loadFromDb(int characterId) {
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT b.buddyid, b.pending, b.group, c.name as buddyname FROM buddies as b, characters as c WHERE c.id = b.buddyid AND b.characterid = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement ps = con.prepareStatement("SELECT b.buddyid, b.pending, b.group, c.name as buddyname FROM buddies as b, characters as c WHERE c.id = b.buddyid AND b.characterid = ?");
|
||||
ps.setInt(1, characterId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
@@ -121,10 +124,11 @@ public class BuddyList {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("DELETE FROM buddies WHERE pending = 1 AND characterid = ?");
|
||||
ps = con.prepareStatement("DELETE FROM buddies WHERE pending = 1 AND characterid = ?");
|
||||
ps.setInt(1, characterId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -622,7 +622,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
ps.setInt(2, accountid);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -630,9 +631,11 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
|
||||
public static boolean ban(String id, String reason, boolean accountId) {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
if (id.matches("/[0-9]{1,3}\\..*")) {
|
||||
ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?)");
|
||||
ps.setString(1, id);
|
||||
@@ -649,16 +652,22 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
boolean ret = false;
|
||||
ps.setString(1, id);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
try (PreparedStatement psb = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) {
|
||||
psb.setString(1, reason);
|
||||
psb.setInt(2, rs.getInt(1));
|
||||
psb.executeUpdate();
|
||||
}
|
||||
ret = true;
|
||||
if (rs.next()) {
|
||||
Connection con2 = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement psb = con2.prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) {
|
||||
psb.setString(1, reason);
|
||||
psb.setInt(2, rs.getInt(1));
|
||||
psb.executeUpdate();
|
||||
} finally {
|
||||
con2.close();
|
||||
}
|
||||
ret = true;
|
||||
}
|
||||
rs.close();
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return ret;
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -670,6 +679,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1395,6 +1407,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
ps.setInt(1, skill.getId());
|
||||
ps.setInt(2, id);
|
||||
ps.execute();
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1464,10 +1478,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
if (id / 1000000 == 2) {
|
||||
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
||||
if (ii.isConsumeOnPickup(id)) {
|
||||
if (ii.isPartyItem(id)) {
|
||||
if (ItemConstants.isPartyItem(id)) {
|
||||
List<MapleCharacter> pchr = c.getPlayer().getPartyMembersOnSameMap();
|
||||
|
||||
if(!ii.isPartyAllcure(id)) {
|
||||
if(!ItemConstants.isPartyAllcure(id)) {
|
||||
if(!pchr.isEmpty()) {
|
||||
for (MapleCharacter mc : pchr) {
|
||||
ii.getItemEffect(id).applyTo(mc);
|
||||
@@ -1663,6 +1677,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM guilds WHERE guildid = ?")) {
|
||||
ps.setInt(1, id);
|
||||
ps.execute();
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1697,8 +1713,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
public static boolean deleteCharFromDB(MapleCharacter player) {
|
||||
int cid = player.getId(), accId = -1, world = 0;
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT accountid, world FROM characters WHERE id = ?")) {
|
||||
ps.setInt(1, cid);
|
||||
|
||||
@@ -2297,7 +2315,6 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
expiretask = TimerManager.getInstance().register(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MapleItemInformationProvider miip = MapleItemInformationProvider.getInstance();
|
||||
boolean deletedCoupon = false;
|
||||
|
||||
long expiration, currenttime = System.currentTimeMillis();
|
||||
@@ -2323,12 +2340,13 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
} else if (expiration != -1 && expiration < currenttime) {
|
||||
client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
|
||||
toberemove.add(item);
|
||||
if(miip.isRateCoupon(item.getItemId())) {
|
||||
if(ItemConstants.isRateCoupon(item.getItemId())) {
|
||||
deletedCoupon = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Item item : toberemove) {
|
||||
if(item.getPetId() > -1) unequipPet(getPet(getPetIndex(item.getPetId())), true);
|
||||
MapleInventoryManipulator.removeFromSlot(client, inv.getType(), item.getPosition(), item.getQuantity(), true);
|
||||
}
|
||||
toberemove.clear();
|
||||
@@ -2532,7 +2550,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
Map<String, String> character = new LinkedHashMap<>();
|
||||
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `id`, `accountid`, `name` FROM `characters` WHERE `name` = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT `id`, `accountid`, `name` FROM `characters` WHERE `name` = ?")) {
|
||||
ps.setString(1, name);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
@@ -2545,6 +2565,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
character.put(rs.getMetaData().getColumnLabel(i), rs.getString(i));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
@@ -2855,7 +2877,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
public static int getAccountIdByName(String name) {
|
||||
try {
|
||||
int id;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT accountid FROM characters WHERE name = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?")) {
|
||||
ps.setString(1, name);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
@@ -2865,6 +2889,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
id = rs.getInt("accountid");
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
return id;
|
||||
} catch (Exception e) {
|
||||
@@ -2876,7 +2902,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
public static int getIdByName(String name) {
|
||||
try {
|
||||
int id;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT id FROM characters WHERE name = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT id FROM characters WHERE name = ?")) {
|
||||
ps.setString(1, name);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
@@ -2886,6 +2913,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
id = rs.getInt("id");
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
return id;
|
||||
} catch (Exception e) {
|
||||
@@ -2897,7 +2926,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
public static String getNameById(int id) {
|
||||
try {
|
||||
String name;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name FROM characters WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT name FROM characters WHERE id = ?")) {
|
||||
ps.setInt(1, id);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
@@ -2907,6 +2937,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
name = rs.getString("name");
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
return name;
|
||||
} catch (Exception e) {
|
||||
@@ -3715,11 +3747,15 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
lastfametime = System.currentTimeMillis();
|
||||
lastmonthfameids.add(Integer.valueOf(to.getId()));
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO famelog (characterid, characterid_to) VALUES (?, ?)")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO famelog (characterid, characterid_to) VALUES (?, ?)")) {
|
||||
ps.setInt(1, getId());
|
||||
ps.setInt(2, to.getId());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -3794,7 +3830,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
|
||||
public boolean isBeginnerJob() {
|
||||
return (getJob().getId() == 0 || getJob().getId() == 1000 || getJob().getId() == 2000) && getLevel() < 11;
|
||||
return (getJob().getId() == 0 || getJob().getId() == 1000 || getJob().getId() == 2000);
|
||||
}
|
||||
|
||||
public boolean isGM() {
|
||||
@@ -3832,7 +3868,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
int improvingMaxHPLevel = 0;
|
||||
int improvingMaxMPLevel = 0;
|
||||
|
||||
if (isBeginnerJob()) {
|
||||
if (isBeginnerJob() && getLevel() < 11) {
|
||||
remainingAp = 0;
|
||||
if (getLevel() < 6) {
|
||||
str += 5;
|
||||
@@ -3904,9 +3940,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
if (level == 200) {
|
||||
exp.set(0);
|
||||
}
|
||||
hp = maxhp;
|
||||
mp = maxmp;
|
||||
recalcLocalStats();
|
||||
hp = localmaxhp;
|
||||
mp = localmaxmp;
|
||||
List<Pair<MapleStat, Integer>> statup = new ArrayList<>(10);
|
||||
statup.add(new Pair<>(MapleStat.AVAILABLEAP, remainingAp));
|
||||
statup.add(new Pair<>(MapleStat.HP, localmaxhp));
|
||||
@@ -4116,10 +4152,6 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
dropCoupon = 1;
|
||||
}
|
||||
|
||||
private boolean isExpCoupon(int couponId) {
|
||||
return couponId / 1000 == 5211;
|
||||
}
|
||||
|
||||
private int getCouponMultiplier(int couponId) {
|
||||
return activeCouponRates.get(couponId);
|
||||
}
|
||||
@@ -4152,7 +4184,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
int couponQty = coupon.getValue();
|
||||
|
||||
commitBuffCoupon(couponId);
|
||||
if(isExpCoupon(couponId)) setExpCouponRate(couponId, couponQty);
|
||||
if(ItemConstants.isExpCoupon(couponId)) setExpCouponRate(couponId, couponQty);
|
||||
else setDropCouponRate(couponId, couponQty);
|
||||
}
|
||||
}
|
||||
@@ -4162,7 +4194,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
for(Entry<Integer,Integer> coupon: activeCoupons.entrySet()) {
|
||||
int couponId = coupon.getKey();
|
||||
|
||||
if(isExpCoupon(couponId)) {
|
||||
if(ItemConstants.isExpCoupon(couponId)) {
|
||||
if(maxExpRate < getCouponMultiplier(couponId)) {
|
||||
maxExpCouponId = couponId;
|
||||
maxExpRate = getCouponMultiplier(couponId);
|
||||
@@ -4199,7 +4231,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
List<Integer> active = Server.getInstance().getActiveCoupons();
|
||||
|
||||
for(Item it: this.getInventory(MapleInventoryType.CASH).list()) {
|
||||
if(MapleItemInformationProvider.getInstance().isRateCoupon(it.getItemId()) && active.contains(it.getItemId())) {
|
||||
if(ItemConstants.isRateCoupon(it.getItemId()) && active.contains(it.getItemId())) {
|
||||
Integer count = activeCoupons.get(it.getItemId());
|
||||
|
||||
if(count != null) activeCoupons.put(it.getItemId(), count + 1);
|
||||
@@ -4231,10 +4263,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
chrLock.unlock();
|
||||
}
|
||||
|
||||
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
||||
|
||||
for (MapleBuffStatValueHolder mbsvh : allBuffs) {
|
||||
if (ii.isRateCoupon(mbsvh.effect.getSourceId())) {
|
||||
if (ItemConstants.isRateCoupon(mbsvh.effect.getSourceId())) {
|
||||
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
|
||||
}
|
||||
}
|
||||
@@ -4249,6 +4279,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
MapleCharacter ret = new MapleCharacter();
|
||||
ret.client = client;
|
||||
ret.id = charid;
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?");
|
||||
ps.setInt(1, charid);
|
||||
@@ -4570,6 +4601,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
ret.maplemount.setTiredness(mounttiredness);
|
||||
ret.maplemount.setActive(false);
|
||||
|
||||
con.close();
|
||||
return ret;
|
||||
} catch (SQLException | RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
@@ -4723,6 +4755,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -5183,6 +5216,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
ps.executeBatch();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
@@ -5191,13 +5226,16 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
|
||||
public void saveGuildStatus() {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET guildid = ?, guildrank = ?, allianceRank = ? WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET guildid = ?, guildrank = ?, allianceRank = ? WHERE id = ?")) {
|
||||
ps.setInt(1, guildid);
|
||||
ps.setInt(2, guildRank);
|
||||
ps.setInt(3, allianceRank);
|
||||
ps.setInt(4, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
@@ -5209,13 +5247,15 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
|
||||
public final boolean insertNewChar() {
|
||||
final Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
|
||||
con.setAutoCommit(false);
|
||||
ps = con.prepareStatement("INSERT INTO characters (str, dex, luk, `int`, gm, skincolor, gender, job, hair, face, map, meso, spawnpoint, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", DatabaseConnection.RETURN_GENERATED_KEYS);
|
||||
ps = con.prepareStatement("INSERT INTO characters (str, dex, luk, `int`, gm, skincolor, gender, job, hair, face, map, meso, spawnpoint, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setInt(1, 12);
|
||||
ps.setInt(2, 5);
|
||||
ps.setInt(3, 4);
|
||||
@@ -5303,6 +5343,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
con.setAutoCommit(true);
|
||||
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -5313,8 +5354,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
public synchronized void saveToDB() {
|
||||
Calendar c = Calendar.getInstance();
|
||||
FilePrinter.print(FilePrinter.SAVING_CHARACTER, "Attempting to save " + name + " at " + c.getTime().toString());
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
|
||||
con.setAutoCommit(false);
|
||||
PreparedStatement ps;
|
||||
@@ -5585,6 +5627,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
try {
|
||||
con.setAutoCommit(true);
|
||||
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -5632,13 +5675,16 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
|
||||
public void sendNote(String to, String msg, byte fame) throws SQLException {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setString(1, to);
|
||||
ps.setString(2, this.getName());
|
||||
ps.setString(3, msg);
|
||||
ps.setLong(4, System.currentTimeMillis());
|
||||
ps.setByte(5, fame);
|
||||
ps.executeUpdate();
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5759,11 +5805,15 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
|
||||
public void setHasMerchant(boolean set) {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET HasMerchant = ? WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET HasMerchant = ? WHERE id = ?")) {
|
||||
ps.setInt(1, set ? 1 : 0);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -5772,11 +5822,14 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
|
||||
public void addMerchantMesos(int add) {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setInt(1, merchantmeso + add);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
@@ -5786,11 +5839,13 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
|
||||
public void setMerchantMeso(int set) {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setInt(1, set);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
@@ -5969,11 +6024,13 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
public void changeName(String name) {
|
||||
this.name = name;
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE `characters` SET `name` = ? WHERE `id` = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE `characters` SET `name` = ? WHERE `id` = ?");
|
||||
ps.setString(1, name);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -6157,7 +6214,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
|
||||
public void showNote() {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM notes WHERE `to`=? AND `deleted` = 0", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM notes WHERE `to`=? AND `deleted` = 0", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
|
||||
ps.setString(1, this.getName());
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
rs.last();
|
||||
@@ -6166,6 +6224,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
client.announce(MaplePacketCreator.showNotes(rs, count));
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -6522,6 +6582,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
ps.setInt(3, reason);
|
||||
ps.setInt(4, accountid);
|
||||
ps.executeUpdate();
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -180,7 +180,8 @@ public class MapleClient {
|
||||
PreparedStatement ps;
|
||||
List<CharNameAndId> chars = new ArrayList<>(15);
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?");
|
||||
ps.setInt(1, this.getAccID());
|
||||
ps.setInt(2, serverId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
@@ -189,6 +190,7 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -202,7 +204,8 @@ public class MapleClient {
|
||||
public boolean hasBannedIP() {
|
||||
boolean ret = false;
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) {
|
||||
ps.setString(1, session.getRemoteAddress().toString());
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
rs.next();
|
||||
@@ -211,6 +214,7 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -222,7 +226,8 @@ public class MapleClient {
|
||||
return voteTime;
|
||||
}
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT date FROM bit_votingrecords WHERE UPPER(account) = UPPER(?)")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT date FROM bit_votingrecords WHERE UPPER(account) = UPPER(?)")) {
|
||||
ps.setString(1, accountName);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
@@ -231,6 +236,7 @@ public class MapleClient {
|
||||
voteTime = rs.getInt("date");
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
FilePrinter.printError("hasVotedAlready.txt", e);
|
||||
return -1;
|
||||
@@ -255,8 +261,10 @@ public class MapleClient {
|
||||
|
||||
boolean ret = false;
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?");
|
||||
ps.setString(1, hwid);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs != null && rs.next()) {
|
||||
@@ -270,6 +278,10 @@ public class MapleClient {
|
||||
if(ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -293,7 +305,9 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
sql.append(")");
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement(sql.toString())) {
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement(sql.toString())) {
|
||||
i = 0;
|
||||
for (String mac : macs) {
|
||||
i++;
|
||||
@@ -305,7 +319,9 @@ public class MapleClient {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -314,21 +330,25 @@ public class MapleClient {
|
||||
|
||||
private void loadHWIDIfNescessary() throws SQLException {
|
||||
if(hwid == null) {
|
||||
try(PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT hwid FROM accounts WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try(PreparedStatement ps = con.prepareStatement("SELECT hwid FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
try(ResultSet rs = ps.executeQuery()) {
|
||||
if(rs.next()) {
|
||||
hwid = rs.getString("hwid");
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Recode to close statements...
|
||||
private void loadMacsIfNescessary() throws SQLException {
|
||||
if (macs.isEmpty()) {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT macs FROM accounts WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT macs FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
@@ -339,15 +359,19 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void banHWID() {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
loadHWIDIfNescessary();
|
||||
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("INSERT INTO hwidbans (hwid) VALUES (?)");
|
||||
ps.setString(1, hwid);
|
||||
ps.executeUpdate();
|
||||
@@ -355,8 +379,12 @@ public class MapleClient {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if(ps != null && !ps.isClosed())
|
||||
if(ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -364,9 +392,11 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public void banMacs() {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
loadMacsIfNescessary();
|
||||
|
||||
con = DatabaseConnection.getConnection();
|
||||
List<String> filtered = new LinkedList<>();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT filter FROM macfilters"); ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
@@ -389,6 +419,8 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -408,11 +440,14 @@ public class MapleClient {
|
||||
public void setPin(String pin) {
|
||||
this.pin = pin;
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET pin = ? WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pin = ? WHERE id = ?")) {
|
||||
ps.setString(1, pin);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -437,11 +472,14 @@ public class MapleClient {
|
||||
public void setPic(String pic) {
|
||||
this.pic = pic;
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET pic = ? WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pic = ? WHERE id = ?")) {
|
||||
ps.setString(1, pic);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -471,10 +509,11 @@ public class MapleClient {
|
||||
getSession().close(true);
|
||||
}
|
||||
int loginok = 5;
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT id, password, salt, gender, banned, gm, pin, pic, characterslots, tos FROM accounts WHERE name = ?");
|
||||
ps.setString(1, login);
|
||||
rs = ps.executeQuery();
|
||||
@@ -522,6 +561,9 @@ public class MapleClient {
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -533,11 +575,12 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public Calendar getTempBanCalendar() {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
final Calendar lTempban = Calendar.getInstance();
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?");
|
||||
ps.setInt(1, getAccID());
|
||||
rs = ps.executeQuery();
|
||||
@@ -560,6 +603,9 @@ public class MapleClient {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -595,8 +641,10 @@ public class MapleClient {
|
||||
this.hwid = hwid.toString();
|
||||
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?");
|
||||
ps.setString(1, this.hwid);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
@@ -608,6 +656,9 @@ public class MapleClient {
|
||||
if(ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -629,8 +680,10 @@ public class MapleClient {
|
||||
newMacData.append(", ");
|
||||
}
|
||||
}
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
|
||||
ps.setString(1, newMacData.toString());
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
@@ -642,8 +695,11 @@ public class MapleClient {
|
||||
if (ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -664,6 +720,8 @@ public class MapleClient {
|
||||
ps.setInt(2, getAccID());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -714,6 +772,8 @@ public class MapleClient {
|
||||
} else {
|
||||
loggedIn = false;
|
||||
}
|
||||
|
||||
con.close();
|
||||
return state;
|
||||
} catch (SQLException e) {
|
||||
loggedIn = false;
|
||||
@@ -1006,7 +1066,8 @@ public class MapleClient {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `tos` FROM accounts WHERE id = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `tos` FROM accounts WHERE id = ?");
|
||||
ps.setInt(1, accId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -1017,10 +1078,11 @@ public class MapleClient {
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?");
|
||||
ps = con.prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?");
|
||||
ps.setInt(1, accId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1030,7 +1092,8 @@ public class MapleClient {
|
||||
public int getVotePoints(){
|
||||
int points = 0;
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `votes` FROM accounts WHERE id = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `votes` FROM accounts WHERE id = ?");
|
||||
ps.setInt(1, accId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -1040,6 +1103,7 @@ public class MapleClient {
|
||||
ps.close();
|
||||
rs.close();
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1070,6 +1134,8 @@ public class MapleClient {
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1107,15 +1173,19 @@ public class MapleClient {
|
||||
|
||||
public boolean gainCharacterSlot() {
|
||||
if (characterSlots < 15) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET characterslots = ? WHERE id = ?")) {
|
||||
ps.setInt(1, this.characterSlots += 1);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1123,10 +1193,11 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public final byte getGReason() {
|
||||
final Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT `greason` FROM `accounts` WHERE id = ?");
|
||||
ps.setInt(1, accId);
|
||||
rs = ps.executeQuery();
|
||||
@@ -1143,8 +1214,11 @@ public class MapleClient {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -1156,12 +1230,16 @@ public class MapleClient {
|
||||
|
||||
public void setGender(byte m) {
|
||||
this.gender = m;
|
||||
Connection con = null;
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) {
|
||||
ps.setByte(1, gender);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package client;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -38,7 +39,8 @@ public class MapleFamily {
|
||||
|
||||
public MapleFamily(int cid) {
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT familyid FROM family_character WHERE cid = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT familyid FROM family_character WHERE cid = ?");
|
||||
ps.setInt(1, cid);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
@@ -46,6 +48,7 @@ public class MapleFamily {
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
getMapleFamily();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -54,7 +57,8 @@ public class MapleFamily {
|
||||
|
||||
private static void getMapleFamily() {
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM family_character WHERE familyid = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM family_character WHERE familyid = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
@@ -72,6 +76,7 @@ public class MapleFamily {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MapleRing implements Comparable<MapleRing> {
|
||||
public static MapleRing loadFromDb(int ringId) {
|
||||
try {
|
||||
MapleRing ret = null;
|
||||
Connection con = DatabaseConnection.getConnection(); // Get a connection to the database
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM rings WHERE id = ?"); // Get ring details..
|
||||
ps.setInt(1, ringId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -60,6 +60,7 @@ public class MapleRing implements Comparable<MapleRing> {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return ret;
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -102,6 +103,7 @@ public class MapleRing implements Comparable<MapleRing> {
|
||||
ps.setInt(2, ringID[0]);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
return ringID[0];
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -91,7 +91,8 @@ public final class MonsterBook {
|
||||
}
|
||||
|
||||
public void loadCards(final int charid) throws SQLException {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT cardid, level FROM monsterbook WHERE charid = ? ORDER BY cardid ASC")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT cardid, level FROM monsterbook WHERE charid = ? ORDER BY cardid ASC")) {
|
||||
ps.setInt(1, charid);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
int cardid, level;
|
||||
@@ -107,6 +108,8 @@ public final class MonsterBook {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
calculateLevel();
|
||||
}
|
||||
|
||||
@@ -139,6 +142,7 @@ public final class MonsterBook {
|
||||
ps = con.prepareStatement(query.toString());
|
||||
ps.execute();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -450,7 +450,8 @@ public class Commands {
|
||||
Pair<Integer, String> data = listIterator.next();
|
||||
output += "#b" + data.getRight() + "#k is dropped by:\r\n";
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM drop_data WHERE itemid = ? LIMIT 50");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM drop_data WHERE itemid = ? LIMIT 50");
|
||||
ps.setInt(1, data.getLeft());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
@@ -461,6 +462,7 @@ public class Commands {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
player.dropMessage("There was a problem retreiving the required data. Please try again.");
|
||||
e.printStackTrace();
|
||||
@@ -641,13 +643,16 @@ public class Commands {
|
||||
case "ranks":
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT `characters`.`name`, `characters`.`level` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` = '0' AND `accounts`.`banned` = '0' ORDER BY level DESC, exp DESC LIMIT 50");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` = '0' AND `accounts`.`banned` = '0' ORDER BY level DESC, exp DESC LIMIT 50");
|
||||
rs = ps.executeQuery();
|
||||
|
||||
player.announce(MaplePacketCreator.showPlayerRanks(9010000, rs));
|
||||
ps.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
} catch(SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
@@ -658,6 +663,9 @@ public class Commands {
|
||||
if(rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1774,6 +1782,8 @@ public class Commands {
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
c.getPlayer().message("Error occured while banning IP address");
|
||||
@@ -1819,6 +1829,8 @@ public class Commands {
|
||||
|
||||
p = con.prepareStatement("DELETE FROM macbans WHERE aid = " + aid);
|
||||
p.executeUpdate();
|
||||
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
player.message("Failed to unban " + sub[1]);
|
||||
|
||||
@@ -61,6 +61,7 @@ public enum ItemFactory {
|
||||
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try {
|
||||
StringBuilder query = new StringBuilder();
|
||||
query.append("SELECT * FROM `inventoryitems` LEFT JOIN `inventoryequipment` USING(`inventoryitemid`) WHERE `type` = ? AND `");
|
||||
@@ -70,8 +71,7 @@ public enum ItemFactory {
|
||||
query.append(" AND `inventorytype` = ").append(MapleInventoryType.EQUIPPED.getType());
|
||||
}
|
||||
|
||||
|
||||
ps = DatabaseConnection.getConnection().prepareStatement(query.toString());
|
||||
ps = con.prepareStatement(query.toString());
|
||||
ps.setInt(1, value);
|
||||
ps.setInt(2, id);
|
||||
rs = ps.executeQuery();
|
||||
@@ -120,13 +120,17 @@ public enum ItemFactory {
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} finally {
|
||||
if (rs != null) {
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (ps != null) {
|
||||
if (ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ public class MapleInventory implements Iterable<Item> {
|
||||
public void addSlot(short slot, Item item) {
|
||||
inventory.put(slot, item);
|
||||
|
||||
if(MapleItemInformationProvider.getInstance().isRateCoupon(item.getItemId())) {
|
||||
if(ItemConstants.isRateCoupon(item.getItemId())) {
|
||||
owner.updateCouponRates();
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ public class MapleInventory implements Iterable<Item> {
|
||||
public void removeSlot(short slot) {
|
||||
Item item = inventory.remove(slot);
|
||||
|
||||
if(item != null && MapleItemInformationProvider.getInstance().isRateCoupon(item.getItemId())) {
|
||||
if(item != null && ItemConstants.isRateCoupon(item.getItemId())) {
|
||||
owner.updateCouponRates();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import server.movement.AbsoluteLifeMovement;
|
||||
import server.movement.LifeMovement;
|
||||
import server.movement.LifeMovementFragment;
|
||||
import client.MapleCharacter;
|
||||
import java.sql.Connection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,8 @@ public class MaplePet extends Item {
|
||||
public static MaplePet loadFromDb(int itemid, short position, int petid) {
|
||||
try {
|
||||
MaplePet ret = new MaplePet(itemid, position, petid);
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name, level, closeness, fullness, summoned FROM pets WHERE petid = ?"); // Get pet details..
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT name, level, closeness, fullness, summoned FROM pets WHERE petid = ?"); // Get pet details..
|
||||
ps.setInt(1, petid);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
@@ -71,6 +73,7 @@ public class MaplePet extends Item {
|
||||
ret.setSummoned(rs.getInt("summoned") == 1);
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return ret;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -80,7 +83,8 @@ public class MaplePet extends Item {
|
||||
|
||||
public void saveToDb() {
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE pets SET name = ?, level = ?, closeness = ?, fullness = ?, summoned = ? WHERE petid = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE pets SET name = ?, level = ?, closeness = ?, fullness = ?, summoned = ? WHERE petid = ?");
|
||||
ps.setString(1, getName());
|
||||
ps.setInt(2, getLevel());
|
||||
ps.setInt(3, getCloseness());
|
||||
@@ -89,6 +93,7 @@ public class MaplePet extends Item {
|
||||
ps.setInt(6, getUniqueId());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -96,7 +101,8 @@ public class MaplePet extends Item {
|
||||
|
||||
public static int createPet(int itemid) {
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, 1, 0, 100, 0)", Statement.RETURN_GENERATED_KEYS);
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, 1, 0, 100, 0)", Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
|
||||
ps.executeUpdate();
|
||||
ResultSet rs = ps.getGeneratedKeys();
|
||||
@@ -106,6 +112,7 @@ public class MaplePet extends Item {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return ret;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -115,7 +122,8 @@ public class MaplePet extends Item {
|
||||
|
||||
public static int createPet(int itemid, byte level, int closeness, int fullness) {
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, ?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS);
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, ?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
|
||||
ps.setByte(2, level);
|
||||
ps.setInt(3, closeness);
|
||||
@@ -125,9 +133,10 @@ public class MaplePet extends Item {
|
||||
int ret = -1;
|
||||
if (rs.next()) {
|
||||
ret = rs.getInt(1);
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return ret;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -26,6 +26,7 @@ import client.inventory.MapleInventoryType;
|
||||
/**
|
||||
*
|
||||
* @author Jay Estrella
|
||||
* @author Ronan
|
||||
*/
|
||||
public final class ItemConstants {
|
||||
public final static int LOCK = 0x01;
|
||||
@@ -89,6 +90,45 @@ public final class ItemConstants {
|
||||
public static boolean isPet(int itemId) {
|
||||
return itemId / 1000 == 5000;
|
||||
}
|
||||
|
||||
public static boolean isTownScroll(int itemId) {
|
||||
return itemId >= 2030000 && itemId < 2030021;
|
||||
}
|
||||
|
||||
public static boolean isAntibanishScroll(int itemId) {
|
||||
return itemId == 2030100;
|
||||
}
|
||||
|
||||
public static boolean isCleanSlate(int scrollId) {
|
||||
return scrollId > 2048999 && scrollId < 2049004;
|
||||
}
|
||||
|
||||
public static boolean isFlagModifier(int scrollId, byte flag) {
|
||||
if(scrollId == 2041058 && ((flag & ItemConstants.COLD) == ItemConstants.COLD)) return true;
|
||||
if(scrollId == 2040727 && ((flag & ItemConstants.SPIKES) == ItemConstants.SPIKES)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isChaosScroll(int scrollId) {
|
||||
return scrollId >= 2049100 && scrollId <= 2049103;
|
||||
}
|
||||
|
||||
public static boolean isRateCoupon(int itemId) {
|
||||
int itemType = itemId / 1000;
|
||||
return itemType == 5211 || itemType == 5360;
|
||||
}
|
||||
|
||||
public static boolean isExpCoupon(int couponId) {
|
||||
return couponId / 1000 == 5211;
|
||||
}
|
||||
|
||||
public static boolean isPartyItem(int itemId) {
|
||||
return itemId >= 2022430 && itemId <= 2022433;
|
||||
}
|
||||
|
||||
public static boolean isPartyAllcure(int itemId) {
|
||||
return itemId == 2022433;
|
||||
}
|
||||
|
||||
public static MapleInventoryType getInventoryType(final int itemId) {
|
||||
final byte type = (byte) (itemId / 1000000);
|
||||
|
||||
@@ -4,6 +4,11 @@ import java.io.FileInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ServerConstants {
|
||||
//Database Configuration
|
||||
public static String DB_URL = "";
|
||||
public static String DB_USER = "";
|
||||
public static String DB_PASS = "";
|
||||
public static final short DB_EXPERIMENTAL_POOLS = 4; //[EXPERIMENTAL] Installs a set number of database drivers/pools to hub connections. Set 0 to default.
|
||||
|
||||
//World And Version
|
||||
public static short VERSION = 83;
|
||||
@@ -21,11 +26,6 @@ public class ServerConstants {
|
||||
//Ip Configuration
|
||||
public static String HOST;
|
||||
|
||||
//Database Configuration
|
||||
public static String DB_URL = "";
|
||||
public static String DB_USER = "";
|
||||
public static String DB_PASS = "";
|
||||
|
||||
//Other Configuration
|
||||
public static boolean JAVA_8;
|
||||
public static boolean SHUTDOWNHOOK;
|
||||
@@ -59,7 +59,7 @@ public class ServerConstants {
|
||||
//Dangling Items Configuration
|
||||
public static final int ITEM_EXPIRE_TIME = 3 * 60 * 1000; //Time before items start disappearing. Recommended to be set up to 3 minutes.
|
||||
public static final int ITEM_MONITOR_TIME = 5 * 60 * 1000; //Interval between item monitoring task on maps, which checks for dangling item objects on the map item history.
|
||||
public static final int ITEM_LIMIT_ON_MAP = 777; //Max number of items allowed on a map.
|
||||
public static final int ITEM_LIMIT_ON_MAP = 250; //Max number of items allowed on a map.
|
||||
|
||||
//Some Gameplay Enhancing Configuration
|
||||
public static final boolean USE_PERFECT_SCROLLING = true; //Scrolls doesn't use slots upon failure.
|
||||
|
||||
@@ -99,12 +99,14 @@ public class RankingWorker implements Runnable {
|
||||
|
||||
con.setAutoCommit(true);
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
try {
|
||||
con.rollback();
|
||||
con.setAutoCommit(true);
|
||||
if(!con.isClosed()) con.close();
|
||||
} catch (SQLException ex2) {
|
||||
ex2.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -55,13 +55,13 @@ import org.apache.mina.filter.codec.ProtocolCodecFilter;
|
||||
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
|
||||
import server.CashShop.CashItemFactory;
|
||||
import server.MapleItemInformationProvider;
|
||||
import server.TimerManager;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.FilePrinter;
|
||||
import tools.Pair;
|
||||
import client.MapleCharacter;
|
||||
import client.SkillFactory;
|
||||
import constants.ItemConstants;
|
||||
import constants.ServerConstants;
|
||||
import java.util.Calendar;
|
||||
import server.quest.MapleQuest;
|
||||
@@ -173,7 +173,7 @@ public class Server implements Runnable {
|
||||
}
|
||||
|
||||
public void toggleCoupon(Integer couponId) {
|
||||
if(MapleItemInformationProvider.getInstance().isRateCoupon(couponId)) {
|
||||
if(ItemConstants.isRateCoupon(couponId)) {
|
||||
synchronized(activeCoupons) {
|
||||
if(activeCoupons.contains(couponId)) {
|
||||
activeCoupons.remove(couponId);
|
||||
@@ -219,8 +219,9 @@ public class Server implements Runnable {
|
||||
ex.printStackTrace();
|
||||
|
||||
try {
|
||||
if(con != null && !con.isClosed())
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex2) {
|
||||
ex2.printStackTrace();
|
||||
}
|
||||
@@ -245,9 +246,9 @@ public class Server implements Runnable {
|
||||
if(ServerConstants.SHUTDOWNHOOK)
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(shutdown(false)));
|
||||
|
||||
//DatabaseConnection.getConnection();
|
||||
Connection c = DatabaseConnection.getConnection();
|
||||
Connection c = null;
|
||||
try {
|
||||
c = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = c.prepareStatement("UPDATE accounts SET loggedin = 0");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
@@ -257,6 +258,8 @@ public class Server implements Runnable {
|
||||
|
||||
loadCouponRates(c);
|
||||
updateActiveCoupons();
|
||||
|
||||
c.close();
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -97,12 +97,15 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
private static void listBBSThreads(MapleClient c, int start) {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM bbs_threads WHERE guildid = ? ORDER BY localthreadid DESC")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM bbs_threads WHERE guildid = ? ORDER BY localthreadid DESC")) {
|
||||
ps.setInt(1, c.getPlayer().getGuildId());
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
c.announce(MaplePacketCreator.BBSThreadList(rs, start));
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
@@ -112,8 +115,9 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
if (c.getPlayer().getGuildId() <= 0) {
|
||||
return;
|
||||
}
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT threadid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?");
|
||||
ps.setInt(1, c.getPlayer().getGuildId());
|
||||
ps.setInt(2, localthreadid);
|
||||
@@ -137,6 +141,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(1, threadid);
|
||||
ps.execute();
|
||||
ps.close();
|
||||
con.close();
|
||||
displayThread(c, localthreadid);
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
@@ -149,7 +154,8 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE bbs_threads SET `name` = ?, `timestamp` = ?, " + "`icon` = ?, " + "`startpost` = ? WHERE guildid = ? AND localthreadid = ? AND (postercid = ? OR ?)")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE bbs_threads SET `name` = ?, `timestamp` = ?, " + "`icon` = ?, " + "`startpost` = ? WHERE guildid = ? AND localthreadid = ? AND (postercid = ? OR ?)")) {
|
||||
ps.setString(1, title);
|
||||
ps.setLong(2, System.currentTimeMillis());
|
||||
ps.setInt(3, icon);
|
||||
@@ -160,6 +166,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
ps.setBoolean(8, c.getGuildRank() < 3);
|
||||
ps.execute();
|
||||
}
|
||||
con.close();
|
||||
displayThread(client, localthreadid);
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
@@ -194,6 +201,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(7, nextId);
|
||||
ps.execute();
|
||||
ps.close();
|
||||
con.close();
|
||||
displayThread(client, nextId);
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
@@ -206,8 +214,9 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
if (mc.getGuildId() <= 0) {
|
||||
return;
|
||||
}
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT threadid, postercid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?");
|
||||
ps.setInt(1, mc.getGuildId());
|
||||
ps.setInt(2, localthreadid);
|
||||
@@ -233,6 +242,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
ps.execute();
|
||||
threadRS.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
@@ -244,8 +254,9 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
return;
|
||||
}
|
||||
int threadid;
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT postercid, threadid FROM bbs_replies WHERE replyid = ?");
|
||||
ps.setInt(1, replyid);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -270,6 +281,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(1, threadid);
|
||||
ps.execute();
|
||||
ps.close();
|
||||
con.close();
|
||||
displayThread(client, threadid, false);
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
@@ -285,8 +297,9 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
if (mc.getGuildId() <= 0) {
|
||||
return;
|
||||
}
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps2;
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM bbs_threads WHERE guildid = ? AND " + (bIsThreadIdLocal ? "local" : "") + "threadid = ?")) {
|
||||
ps.setInt(1, mc.getGuildId());
|
||||
@@ -310,6 +323,8 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
|
||||
if (ps2 != null) {
|
||||
ps2.close();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
} catch (RuntimeException re) {//btw we get this everytime for some reason, but replies work!
|
||||
|
||||
@@ -72,6 +72,7 @@ public class BuddylistModifyHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -129,6 +130,7 @@ public class BuddylistModifyHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
}
|
||||
if (buddyAddResult == BuddyAddResult.BUDDYLIST_FULL) {
|
||||
c.announce(MaplePacketCreator.serverNotice(1, "\"" + addName + "\"'s Buddylist is full"));
|
||||
@@ -146,6 +148,7 @@ public class BuddylistModifyHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(2, player.getId());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
con.close();
|
||||
}
|
||||
buddylist.put(new BuddylistEntry(charWithId.getName(), group, otherCid, displayChannel, true));
|
||||
c.announce(MaplePacketCreator.updateBuddylist(buddylist.getBuddies()));
|
||||
@@ -177,6 +180,7 @@ public class BuddylistModifyHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} else {
|
||||
otherName = otherChar.getName();
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public final class CouponCodeHandler extends AbstractMaplePacketHandler {
|
||||
ps.setString(2, code);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -90,7 +91,8 @@ public final class CouponCodeHandler extends AbstractMaplePacketHandler {
|
||||
private int getNXCode(String code, String type) {
|
||||
int item = -1;
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `" + type + "` FROM nxcode WHERE code = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `" + type + "` FROM nxcode WHERE code = ?");
|
||||
ps.setString(1, code);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
@@ -98,6 +100,7 @@ public final class CouponCodeHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -106,7 +109,8 @@ public final class CouponCodeHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
private boolean getNXCodeValid(String code, boolean validcode) {
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `valid` FROM nxcode WHERE code = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `valid` FROM nxcode WHERE code = ?");
|
||||
ps.setString(1, code);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
@@ -114,6 +118,7 @@ public final class CouponCodeHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
if (accountid) {
|
||||
text = "SELECT id,accountid FROM characters WHERE name = ?";
|
||||
}
|
||||
ps = DatabaseConnection.getConnection().prepareStatement(text);
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement(text);
|
||||
ps.setString(1, name);
|
||||
int id_;
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
@@ -90,6 +91,7 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
id_ = accountid ? rs.getInt("accountid") : rs.getInt("id");
|
||||
}
|
||||
ps.close();
|
||||
con.close();
|
||||
return id_;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -177,8 +179,9 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
int packageid = slea.readInt();
|
||||
List<DueyPackages> packages = new LinkedList<>();
|
||||
DueyPackages dp = null;
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
DueyPackages dueypack;
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?")) {
|
||||
ps.setInt(1, packageid);
|
||||
@@ -223,6 +226,8 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
removeItemFromDB(packageid);
|
||||
c.announce(MaplePacketCreator.removeItemFromDuey(false, packageid));
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -234,8 +239,9 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
private void addItemToDB(Item item, int quantity, int mesos, String sName, int recipientID) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO dueypackages (RecieverId, SenderName, Mesos, TimeStamp, Checked, Type) VALUES (?, ?, ?, ?, ?, ?)")) {
|
||||
ps.setInt(1, recipientID);
|
||||
ps.setString(2, sName);
|
||||
@@ -287,6 +293,8 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -294,8 +302,9 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
public static List<DueyPackages> loadItems(MapleCharacter chr) {
|
||||
List<DueyPackages> packages = new LinkedList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages dp LEFT JOIN dueyitems di ON dp.PackageId=di.PackageId WHERE RecieverId = ?")) {
|
||||
ps.setInt(1, chr.getId());
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
@@ -309,6 +318,7 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
return packages;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -346,8 +356,10 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
private void removeItemFromDB(int packageid) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement ps = con.prepareStatement("DELETE FROM dueypackages WHERE PackageId = ?");
|
||||
ps.setInt(1, packageid);
|
||||
ps.executeUpdate();
|
||||
@@ -356,6 +368,7 @@ public final class DueyHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(1, packageid);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -75,7 +75,8 @@ public final class EnterMTSHandler extends AbstractMaplePacketHandler {
|
||||
List<MTSItemInfo> items = new ArrayList<>();
|
||||
int pages = 0;
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM mts_items WHERE tab = 1 AND transfer = 0 ORDER BY id DESC LIMIT 16, 16");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = 1 AND transfer = 0 ORDER BY id DESC LIMIT 16, 16");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("type") != 1) {
|
||||
@@ -110,13 +111,15 @@ public final class EnterMTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT COUNT(*) FROM mts_items");
|
||||
|
||||
ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items");
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
pages = (int) Math.ceil(rs.getInt(1) / 16);
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -128,7 +131,8 @@ public final class EnterMTSHandler extends AbstractMaplePacketHandler {
|
||||
private List<MTSItemInfo> getNotYetSold(int cid) {
|
||||
List<MTSItemInfo> items = new ArrayList<>();
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 0 ORDER BY id DESC")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 0 ORDER BY id DESC")) {
|
||||
ps.setInt(1, cid);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
@@ -164,6 +168,7 @@ public final class EnterMTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -210,6 +215,7 @@ public final class EnterMTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ public class FredrickHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(2, chr.getId());
|
||||
ps.execute();
|
||||
}
|
||||
con.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -101,8 +101,10 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(itemid);
|
||||
Item i = c.getPlayer().getInventory(type).getItem(slot).copy();
|
||||
if (i != null && c.getPlayer().getMeso() >= 5000) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE seller = ?");
|
||||
ps.setInt(1, c.getPlayer().getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -201,6 +203,8 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
MapleInventoryManipulator.removeFromSlot(c, type, slot, quantity, false);
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -254,8 +258,9 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
|
||||
} else if (op == 7) { //cancel sale
|
||||
int id = slea.readInt(); //id of the item
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE mts_items SET transfer = 1 WHERE id = ? AND seller = ?");
|
||||
ps.setInt(1, id);
|
||||
ps.setInt(2, c.getPlayer().getId());
|
||||
@@ -265,6 +270,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(1, id);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -274,10 +280,11 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
|
||||
} else if (op == 8) { //transfer item from transfer inv.
|
||||
int id = slea.readInt(); //id of the item
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 1 AND id= ? ORDER BY id DESC");
|
||||
ps.setInt(1, c.getPlayer().getId());
|
||||
ps.setInt(2, id);
|
||||
@@ -329,14 +336,16 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("MTS Transfer error: " + e);
|
||||
}
|
||||
} else if (op == 9) { //add to cart
|
||||
int id = slea.readInt(); //id of the item
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps1 = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? AND seller <> ?")) {
|
||||
ps1.setInt(1, id);//Previene que agregues al cart tus propios items
|
||||
ps1.setInt(2, c.getPlayer().getId());
|
||||
@@ -357,6 +366,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -367,13 +377,15 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
|
||||
} else if (op == 10) { //delete from cart
|
||||
int id = slea.readInt(); //id of the item
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ? AND cid = ?")) {
|
||||
ps.setInt(1, id);
|
||||
ps.setInt(2, c.getPlayer().getId());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -386,10 +398,11 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
} else if (op == 14) { //buy auction item now
|
||||
} else if (op == 16) { //buy
|
||||
int id = slea.readInt(); //id of the item
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
@@ -442,16 +455,18 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
c.announce(MaplePacketCreator.MTSFailBuy());
|
||||
}
|
||||
} else if (op == 17) { //buy from cart
|
||||
int id = slea.readInt(); //id of the item
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
@@ -500,6 +515,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
c.announce(MaplePacketCreator.MTSFailBuy());
|
||||
@@ -514,10 +530,11 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
public List<MTSItemInfo> getNotYetSold(int cid) {
|
||||
List<MTSItemInfo> items = new ArrayList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 0 ORDER BY id DESC");
|
||||
ps.setInt(1, cid);
|
||||
rs = ps.executeQuery();
|
||||
@@ -554,6 +571,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -562,11 +580,12 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
public byte[] getCart(int cid) {
|
||||
List<MTSItemInfo> items = new ArrayList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
int pages = 0;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM mts_cart WHERE cid = ? ORDER BY id DESC");
|
||||
ps.setInt(1, cid);
|
||||
rs = ps.executeQuery();
|
||||
@@ -620,6 +639,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -628,10 +648,11 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
public List<MTSItemInfo> getTransfer(int cid) {
|
||||
List<MTSItemInfo> items = new ArrayList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM mts_items WHERE transfer = 1 AND seller = ? ORDER BY id DESC");
|
||||
ps.setInt(1, cid);
|
||||
rs = ps.executeQuery();
|
||||
@@ -668,6 +689,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -676,11 +698,12 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
private static byte[] getMTS(int tab, int type, int page) {
|
||||
List<MTSItemInfo> items = new ArrayList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
int pages = 0;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
if (type != 0) {
|
||||
ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? AND type = ? AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
|
||||
} else {
|
||||
@@ -741,6 +764,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -768,11 +792,12 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
} else {
|
||||
listaitems = " AND sellername LIKE CONCAT('%','" + search + "', '%')";
|
||||
}
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
int pages = 0;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
if (type != 0) {
|
||||
ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? " + listaitems + " AND type = ? AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
|
||||
} else {
|
||||
@@ -835,6 +860,7 @@ public final class MTSHandler extends AbstractMaplePacketHandler {
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
import client.MapleClient;
|
||||
import java.sql.Connection;
|
||||
|
||||
public final class NoteActionHandler extends AbstractMaplePacketHandler {
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
@@ -56,17 +57,19 @@ public final class NoteActionHandler extends AbstractMaplePacketHandler {
|
||||
slea.readByte(); //Fame, but we read it from the database :)
|
||||
PreparedStatement ps;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT `fame` FROM notes WHERE id=? AND deleted=0");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT `fame` FROM notes WHERE id=? AND deleted=0");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next())
|
||||
fame += rs.getInt("fame");
|
||||
rs.close();
|
||||
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE notes SET `deleted` = 1 WHERE id = ?");
|
||||
ps = con.prepareStatement("UPDATE notes SET `deleted` = 1 WHERE id = ?");
|
||||
ps.setInt(1, id);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -113,20 +113,23 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
if (buffs != null) {
|
||||
player.silentGiveBuffs(buffs);
|
||||
}
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
PreparedStatement pss = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT Mesos FROM dueypackages WHERE RecieverId = ? and Checked = 1");
|
||||
ps.setInt(1, player.getId());
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
try {
|
||||
pss = DatabaseConnection.getConnection().prepareStatement("UPDATE dueypackages SET Checked = 0 where RecieverId = ?");
|
||||
Connection con2 = DatabaseConnection.getConnection();
|
||||
pss = con2.prepareStatement("UPDATE dueypackages SET Checked = 0 where RecieverId = ?");
|
||||
pss.setInt(1, player.getId());
|
||||
pss.executeUpdate();
|
||||
pss.close();
|
||||
con2.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -145,6 +148,9 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
if (ps != null) {
|
||||
ps.close();
|
||||
}
|
||||
if (con != null) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
//ignore
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -84,8 +84,9 @@ public final class ReportHandler extends AbstractMaplePacketHandler {
|
||||
public void addReport(int reporterid, int victimid, int reason, String description, String chatlog) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Timestamp currentTimestamp = new java.sql.Timestamp(calendar.getTime().getTime());
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO reports (`reporttime`, `reporterid`, `victimid`, `reason`, `chatlog`, `description`) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
ps.setString(1, currentTimestamp.toGMTString().toString());
|
||||
ps.setInt(2, reporterid);
|
||||
@@ -96,6 +97,7 @@ public final class ReportHandler extends AbstractMaplePacketHandler {
|
||||
ps.addBatch();
|
||||
ps.executeBatch();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ public final class RingActionHandler extends AbstractMaplePacketHandler {
|
||||
ps.setInt(2, player.getPartner().getId());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class ScrollHandler extends AbstractMaplePacketHandler {
|
||||
Item scroll = useInventory.getItem(slot);
|
||||
Item wscroll = null;
|
||||
|
||||
if (((Equip) toScroll).getUpgradeSlots() < 1 && !isCleanSlate(scroll.getItemId())) {
|
||||
if (((Equip) toScroll).getUpgradeSlots() < 1 && !ItemConstants.isCleanSlate(scroll.getItemId())) {
|
||||
c.announce(MaplePacketCreator.getInventoryFull());
|
||||
return;
|
||||
}
|
||||
@@ -85,24 +85,24 @@ public final class ScrollHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isChaosScroll(scroll.getItemId()) && !isCleanSlate(scroll.getItemId())) {
|
||||
if (!ItemConstants.isChaosScroll(scroll.getItemId()) && !ItemConstants.isCleanSlate(scroll.getItemId())) {
|
||||
if (!canScroll(scroll.getItemId(), toScroll.getItemId())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isCleanSlate(scroll.getItemId()) && !(toScroll.getLevel() + toScroll.getUpgradeSlots() < ii.getEquipStats(toScroll.getItemId()).get("tuc"))) { //upgrade slots can be over because of hammers
|
||||
if (ItemConstants.isCleanSlate(scroll.getItemId()) && !(toScroll.getLevel() + toScroll.getUpgradeSlots() < ii.getEquipStats(toScroll.getItemId()).get("tuc"))) { //upgrade slots can be over because of hammers
|
||||
return;
|
||||
}
|
||||
Equip scrolled = (Equip) ii.scrollEquipWithId(toScroll, scroll.getItemId(), whiteScroll, c.getPlayer().isGM());
|
||||
ScrollResult scrollSuccess = Equip.ScrollResult.FAIL; // fail
|
||||
if (scrolled == null) {
|
||||
scrollSuccess = Equip.ScrollResult.CURSE;
|
||||
} else if (scrolled.getLevel() > oldLevel || (isCleanSlate(scroll.getItemId()) && scrolled.getUpgradeSlots() == oldSlots + 1) || isFlagModifier(scroll.getItemId(), scrolled.getFlag())) {
|
||||
} else if (scrolled.getLevel() > oldLevel || (ItemConstants.isCleanSlate(scroll.getItemId()) && scrolled.getUpgradeSlots() == oldSlots + 1) || ItemConstants.isFlagModifier(scroll.getItemId(), scrolled.getFlag())) {
|
||||
scrollSuccess = Equip.ScrollResult.SUCCESS;
|
||||
}
|
||||
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, scroll.getPosition(), (short) 1, false);
|
||||
if (whiteScroll && !isCleanSlate(scroll.getItemId())) {
|
||||
if (whiteScroll && !ItemConstants.isCleanSlate(scroll.getItemId())) {
|
||||
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, wscroll.getPosition(), (short) 1, false, false);
|
||||
}
|
||||
final List<ModifyInventory> mods = new ArrayList<>();
|
||||
@@ -124,20 +124,6 @@ public final class ScrollHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFlagModifier(int scrollId, byte flag) {
|
||||
if(scrollId == 2041058 && ((flag & ItemConstants.COLD) == ItemConstants.COLD)) return true;
|
||||
if(scrollId == 2040727 && ((flag & ItemConstants.SPIKES) == ItemConstants.SPIKES)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isCleanSlate(int scrollId) {
|
||||
return scrollId > 2048999 && scrollId < 2049004;
|
||||
}
|
||||
|
||||
private boolean isChaosScroll(int scrollId) {
|
||||
return scrollId >= 2049100 && scrollId <= 2049103;
|
||||
}
|
||||
|
||||
public boolean canScroll(int scrollid, int itemid) {
|
||||
int sid = scrollid / 100;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import client.inventory.MapleInventoryType;
|
||||
import client.inventory.MaplePet;
|
||||
import client.inventory.PetDataFactory;
|
||||
import client.SkillFactory;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import tools.DatabaseConnection;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
@@ -66,10 +67,12 @@ public final class SpawnPetHandler extends AbstractMaplePacketHandler {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("DELETE FROM pets WHERE `petid` = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("DELETE FROM pets WHERE `petid` = ?");
|
||||
ps.setInt(1, pet.getUniqueId());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import client.MapleClient;
|
||||
import client.MapleDisease;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.MapleInventoryType;
|
||||
import constants.ItemConstants;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import server.MapleInventoryManipulator;
|
||||
import server.MapleItemInformationProvider;
|
||||
@@ -66,13 +67,13 @@ public final class UseItemHandler extends AbstractMaplePacketHandler {
|
||||
remove(c, slot);
|
||||
return;
|
||||
}
|
||||
else if (isTownScroll(itemId)) {
|
||||
else if (ItemConstants.isTownScroll(itemId)) {
|
||||
if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
|
||||
remove(c, slot);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (isAntibanishScroll(itemId)) {
|
||||
else if (ItemConstants.isAntibanishScroll(itemId)) {
|
||||
if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
|
||||
remove(c, slot);
|
||||
} else {
|
||||
@@ -92,12 +93,4 @@ public final class UseItemHandler extends AbstractMaplePacketHandler {
|
||||
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
}
|
||||
|
||||
private static boolean isTownScroll(int itemId) {
|
||||
return itemId >= 2030000 && itemId < 2030021;
|
||||
}
|
||||
|
||||
private static boolean isAntibanishScroll(int itemId) {
|
||||
return itemId == 2030100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import tools.data.input.SeekableLittleEndianAccessor;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.autoban.AutobanFactory;
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -93,7 +94,8 @@ public final class WhisperHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
} else { // not found
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT gm FROM characters WHERE name = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT gm FROM characters WHERE name = ?");
|
||||
ps.setString(1, recipient);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
@@ -104,6 +106,7 @@ public final class WhisperHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
byte channel = (byte) (c.getWorldServer().find(recipient) - 1);
|
||||
if (channel > -1) {
|
||||
c.announce(MaplePacketCreator.getFindReply(recipient, channel, 3));
|
||||
|
||||
@@ -64,7 +64,8 @@ public class MapleAlliance {
|
||||
}
|
||||
try {
|
||||
ResultSet rs;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name FROM alliance WHERE name = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT name FROM alliance WHERE name = ?")) {
|
||||
ps.setString(1, name);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
@@ -74,6 +75,7 @@ public class MapleAlliance {
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
con.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -166,7 +168,6 @@ public class MapleAlliance {
|
||||
|
||||
ps.close();
|
||||
con.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
@@ -217,7 +218,6 @@ public class MapleAlliance {
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -58,8 +58,9 @@ public class MapleGuild {
|
||||
public MapleGuild(int guildid, int world) {
|
||||
this.world = world;
|
||||
members = new ArrayList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM guilds WHERE guildid = " + guildid);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (!rs.first()) {
|
||||
@@ -99,6 +100,7 @@ public class MapleGuild {
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
System.out.println("Unable to read guild information from sql" + se);
|
||||
@@ -169,6 +171,8 @@ public class MapleGuild {
|
||||
ps.close();
|
||||
this.broadcast(MaplePacketCreator.guildDisband(this.id));
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
@@ -413,13 +417,16 @@ public class MapleGuild {
|
||||
Server.getInstance().getWorld(mgc.getWorld()).setGuildAndRank(cid, 0, 5);
|
||||
} else {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`) VALUES (?, ?, ?, ?)")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`) VALUES (?, ?, ?, ?)")) {
|
||||
ps.setString(1, mgc.getName());
|
||||
ps.setString(2, initiator.getName());
|
||||
ps.setString(3, "You have been expelled from the guild.");
|
||||
ps.setLong(4, System.currentTimeMillis());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("expelMember - MapleGuild " + e);
|
||||
@@ -572,11 +579,13 @@ public class MapleGuild {
|
||||
public static void displayGuildRanks(MapleClient c, int npcid) {
|
||||
try {
|
||||
ResultSet rs;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `name`, `GP`, `logoBG`, `logoBGColor`, `logo`, `logoColor` FROM guilds WHERE NOT `guildid` = '1' ORDER BY `GP` DESC LIMIT 50")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT `name`, `GP`, `logoBG`, `logoBGColor`, `logo`, `logoColor` FROM guilds WHERE NOT `guildid` = '1' ORDER BY `GP` DESC LIMIT 50")) {
|
||||
rs = ps.executeQuery();
|
||||
c.announce(MaplePacketCreator.showGuildRanks(npcid, rs));
|
||||
}
|
||||
rs.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("failed to display guild ranks. " + e);
|
||||
@@ -590,11 +599,14 @@ public class MapleGuild {
|
||||
public void setAllianceId(int aid) {
|
||||
this.allianceId = aid;
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE guilds SET allianceId = ? WHERE guildid = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE guilds SET allianceId = ? WHERE guildid = ?")) {
|
||||
ps.setInt(1, aid);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -608,11 +620,14 @@ public class MapleGuild {
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET allianceRank = ? WHERE guildid = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET allianceRank = ? WHERE guildid = ?")) {
|
||||
ps.setInt(1, 5);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ package net.server.handlers.login;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
@@ -40,7 +41,9 @@ public final class ViewCharHandler extends AbstractMaplePacketHandler {
|
||||
short charsNum;
|
||||
List<Integer> worlds;
|
||||
List<MapleCharacter> chars;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT world, id FROM characters WHERE accountid = ?")) {
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT world, id FROM characters WHERE accountid = ?")) {
|
||||
ps.setInt(1, c.getAccID());
|
||||
charsNum = 0;
|
||||
worlds = new ArrayList<>();
|
||||
@@ -75,6 +78,8 @@ public final class ViewCharHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
c.announce(MaplePacketCreator.showAllCharacterInfo(w, chrsinworld));
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import client.BuddylistEntry;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleFamily;
|
||||
import constants.ServerConstants;
|
||||
import java.sql.Connection;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
@@ -252,12 +253,15 @@ public class World {
|
||||
|
||||
public void setOfflineGuildStatus(int guildid, int guildrank, int cid) {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET guildid = ?, guildrank = ? WHERE id = ?")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET guildid = ?, guildrank = ? WHERE id = ?")) {
|
||||
ps.setInt(1, guildid);
|
||||
ps.setInt(2, guildrank);
|
||||
ps.setInt(3, cid);
|
||||
ps.execute();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -416,29 +416,31 @@ public class AbstractPlayerInteraction {
|
||||
Item item = null;
|
||||
MaplePet evolved = null;
|
||||
int petId = -1;
|
||||
if (id >= 5000000 && id <= 5000100) {
|
||||
petId = MaplePet.createPet(id);
|
||||
|
||||
if(from != null) {
|
||||
evolved = MaplePet.loadFromDb(id, (short) 0, petId);
|
||||
|
||||
Point pos = getPlayer().getPosition();
|
||||
pos.y -= 12;
|
||||
evolved.setPos(pos);
|
||||
evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
|
||||
evolved.setStance(0);
|
||||
evolved.setSummoned(true);
|
||||
|
||||
evolved.setName(from.getName());
|
||||
evolved.setCloseness(from.getCloseness());
|
||||
evolved.setFullness(from.getFullness());
|
||||
evolved.setLevel(from.getLevel());
|
||||
evolved.saveToDb();
|
||||
}
|
||||
|
||||
//MapleInventoryManipulator.addById(c, id, (short) 1, null, petId, expires == -1 ? -1 : System.currentTimeMillis() + expires);
|
||||
}
|
||||
|
||||
if (quantity >= 0) {
|
||||
if (id >= 5000000 && id <= 5000100) {
|
||||
petId = MaplePet.createPet(id);
|
||||
|
||||
if(from != null) {
|
||||
evolved = MaplePet.loadFromDb(id, (short) 0, petId);
|
||||
|
||||
Point pos = getPlayer().getPosition();
|
||||
pos.y -= 12;
|
||||
evolved.setPos(pos);
|
||||
evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
|
||||
evolved.setStance(0);
|
||||
evolved.setSummoned(true);
|
||||
|
||||
evolved.setName(from.getName());
|
||||
evolved.setCloseness(from.getCloseness());
|
||||
evolved.setFullness(from.getFullness());
|
||||
evolved.setLevel(from.getLevel());
|
||||
evolved.saveToDb();
|
||||
}
|
||||
|
||||
//MapleInventoryManipulator.addById(c, id, (short) 1, null, petId, expires == -1 ? -1 : System.currentTimeMillis() + expires);
|
||||
}
|
||||
|
||||
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
||||
|
||||
if (ii.getInventoryType(id).equals(MapleInventoryType.EQUIP)) {
|
||||
@@ -687,7 +689,7 @@ public class AbstractPlayerInteraction {
|
||||
}
|
||||
|
||||
public void removeAll(int id, MapleClient cl) {
|
||||
MapleInventoryType invType = MapleItemInformationProvider.getInstance().getInventoryType(id);
|
||||
MapleInventoryType invType = MapleItemInformationProvider.getInstance().getInventoryType(id);
|
||||
int possessed = cl.getPlayer().getInventory(invType).countById(id);
|
||||
if (possessed > 0) {
|
||||
MapleInventoryManipulator.removeById(cl, MapleItemInformationProvider.getInstance().getInventoryType(id), id, possessed, true, false);
|
||||
|
||||
@@ -57,6 +57,7 @@ import client.Skill;
|
||||
import constants.ItemConstants;
|
||||
import constants.ServerConstants;
|
||||
import java.awt.Point;
|
||||
import java.sql.Connection;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -570,13 +571,16 @@ public class EventInstanceManager {
|
||||
|
||||
public void saveWinner(MapleCharacter chr) {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO eventstats (event, instance, characterid, channel) VALUES (?, ?, ?, ?)")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO eventstats (event, instance, characterid, channel) VALUES (?, ?, ?, ?)")) {
|
||||
ps.setString(1, em.getName());
|
||||
ps.setString(2, getName());
|
||||
ps.setInt(3, chr.getId());
|
||||
ps.setInt(4, chr.getClient().getChannel());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package scripting.portal;
|
||||
|
||||
import client.MapleClient;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -46,14 +47,16 @@ public class PortalPlayerInteraction extends AbstractPlayerInteraction {
|
||||
public boolean hasLevel30Character() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT `level` FROM `characters` WHERE accountid = ?");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT `level` FROM `characters` WHERE accountid = ?");
|
||||
ps.setInt(1, getPlayer().getAccountID());
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("level") >= 30) {
|
||||
ps.close();
|
||||
rs.close();
|
||||
ps.close();
|
||||
rs.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -67,11 +70,15 @@ public class PortalPlayerInteraction extends AbstractPlayerInteraction {
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return getPlayer().getLevel() >= 30;
|
||||
}
|
||||
|
||||
public void blockPortal() {
|
||||
|
||||
@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package scripting.reactor;
|
||||
|
||||
import client.MapleClient;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
@@ -82,7 +83,8 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
||||
if (ret == null) {
|
||||
ret = new LinkedList<>();
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT itemid, chance, questid FROM reactordrops WHERE reactorid = ? AND chance >= 0")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT itemid, chance, questid FROM reactordrops WHERE reactorid = ? AND chance >= 0")) {
|
||||
ps.setInt(1, rid);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
@@ -90,6 +92,8 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (Throwable e) {
|
||||
FilePrinter.printError(FilePrinter.REACTOR + rid + ".txt", e);
|
||||
}
|
||||
|
||||
@@ -162,8 +162,10 @@ public class CashShop {
|
||||
}
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM specialcashitems");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM specialcashitems");
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
specialcashitems.add(new SpecialCashItem(rs.getInt("sn"), rs.getInt("modifier"), rs.getByte("info")));
|
||||
@@ -172,8 +174,9 @@ public class CashShop {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) rs.close();
|
||||
if (ps != null) ps.close();
|
||||
if (rs != null && !rs.isClosed()) rs.close();
|
||||
if (ps != null && !ps.isClosed()) ps.close();
|
||||
if (con != null && !con.isClosed()) con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -206,8 +209,10 @@ public class CashShop {
|
||||
specialcashitems.clear();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM specialcashitems");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM specialcashitems");
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
specialcashitems.add(new SpecialCashItem(rs.getInt("sn"), rs.getInt("modifier"), rs.getByte("info")));
|
||||
@@ -216,14 +221,16 @@ public class CashShop {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) rs.close();
|
||||
if (ps != null) ps.close();
|
||||
if (rs != null && !rs.isClosed()) rs.close();
|
||||
if (ps != null && !ps.isClosed()) ps.close();
|
||||
if (con != null && !con.isClosed()) con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int accountId, characterId, nxCredit, maplePoint, nxPrepaid;
|
||||
private boolean opened;
|
||||
private ItemFactory factory;
|
||||
@@ -274,9 +281,11 @@ public class CashShop {
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} finally {
|
||||
if (ps != null) ps.close();
|
||||
if (rs != null) rs.close();
|
||||
if (ps != null && !ps.isClosed()) ps.close();
|
||||
if (rs != null && !rs.isClosed()) rs.close();
|
||||
if (con != null && !con.isClosed()) con.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,31 +370,35 @@ public class CashShop {
|
||||
|
||||
public void gift(int recipient, String from, String message, int sn, int ringid) {
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO `gifts` VALUES (DEFAULT, ?, ?, ?, ?, ?)");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("INSERT INTO `gifts` VALUES (DEFAULT, ?, ?, ?, ?, ?)");
|
||||
ps.setInt(1, recipient);
|
||||
ps.setString(2, from);
|
||||
ps.setString(3, message);
|
||||
ps.setInt(4, sn);
|
||||
ps.setInt(5, ringid);
|
||||
ps.executeUpdate();
|
||||
con.close();
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (ps != null) ps.close();
|
||||
if (ps != null && !ps.isClosed()) ps.close();
|
||||
if (con != null && !con.isClosed()) con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Pair<Item, String>> loadGifts() {
|
||||
List<Pair<Item, String>> gifts = new ArrayList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM `gifts` WHERE `to` = ?");
|
||||
ps.setInt(1, characterId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -419,6 +432,7 @@ public class CashShop {
|
||||
ps.setInt(1, characterId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class MakerItemFactory {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
createCache.put(toCreate, ret);
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
|
||||
@@ -65,6 +65,7 @@ import constants.ItemConstants;
|
||||
import constants.skills.Assassin;
|
||||
import constants.skills.Gunslinger;
|
||||
import constants.skills.NightWalker;
|
||||
import java.sql.Connection;
|
||||
import server.life.MapleMonsterInformationProvider;
|
||||
|
||||
/**
|
||||
@@ -533,10 +534,6 @@ public class MapleItemInformationProvider {
|
||||
return type[cat - 30];
|
||||
}
|
||||
|
||||
private boolean isCleanSlate(int scrollId) {
|
||||
return scrollId > 2048999 && scrollId < 2049004;
|
||||
}
|
||||
|
||||
private static double testYourLuck() {
|
||||
double result = 100.0, rolled;
|
||||
int i, j = ServerConstants.SCROLL_CHANCE_RATE;
|
||||
@@ -554,6 +551,14 @@ public class MapleItemInformationProvider {
|
||||
return(testYourLuck() <= prop && prop > 0.0);
|
||||
}
|
||||
|
||||
private static short getMaximumShortMaxIfOverflow(int value1, int value2) {
|
||||
return (short)Math.min(Short.MAX_VALUE, Math.max(value1, value2));
|
||||
}
|
||||
|
||||
private static short getShortMaxIfOverflow(int value) {
|
||||
return (short)Math.min(Short.MAX_VALUE, value);
|
||||
}
|
||||
|
||||
public Item scrollEquipWithId(Item equip, int scrollId, boolean usingWhiteScroll, boolean isGM) {
|
||||
if (equip instanceof Equip) {
|
||||
Equip nEquip = (Equip) equip;
|
||||
@@ -561,7 +566,7 @@ public class MapleItemInformationProvider {
|
||||
Map<String, Integer> stats = this.getEquipStats(scrollId);
|
||||
Map<String, Integer> eqstats = this.getEquipStats(equip.getItemId());
|
||||
|
||||
if (((nEquip.getUpgradeSlots() > 0 || isCleanSlate(scrollId))) || isGM) {
|
||||
if (((nEquip.getUpgradeSlots() > 0 || ItemConstants.isCleanSlate(scrollId))) || isGM) {
|
||||
if(isGM || rollSuccessChance((double)stats.get("success"))) {
|
||||
short flag = nEquip.getFlag();
|
||||
switch (scrollId) {
|
||||
@@ -600,7 +605,7 @@ public class MapleItemInformationProvider {
|
||||
for(i = 0; i < ServerConstants.SCROLL_CHANCE_RATE; i++) {
|
||||
if (nEquip.getStr() > 0) {
|
||||
temp = (nEquip.getStr() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setStr((short) Math.max(mdStr, temp));
|
||||
nEquip.setStr(getMaximumShortMaxIfOverflow(mdStr, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdStr = nEquip.getStr();
|
||||
@@ -612,7 +617,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getDex() > 0) {
|
||||
temp = (nEquip.getDex() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setDex((short) Math.max(mdDex, temp));
|
||||
nEquip.setDex(getMaximumShortMaxIfOverflow(mdDex, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdDex = nEquip.getDex();
|
||||
@@ -624,7 +629,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getInt() > 0) {
|
||||
temp = (nEquip.getInt() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setInt((short) Math.max(mdInt, temp));
|
||||
nEquip.setInt(getMaximumShortMaxIfOverflow(mdInt, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdInt = nEquip.getInt();
|
||||
@@ -636,7 +641,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getLuk() > 0) {
|
||||
temp = (nEquip.getLuk() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setLuk((short) Math.max(mdLuk, temp));
|
||||
nEquip.setLuk(getMaximumShortMaxIfOverflow(mdLuk, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdLuk = nEquip.getLuk();
|
||||
@@ -648,7 +653,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getWatk() > 0) {
|
||||
temp = (nEquip.getWatk() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setWatk((short) Math.max(mdWatk, temp));
|
||||
nEquip.setWatk(getMaximumShortMaxIfOverflow(mdWatk, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdWatk = nEquip.getWatk();
|
||||
@@ -660,7 +665,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getWdef() > 0) {
|
||||
temp = (nEquip.getWdef() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setWdef((short) Math.max(mdWdef, temp));
|
||||
nEquip.setWdef(getMaximumShortMaxIfOverflow(mdWdef, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdWdef = nEquip.getWdef();
|
||||
@@ -672,7 +677,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getMatk() > 0) {
|
||||
temp = (nEquip.getMatk() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setMatk((short) Math.max(mdMatk, temp));
|
||||
nEquip.setMatk(getMaximumShortMaxIfOverflow(mdMatk, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdMatk = nEquip.getMatk();
|
||||
@@ -684,7 +689,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getMdef() > 0) {
|
||||
temp = (nEquip.getMdef() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setMdef((short) Math.max(mdMdef, temp));
|
||||
nEquip.setMdef(getMaximumShortMaxIfOverflow(mdMdef, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdMdef = nEquip.getMdef();
|
||||
@@ -696,7 +701,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getAcc() > 0) {
|
||||
temp = (nEquip.getAcc() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setAcc((short) Math.max(mdAcc, temp));
|
||||
nEquip.setAcc(getMaximumShortMaxIfOverflow(mdAcc, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdAcc = nEquip.getAcc();
|
||||
@@ -708,7 +713,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getAvoid() > 0) {
|
||||
temp = (nEquip.getAvoid() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setAvoid((short) Math.max(mdAvoid, temp));
|
||||
nEquip.setAvoid(getMaximumShortMaxIfOverflow(mdAvoid, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdAvoid = nEquip.getAvoid();
|
||||
@@ -720,7 +725,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getSpeed() > 0) {
|
||||
temp = (nEquip.getSpeed() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setSpeed((short) Math.max(mdSpeed, temp));
|
||||
nEquip.setSpeed(getMaximumShortMaxIfOverflow(mdSpeed, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdSpeed = nEquip.getSpeed();
|
||||
@@ -732,7 +737,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getJump() > 0) {
|
||||
temp = (nEquip.getJump() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setJump((short) Math.max(mdJump, temp));
|
||||
nEquip.setJump(getMaximumShortMaxIfOverflow(mdJump, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdJump = nEquip.getJump();
|
||||
@@ -744,7 +749,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getHp() > 0) {
|
||||
temp = (nEquip.getHp() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setHp((short) Math.max(mdHp, temp));
|
||||
nEquip.setHp(getMaximumShortMaxIfOverflow(mdHp, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdHp = nEquip.getHp();
|
||||
@@ -756,7 +761,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
if (nEquip.getMp() > 0) {
|
||||
temp = (nEquip.getMp() + Randomizer.nextInt(6) * inc);
|
||||
nEquip.setMp((short) Math.max(mdMp, temp));
|
||||
nEquip.setMp(getMaximumShortMaxIfOverflow(mdMp, temp));
|
||||
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) {
|
||||
mdMp = nEquip.getMp();
|
||||
@@ -778,60 +783,60 @@ public class MapleItemInformationProvider {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) inc = 1;
|
||||
|
||||
if (nEquip.getStr() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setStr((short) Math.max(nEquip.getStr(), (nEquip.getStr() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setStr((short) Math.max(0, (nEquip.getStr() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setStr(getMaximumShortMaxIfOverflow(nEquip.getStr(), (nEquip.getStr() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setStr(getMaximumShortMaxIfOverflow(0, (nEquip.getStr() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getDex() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setDex((short) Math.max(nEquip.getDex(), (nEquip.getDex() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setDex((short) Math.max(0, (nEquip.getDex() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setDex(getMaximumShortMaxIfOverflow(nEquip.getDex(), (nEquip.getDex() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setDex(getMaximumShortMaxIfOverflow(0, (nEquip.getDex() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getInt() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setInt((short) Math.max(nEquip.getInt(), (nEquip.getInt() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setInt((short) Math.max(0, (nEquip.getInt() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setInt(getMaximumShortMaxIfOverflow(nEquip.getInt(), (nEquip.getInt() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setInt(getMaximumShortMaxIfOverflow(0, (nEquip.getInt() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getLuk() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setLuk((short) Math.max(nEquip.getLuk(), (nEquip.getLuk() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setLuk((short) Math.max(0, (nEquip.getLuk() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setLuk(getMaximumShortMaxIfOverflow(nEquip.getLuk(), (nEquip.getLuk() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setLuk(getMaximumShortMaxIfOverflow(0, (nEquip.getLuk() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getWatk() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setWatk((short) Math.max(nEquip.getWatk(), (nEquip.getWatk() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setWatk((short) Math.max(0, (nEquip.getWatk() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setWatk(getMaximumShortMaxIfOverflow(nEquip.getWatk(), (nEquip.getWatk() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setWatk(getMaximumShortMaxIfOverflow(0, (nEquip.getWatk() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getWdef() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setWdef((short) Math.max(nEquip.getWdef(), (nEquip.getWdef() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setWdef((short) Math.max(0, (nEquip.getWdef() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setWdef(getMaximumShortMaxIfOverflow(nEquip.getWdef(), (nEquip.getWdef() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setWdef(getMaximumShortMaxIfOverflow(0, (nEquip.getWdef() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getMatk() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setMatk((short) Math.max(nEquip.getMatk(), (nEquip.getMatk() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setMatk((short) Math.max(0, (nEquip.getMatk() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setMatk(getMaximumShortMaxIfOverflow(nEquip.getMatk(), (nEquip.getMatk() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setMatk(getMaximumShortMaxIfOverflow(0, (nEquip.getMatk() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getMdef() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setMdef((short) Math.max(nEquip.getMdef(), (nEquip.getMdef() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setMdef((short) Math.max(0, (nEquip.getMdef() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setMdef(getMaximumShortMaxIfOverflow(nEquip.getMdef(), (nEquip.getMdef() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setMdef(getMaximumShortMaxIfOverflow(0, (nEquip.getMdef() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getAcc() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setAcc((short) Math.max(nEquip.getAcc(), (nEquip.getAcc() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setAcc((short) Math.max(0, (nEquip.getAcc() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setAcc(getMaximumShortMaxIfOverflow(nEquip.getAcc(), (nEquip.getAcc() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setAcc(getMaximumShortMaxIfOverflow(0, (nEquip.getAcc() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getAvoid() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setAvoid((short) Math.max(nEquip.getAvoid(), (nEquip.getAvoid() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setAvoid((short) Math.max(0, (nEquip.getAvoid() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setAvoid(getMaximumShortMaxIfOverflow(nEquip.getAvoid(), (nEquip.getAvoid() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setAvoid(getMaximumShortMaxIfOverflow(0, (nEquip.getAvoid() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getSpeed() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setSpeed((short) Math.max(nEquip.getSpeed(), (nEquip.getSpeed() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setSpeed((short) Math.max(0, (nEquip.getSpeed() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setSpeed(getMaximumShortMaxIfOverflow(nEquip.getSpeed(), (nEquip.getSpeed() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setSpeed(getMaximumShortMaxIfOverflow(0, (nEquip.getSpeed() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getJump() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setJump((short) Math.max(nEquip.getJump(), (nEquip.getJump() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setJump((short) Math.max(0, (nEquip.getJump() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setJump(getMaximumShortMaxIfOverflow(nEquip.getJump(), (nEquip.getJump() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setJump(getMaximumShortMaxIfOverflow(0, (nEquip.getJump() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getHp() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setHp((short) Math.max(nEquip.getHp(), (nEquip.getHp() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setHp((short) Math.max(0, (nEquip.getHp() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setHp(getMaximumShortMaxIfOverflow(nEquip.getHp(), (nEquip.getHp() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setHp(getMaximumShortMaxIfOverflow(0, (nEquip.getHp() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
if (nEquip.getMp() > 0) {
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setMp((short) Math.max(nEquip.getMp(), (nEquip.getMp() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setMp((short) Math.max(0, (nEquip.getMp() + Randomizer.nextInt(6) * inc)));
|
||||
if(ServerConstants.USE_ENHANCED_CHSCROLL == true) nEquip.setMp(getMaximumShortMaxIfOverflow(nEquip.getMp(), (nEquip.getMp() + Randomizer.nextInt(6) * inc)));
|
||||
else nEquip.setMp(getMaximumShortMaxIfOverflow(0, (nEquip.getMp() + Randomizer.nextInt(6) * inc)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -840,46 +845,46 @@ public class MapleItemInformationProvider {
|
||||
for (Entry<String, Integer> stat : stats.entrySet()) {
|
||||
switch (stat.getKey()) {
|
||||
case "STR":
|
||||
nEquip.setStr((short) (nEquip.getStr() + stat.getValue().intValue()));
|
||||
nEquip.setStr(getShortMaxIfOverflow(nEquip.getStr() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "DEX":
|
||||
nEquip.setDex((short) (nEquip.getDex() + stat.getValue().intValue()));
|
||||
nEquip.setDex(getShortMaxIfOverflow(nEquip.getDex() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "INT":
|
||||
nEquip.setInt((short) (nEquip.getInt() + stat.getValue().intValue()));
|
||||
nEquip.setInt(getShortMaxIfOverflow(nEquip.getInt() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "LUK":
|
||||
nEquip.setLuk((short) (nEquip.getLuk() + stat.getValue().intValue()));
|
||||
nEquip.setLuk(getShortMaxIfOverflow(nEquip.getLuk() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "PAD":
|
||||
nEquip.setWatk((short) (nEquip.getWatk() + stat.getValue().intValue()));
|
||||
nEquip.setWatk(getShortMaxIfOverflow(nEquip.getWatk() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "PDD":
|
||||
nEquip.setWdef((short) (nEquip.getWdef() + stat.getValue().intValue()));
|
||||
nEquip.setWdef(getShortMaxIfOverflow(nEquip.getWdef() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "MAD":
|
||||
nEquip.setMatk((short) (nEquip.getMatk() + stat.getValue().intValue()));
|
||||
nEquip.setMatk(getShortMaxIfOverflow(nEquip.getMatk() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "MDD":
|
||||
nEquip.setMdef((short) (nEquip.getMdef() + stat.getValue().intValue()));
|
||||
nEquip.setMdef(getShortMaxIfOverflow(nEquip.getMdef() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "ACC":
|
||||
nEquip.setAcc((short) (nEquip.getAcc() + stat.getValue().intValue()));
|
||||
nEquip.setAcc(getShortMaxIfOverflow(nEquip.getAcc() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "EVA":
|
||||
nEquip.setAvoid((short) (nEquip.getAvoid() + stat.getValue().intValue()));
|
||||
nEquip.setAvoid(getShortMaxIfOverflow(nEquip.getAvoid() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "Speed":
|
||||
nEquip.setSpeed((short) (nEquip.getSpeed() + stat.getValue().intValue()));
|
||||
nEquip.setSpeed(getShortMaxIfOverflow(nEquip.getSpeed() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "Jump":
|
||||
nEquip.setJump((short) (nEquip.getJump() + stat.getValue().intValue()));
|
||||
nEquip.setJump(getShortMaxIfOverflow(nEquip.getJump() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "MHP":
|
||||
nEquip.setHp((short) (nEquip.getHp() + stat.getValue().intValue()));
|
||||
nEquip.setHp(getShortMaxIfOverflow(nEquip.getHp() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "MMP":
|
||||
nEquip.setMp((short) (nEquip.getMp() + stat.getValue().intValue()));
|
||||
nEquip.setMp(getShortMaxIfOverflow(nEquip.getMp() + stat.getValue().intValue()));
|
||||
break;
|
||||
case "afterImage":
|
||||
break;
|
||||
@@ -887,7 +892,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!isCleanSlate(scrollId)) {
|
||||
if (!ItemConstants.isCleanSlate(scrollId)) {
|
||||
if (ServerConstants.USE_PERFECT_SCROLLING == true && !isGM && !usingWhiteScroll) {
|
||||
nEquip.setUpgradeSlots((byte) (nEquip.getUpgradeSlots() - 1));
|
||||
}
|
||||
@@ -895,14 +900,14 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
if (ServerConstants.USE_PERFECT_SCROLLING == false && !isCleanSlate(scrollId)) {
|
||||
if (ServerConstants.USE_PERFECT_SCROLLING == false && !ItemConstants.isCleanSlate(scrollId)) {
|
||||
if (!isGM && !usingWhiteScroll) {
|
||||
nEquip.setUpgradeSlots((byte) (nEquip.getUpgradeSlots() - 1));
|
||||
}
|
||||
//nEquip.setLevel((byte) (nEquip.getLevel() + 1));
|
||||
}
|
||||
} else {
|
||||
if (!usingWhiteScroll && !isCleanSlate(scrollId) && !isGM) {
|
||||
if (!usingWhiteScroll && !ItemConstants.isCleanSlate(scrollId) && !isGM) {
|
||||
nEquip.setUpgradeSlots((byte) (nEquip.getUpgradeSlots() - 1));
|
||||
}
|
||||
if (Randomizer.nextInt(101) < stats.get("cursed")) {
|
||||
@@ -1153,24 +1158,30 @@ public class MapleItemInformationProvider {
|
||||
private void loadCardIdData() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT cardid, mobid FROM monstercarddata");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT cardid, mobid FROM monstercarddata");
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
monsterBookID.put(rs.getInt(1), rs.getInt(2));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (ps != null) {
|
||||
if (ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1307,20 +1318,6 @@ public class MapleItemInformationProvider {
|
||||
eq.getAvoid() > 0 || eq.getSpeed() > 0 || eq.getJump() > 0 || eq.getHp() > 0 || eq.getMp() > 0);
|
||||
}
|
||||
|
||||
|
||||
public boolean isRateCoupon(int itemId) {
|
||||
int itemType = itemId / 1000;
|
||||
return itemType == 5211 || itemType == 5360;
|
||||
}
|
||||
|
||||
public boolean isPartyItem(int itemId) {
|
||||
return itemId >= 2022430 && itemId <= 2022433;
|
||||
}
|
||||
|
||||
public boolean isPartyAllcure(int itemId) {
|
||||
return itemId == 2022433;
|
||||
}
|
||||
|
||||
public Collection<Item> canWearEquipment(MapleCharacter chr, Collection<Item> items) {
|
||||
MapleInventory inv = chr.getInventory(MapleInventoryType.EQUIPPED);
|
||||
if (inv.checked()) {
|
||||
@@ -1523,9 +1520,10 @@ public class MapleItemInformationProvider {
|
||||
|
||||
public Set<String> getWhoDrops(Integer itemId) {
|
||||
Set<String> list = new HashSet<>();
|
||||
|
||||
Connection con = null;
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM drop_data WHERE itemid = ? LIMIT 50");
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM drop_data WHERE itemid = ? LIMIT 50");
|
||||
ps.setInt(1, itemId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
@@ -1536,6 +1534,7 @@ public class MapleItemInformationProvider {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -233,6 +233,7 @@ public class MapleShop {
|
||||
} else {
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return null;
|
||||
}
|
||||
ps = con.prepareStatement("SELECT * FROM shopitems WHERE shopid = ? ORDER BY position DESC");
|
||||
@@ -255,6 +256,7 @@ public class MapleShop {
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -61,11 +61,14 @@ public class MapleStorage {
|
||||
|
||||
private static MapleStorage create(int id, int world) {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO storages (accountid, world, slots, meso) VALUES (?, ?, 4, 0)")) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO storages (accountid, world, slots, meso) VALUES (?, ?, 4, 0)")) {
|
||||
ps.setInt(1, id);
|
||||
ps.setInt(2, world);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -84,6 +87,7 @@ public class MapleStorage {
|
||||
if (!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return create(id, world);
|
||||
} else {
|
||||
storeId = rs.getInt("storageid");
|
||||
@@ -94,6 +98,8 @@ public class MapleStorage {
|
||||
ret.items.add(item.getLeft());
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -59,9 +59,10 @@ public class MapleMonsterInformationProvider {
|
||||
private void retrieveGlobal() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
|
||||
try {
|
||||
final Connection con = DatabaseConnection.getConnection();
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM drop_data_global WHERE chance > 0");
|
||||
rs = ps.executeQuery();
|
||||
|
||||
@@ -76,18 +77,23 @@ public class MapleMonsterInformationProvider {
|
||||
rs.getInt("maximum_quantity"),
|
||||
rs.getShort("questid")));
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Error retrieving drop" + e);
|
||||
} finally {
|
||||
try {
|
||||
if (ps != null) {
|
||||
if (ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if (rs != null) {
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
@@ -102,8 +108,10 @@ public class MapleMonsterInformationProvider {
|
||||
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM drop_data WHERE dropperid = ?");
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT * FROM drop_data WHERE dropperid = ?");
|
||||
ps.setInt(1, monsterId);
|
||||
rs = ps.executeQuery();
|
||||
|
||||
@@ -116,17 +124,22 @@ public class MapleMonsterInformationProvider {
|
||||
rs.getInt("maximum_quantity"),
|
||||
rs.getShort("questid")));
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
return ret;
|
||||
} finally {
|
||||
try {
|
||||
if (ps != null) {
|
||||
if (ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if (rs != null) {
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ignore) {
|
||||
ignore.printStackTrace();
|
||||
return ret;
|
||||
|
||||
@@ -167,10 +167,14 @@ public class HiredMerchant extends AbstractMapleMapObject {
|
||||
owner.addMerchantMesos(price);
|
||||
} else {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET MerchantMesos = MerchantMesos + " + price + " WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET MerchantMesos = MerchantMesos + " + price + " WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setInt(1, ownerId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -204,57 +208,67 @@ public class HiredMerchant extends AbstractMapleMapObject {
|
||||
|
||||
map.removeMapObject(this);
|
||||
|
||||
MapleCharacter player = Server.getInstance().getWorld(world).getPlayerStorage().getCharacterById(ownerId);
|
||||
if(player != null) {
|
||||
player.setHasMerchant(false);
|
||||
} else {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET HasMerchant = 0 WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setInt(1, ownerId);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
MapleCharacter player = Server.getInstance().getWorld(world).getPlayerStorage().getCharacterById(ownerId);
|
||||
if(player != null) {
|
||||
player.setHasMerchant(false);
|
||||
} else {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE characters SET HasMerchant = 0 WHERE id = ?", Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setInt(1, ownerId);
|
||||
ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
map = null;
|
||||
schedule = null;
|
||||
}
|
||||
|
||||
public void closeShop(MapleClient c, boolean timeout) {
|
||||
map.removeMapObject(this);
|
||||
map.broadcastMessage(MaplePacketCreator.destroyHiredMerchant(ownerId));
|
||||
c.getChannelServer().removeHiredMerchant(ownerId);
|
||||
try {
|
||||
MapleCharacter player = c.getWorldServer().getPlayerStorage().getCharacterById(ownerId);
|
||||
if(player != null) {
|
||||
player.setHasMerchant(false);
|
||||
} else {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET HasMerchant = 0 WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setInt(1, ownerId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
}
|
||||
if (check(c.getPlayer(), getItems()) && !timeout) {
|
||||
for (MaplePlayerShopItem mpsi : getItems()) {
|
||||
if (mpsi.isExist() && (mpsi.getItem().getType() == MapleInventoryType.EQUIP.getType())) {
|
||||
MapleInventoryManipulator.addFromDrop(c, mpsi.getItem(), false);
|
||||
} else if (mpsi.isExist()) {
|
||||
MapleInventoryManipulator.addById(c, mpsi.getItem().getItemId(), (short) (mpsi.getBundles() * mpsi.getItem().getQuantity()), null, -1, mpsi.getItem().getFlag(), mpsi.getItem().getExpiration());
|
||||
}
|
||||
}
|
||||
items.clear();
|
||||
}
|
||||
map.removeMapObject(this);
|
||||
map.broadcastMessage(MaplePacketCreator.destroyHiredMerchant(ownerId));
|
||||
c.getChannelServer().removeHiredMerchant(ownerId);
|
||||
|
||||
try {
|
||||
this.saveItems(timeout);
|
||||
MapleCharacter player = c.getWorldServer().getPlayerStorage().getCharacterById(ownerId);
|
||||
if(player != null) {
|
||||
player.setHasMerchant(false);
|
||||
} else {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET HasMerchant = 0 WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setInt(1, ownerId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
con.close();
|
||||
}
|
||||
|
||||
if (check(c.getPlayer(), getItems()) && !timeout) {
|
||||
for (MaplePlayerShopItem mpsi : getItems()) {
|
||||
if (mpsi.isExist() && (mpsi.getItem().getType() == MapleInventoryType.EQUIP.getType())) {
|
||||
MapleInventoryManipulator.addFromDrop(c, mpsi.getItem(), false);
|
||||
} else if (mpsi.isExist()) {
|
||||
MapleInventoryManipulator.addById(c, mpsi.getItem().getItemId(), (short) (mpsi.getBundles() * mpsi.getItem().getQuantity()), null, -1, mpsi.getItem().getFlag(), mpsi.getItem().getExpiration());
|
||||
}
|
||||
}
|
||||
items.clear();
|
||||
}
|
||||
|
||||
try {
|
||||
this.saveItems(timeout);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
items.clear();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
items.clear();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
schedule.cancel(false);
|
||||
schedule.cancel(false);
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
@@ -343,8 +357,10 @@ public class HiredMerchant extends AbstractMapleMapObject {
|
||||
itemsWithType.add(new Pair<>(newItem, MapleInventoryType.getByType(newItem.getType())));
|
||||
}
|
||||
}
|
||||
|
||||
ItemFactory.MERCHANT.saveItems(itemsWithType, this.ownerId, DatabaseConnection.getConnection());
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
ItemFactory.MERCHANT.saveItems(itemsWithType, this.ownerId, con);
|
||||
con.close();
|
||||
}
|
||||
|
||||
private static boolean check(MapleCharacter chr, List<MaplePlayerShopItem> items) {
|
||||
|
||||
@@ -23,8 +23,10 @@ package server.maps;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@@ -168,7 +170,9 @@ public class MapleMapFactory {
|
||||
map.addMapleArea(new Rectangle(x1, y1, (x2 - x1), (y2 - y1)));
|
||||
}
|
||||
}
|
||||
try { try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM playernpcs WHERE map = ?")) {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE map = ?")) {
|
||||
ps.setInt(1, omapid);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
@@ -176,7 +180,9 @@ public class MapleMapFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import client.MapleClient;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
@@ -54,7 +55,9 @@ public class PlayerNPCs extends AbstractMapleMapObject {
|
||||
RX1 = rs.getInt("rx1");
|
||||
npcId = rs.getInt("ScriptId");
|
||||
setPosition(new Point(rs.getInt("x"), CY));
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT equippos, equipid FROM playernpcs_equip WHERE NpcId = ?");
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT equippos, equipid FROM playernpcs_equip WHERE NpcId = ?");
|
||||
ps.setInt(1, rs.getInt("id"));
|
||||
ResultSet rs2 = ps.executeQuery();
|
||||
while (rs2.next()) {
|
||||
@@ -62,6 +65,7 @@ public class PlayerNPCs extends AbstractMapleMapObject {
|
||||
}
|
||||
rs2.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -147,8 +147,9 @@ public class MonsterCarnival {
|
||||
}
|
||||
|
||||
public void saveResults() {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO carnivalresults VALUES (?,?,?,?)");
|
||||
for (MapleCharacter chr : red.getMembers()) {
|
||||
ps.setInt(1, chr.getId());
|
||||
@@ -165,6 +166,7 @@ public class MonsterCarnival {
|
||||
ps.execute();
|
||||
}
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import provider.MapleDataProviderFactory;
|
||||
import provider.MapleDataTool;
|
||||
import server.quest.actions.*;
|
||||
import server.quest.requirements.*;
|
||||
import tools.FilePrinter;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
@@ -113,8 +112,9 @@ public class MapleQuest {
|
||||
for (MapleData completeReq : completeReqData.getChildren()) {
|
||||
MapleQuestRequirementType type = MapleQuestRequirementType.getByWZName(completeReq.getName());
|
||||
MapleQuestRequirement req = this.getRequirement(type, completeReq);
|
||||
if(req == null)
|
||||
continue;
|
||||
|
||||
if(req == null)
|
||||
continue;
|
||||
|
||||
if (type.equals(MapleQuestRequirementType.INFO_NUMBER)) {
|
||||
infoNumber = (short) MapleDataTool.getInt(completeReq, 0);
|
||||
@@ -230,6 +230,9 @@ public class MapleQuest {
|
||||
}
|
||||
for (MapleQuestRequirement r : completeReqs.values()) {
|
||||
if (r == null || !r.check(c, npcid)) {
|
||||
if(r.getType() == MapleQuestRequirementType.MESO) { // TODO: find a way to tell the client about the new MESO requirement type.
|
||||
c.dropMessage(5, "You don't have enough mesos to complete this quest.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -402,6 +405,9 @@ public class MapleQuest {
|
||||
case MAX_LEVEL:
|
||||
ret = new MaxLevelRequirement(this, data);
|
||||
break;
|
||||
case MESO:
|
||||
ret = new MesoRequirement(this, data);
|
||||
break;
|
||||
case MIN_LEVEL:
|
||||
ret = new MinLevelRequirement(this, data);
|
||||
break;
|
||||
|
||||
@@ -26,7 +26,7 @@ package server.quest;
|
||||
* @author Matze
|
||||
*/
|
||||
public enum MapleQuestRequirementType {
|
||||
UNDEFINED(-1), JOB(0), ITEM(1), QUEST(2), MIN_LEVEL(3), MAX_LEVEL(4), END_DATE(5), MOB(6), NPC(7), FIELD_ENTER(8), INTERVAL(9), SCRIPT(10), PET(11), MIN_PET_TAMENESS(12), MONSTER_BOOK(13), NORMAL_AUTO_START(14), INFO_NUMBER(15), INFO_EX(16), COMPLETED_QUEST(17), START(18), END(19), DAY_BY_DAY(20);
|
||||
UNDEFINED(-1), JOB(0), ITEM(1), QUEST(2), MIN_LEVEL(3), MAX_LEVEL(4), END_DATE(5), MOB(6), NPC(7), FIELD_ENTER(8), INTERVAL(9), SCRIPT(10), PET(11), MIN_PET_TAMENESS(12), MONSTER_BOOK(13), NORMAL_AUTO_START(14), INFO_NUMBER(15), INFO_EX(16), COMPLETED_QUEST(17), START(18), END(19), DAY_BY_DAY(20), MESO(21);
|
||||
final byte type;
|
||||
|
||||
private MapleQuestRequirementType(int type) {
|
||||
@@ -82,6 +82,8 @@ public enum MapleQuestRequirementType {
|
||||
return END;
|
||||
} else if(name.equals("daybyday")) {
|
||||
return DAY_BY_DAY;
|
||||
} else if (name.equals("money")) {
|
||||
return MESO;
|
||||
} else {
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
52
src/server/quest/requirements/MesoRequirement.java
Normal file
52
src/server/quest/requirements/MesoRequirement.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package server.quest.requirements;
|
||||
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataTool;
|
||||
import server.quest.MapleQuest;
|
||||
import server.quest.MapleQuestRequirementType;
|
||||
import client.MapleCharacter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MesoRequirement extends MapleQuestRequirement {
|
||||
private int meso = 0;
|
||||
|
||||
public MesoRequirement(MapleQuest quest, MapleData data) {
|
||||
super(MapleQuestRequirementType.MESO);
|
||||
processData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processData(MapleData data) {
|
||||
meso = MapleDataTool.getInt(data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean check(MapleCharacter chr, Integer npcid) {
|
||||
return chr.getMeso() >= meso;
|
||||
}
|
||||
}
|
||||
@@ -3,47 +3,89 @@ package tools;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import org.apache.commons.dbcp2.ConnectionFactory;
|
||||
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
|
||||
import org.apache.commons.dbcp2.PoolableConnectionFactory;
|
||||
import org.apache.commons.dbcp2.PoolingDriver;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPool;
|
||||
|
||||
import constants.ServerConstants;
|
||||
|
||||
/**
|
||||
* @author Frz (Big Daddy)
|
||||
* @author The Real Spookster (some modifications to this beautiful code)
|
||||
* @author Ronan (some connection pool to this beautiful code)
|
||||
*/
|
||||
public class DatabaseConnection {
|
||||
|
||||
public static final int RETURN_GENERATED_KEYS = 1;
|
||||
|
||||
private static ThreadLocal<Connection> con = new ThreadLocalConnection();
|
||||
|
||||
public static Connection getConnection() {
|
||||
Connection c = con.get();
|
||||
try {
|
||||
c.getMetaData();
|
||||
} catch (SQLException e) { // connection is dead, therefore discard old object 5ever
|
||||
con.remove();
|
||||
c = con.get();
|
||||
private static Properties prop;
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
if(prop != null) {
|
||||
Connection con = null;
|
||||
while(con == null) { //oh yes, this will loop until success!
|
||||
try {
|
||||
con = DriverManager.getConnection(ServerConstants.DB_URL, prop);
|
||||
} catch (SQLException sqle) {}
|
||||
}
|
||||
|
||||
return con;
|
||||
} else {
|
||||
return DriverManager.getConnection(ServerConstants.DB_URL, ServerConstants.DB_USER, ServerConstants.DB_PASS);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private static Properties getProperties() {
|
||||
Properties connectionProperties = new Properties();
|
||||
connectionProperties.put("user", ServerConstants.DB_USER);
|
||||
connectionProperties.put("password", ServerConstants.DB_PASS);
|
||||
|
||||
connectionProperties.put("minIdle", "-1");
|
||||
connectionProperties.put("maxIdle", "-1");
|
||||
|
||||
connectionProperties.put("testOnBorrow", "true");
|
||||
connectionProperties.put("lifo", "false");
|
||||
|
||||
connectionProperties.put("maxTotal", "42"); //max allotted connections
|
||||
connectionProperties.put("maxConnLifetimeMillis", "60000"); //connection remains valid for 1 min
|
||||
connectionProperties.put("maxWaitMillis", "777"); //there are more pools, if this one is unavailable then pass to another already
|
||||
connectionProperties.put("poolPreparedStatements", "true");
|
||||
connectionProperties.put("maxOpenPreparedStatements", "100"); //max allotted PS
|
||||
|
||||
return connectionProperties;
|
||||
}
|
||||
|
||||
private PoolingDriver installDriver(short id) {
|
||||
GenericObjectPool connectionPool = new GenericObjectPool(null);
|
||||
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(ServerConstants.DB_URL, prop);
|
||||
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool.getJmxName());
|
||||
PoolingDriver driver = new PoolingDriver();
|
||||
driver.registerPool("maplesolaxiapool" + id, connectionPool);
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
private static class ThreadLocalConnection extends ThreadLocal<Connection> {
|
||||
|
||||
@Override
|
||||
protected Connection initialValue() {
|
||||
public DatabaseConnection() {
|
||||
prop = null;
|
||||
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver"); // touch the mysql driver
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println("[SEVERE] SQL Driver Not Found. Consider death by clams.");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if(ServerConstants.DB_EXPERIMENTAL_POOLS > 0) {
|
||||
// Connection Pool on database ftw!
|
||||
|
||||
prop = getProperties();
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver"); // touch the mysql driver
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println("[SEVERE] SQL Driver Not Found. Consider death by clams.");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return DriverManager.getConnection(ServerConstants.DB_URL, ServerConstants.DB_USER, ServerConstants.DB_PASS);
|
||||
} catch (SQLException e) {
|
||||
System.out.println("[SEVERE] Unable to make database connection.");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
for(short i = 0; i < ServerConstants.DB_EXPERIMENTAL_POOLS; i++) {
|
||||
DriverManager.registerDriver(installDriver(i));
|
||||
}
|
||||
} catch(SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user