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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user