refactor: use try-with-resources for Duey db operations
This commit is contained in:
@@ -34,16 +34,6 @@ import client.inventory.manipulator.MapleInventoryManipulator;
|
|||||||
import client.inventory.manipulator.MapleKarmaManipulator;
|
import client.inventory.manipulator.MapleKarmaManipulator;
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.inventory.ItemConstants;
|
import constants.inventory.ItemConstants;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import net.server.channel.Channel;
|
import net.server.channel.Channel;
|
||||||
import server.DueyPackage;
|
import server.DueyPackage;
|
||||||
import server.MapleItemInformationProvider;
|
import server.MapleItemInformationProvider;
|
||||||
@@ -53,8 +43,13 @@ import tools.FilePrinter;
|
|||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
import tools.Pair;
|
import tools.Pair;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author RonanLana - synchronization of Duey modules
|
* @author RonanLana - synchronization of Duey modules
|
||||||
*/
|
*/
|
||||||
public class DueyProcessor {
|
public class DueyProcessor {
|
||||||
@@ -84,7 +79,7 @@ public class DueyProcessor {
|
|||||||
TOCLIENT_RECV_PACKAGE_MSG(0x1B);
|
TOCLIENT_RECV_PACKAGE_MSG(0x1B);
|
||||||
final byte code;
|
final byte code;
|
||||||
|
|
||||||
private Actions(int code) {
|
Actions(int code) {
|
||||||
this.code = (byte) code;
|
this.code = (byte) code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,69 +89,40 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Pair<Integer, Integer> getAccountCharacterIdFromCNAME(String name) {
|
private static Pair<Integer, Integer> getAccountCharacterIdFromCNAME(String name) {
|
||||||
try {
|
Pair<Integer, Integer> ids = null;
|
||||||
Connection con = DatabaseConnection.getConnection();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT id,accountid FROM characters WHERE name = ?");
|
PreparedStatement ps = con.prepareStatement("SELECT id,accountid FROM characters WHERE name = ?")) {
|
||||||
ps.setString(1, name);
|
ps.setString(1, name);
|
||||||
|
|
||||||
Pair<Integer, Integer> id_ = null;
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
id_ = new Pair<>(rs.getInt("accountid"), rs.getInt("id"));
|
ids = new Pair<>(rs.getInt("accountid"), rs.getInt("id"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ps.close();
|
|
||||||
con.close();
|
|
||||||
return id_;
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showDueyNotification(MapleClient c, MapleCharacter player) {
|
private static void showDueyNotification(MapleClient c, MapleCharacter player) {
|
||||||
Connection con = null;
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = con.prepareStatement("SELECT SenderName, Type FROM dueypackages WHERE ReceiverId = ? AND Checked = 1 ORDER BY Type DESC")) {
|
||||||
PreparedStatement pss = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
con = DatabaseConnection.getConnection();
|
|
||||||
ps = con.prepareStatement("SELECT SenderName, Type FROM dueypackages WHERE ReceiverId = ? AND Checked = 1 ORDER BY Type DESC");
|
|
||||||
ps.setInt(1, player.getId());
|
ps.setInt(1, player.getId());
|
||||||
rs = ps.executeQuery();
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
try {
|
try (PreparedStatement ps2 = con.prepareStatement("UPDATE dueypackages SET Checked = 0 where ReceiverId = ?")) {
|
||||||
Connection con2 = DatabaseConnection.getConnection();
|
ps2.setInt(1, player.getId());
|
||||||
pss = con2.prepareStatement("UPDATE dueypackages SET Checked = 0 where ReceiverId = ?");
|
ps2.executeUpdate();
|
||||||
pss.setInt(1, player.getId());
|
|
||||||
pss.executeUpdate();
|
|
||||||
pss.close();
|
|
||||||
con2.close();
|
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.sendDueyParcelReceived(rs.getString("SenderName"), rs.getInt("Type") == 1));
|
c.announce(MaplePacketCreator.sendDueyParcelReceived(rs.getString("SenderName"), rs.getInt("Type") == 1));
|
||||||
} catch (SQLException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (rs != null) {
|
|
||||||
rs.close();
|
|
||||||
}
|
|
||||||
if (pss != null) {
|
|
||||||
pss.close();
|
|
||||||
}
|
|
||||||
if (ps != null) {
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
if (con != null) {
|
|
||||||
con.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,17 +131,12 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void removePackageFromDB(int packageId) {
|
private static void removePackageFromDB(int packageId) {
|
||||||
try {
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
Connection con = DatabaseConnection.getConnection();
|
PreparedStatement ps = con.prepareStatement("DELETE FROM dueypackages WHERE PackageId = ?")) {
|
||||||
|
|
||||||
PreparedStatement ps = con.prepareStatement("DELETE FROM dueypackages WHERE PackageId = ?");
|
|
||||||
ps.setInt(1, packageId);
|
ps.setInt(1, packageId);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
|
||||||
|
|
||||||
deletePackageFromInventoryDB(con, packageId);
|
deletePackageFromInventoryDB(con, packageId);
|
||||||
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -208,21 +169,21 @@ public class DueyProcessor {
|
|||||||
|
|
||||||
private static List<DueyPackage> loadPackages(MapleCharacter chr) {
|
private static List<DueyPackage> loadPackages(MapleCharacter chr) {
|
||||||
List<DueyPackage> packages = new LinkedList<>();
|
List<DueyPackage> packages = new LinkedList<>();
|
||||||
try {
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
Connection con = DatabaseConnection.getConnection();
|
PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages dp WHERE ReceiverId = ?")) {
|
||||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages dp WHERE ReceiverId = ?")) {
|
|
||||||
ps.setInt(1, chr.getId());
|
ps.setInt(1, chr.getId());
|
||||||
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
DueyPackage dueypack = getPackageFromDB(rs);
|
DueyPackage dueypack = getPackageFromDB(rs);
|
||||||
if (dueypack == null) continue;
|
if (dueypack == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
packages.add(dueypack);
|
packages.add(dueypack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -231,14 +192,8 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int createPackage(int mesos, String message, String sender, int toCid, boolean quick) {
|
private static int createPackage(int mesos, String message, String sender, int toCid, boolean quick) {
|
||||||
try {
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
Connection con = null;
|
PreparedStatement ps = con.prepareStatement("INSERT INTO `dueypackages` (ReceiverId, SenderName, Mesos, TimeStamp, Message, Type, Checked) VALUES (?, ?, ?, ?, ?, ?, 1)", Statement.RETURN_GENERATED_KEYS)) {
|
||||||
PreparedStatement ps = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
con = DatabaseConnection.getConnection();
|
|
||||||
ps = con.prepareStatement("INSERT INTO `dueypackages` (ReceiverId, SenderName, Mesos, TimeStamp, Message, Type, Checked) VALUES (?, ?, ?, ?, ?, ?, 1)", Statement.RETURN_GENERATED_KEYS);
|
|
||||||
ps.setInt(1, toCid);
|
ps.setInt(1, toCid);
|
||||||
ps.setString(2, sender);
|
ps.setString(2, sender);
|
||||||
ps.setInt(3, mesos);
|
ps.setInt(3, mesos);
|
||||||
@@ -252,29 +207,17 @@ public class DueyProcessor {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int packageId;
|
final int packageId;
|
||||||
rs = ps.getGeneratedKeys();
|
try (ResultSet rs = ps.getGeneratedKeys()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
packageId = rs.getInt(1);
|
packageId = rs.getInt(1);
|
||||||
} else {
|
} else {
|
||||||
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Failed inserting package [mesos: " + mesos + ", " + sender + ", quick: " + quick + ", to CharacterId: " + toCid + "]");
|
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Failed inserting package [mesos: " + mesos + ", " + sender + ", quick: " + quick + ", to CharacterId: " + toCid + "]");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return packageId;
|
return packageId;
|
||||||
} finally {
|
|
||||||
if (rs != null && !rs.isClosed()) {
|
|
||||||
rs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ps != null && !ps.isClosed()) {
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (con != null && !con.isClosed()) {
|
|
||||||
con.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
sqle.printStackTrace();
|
sqle.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -283,19 +226,16 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean insertPackageItem(int packageId, Item item) {
|
private static boolean insertPackageItem(int packageId, Item item) {
|
||||||
try {
|
|
||||||
Pair<Item, MapleInventoryType> dueyItem = new Pair<>(item, MapleInventoryType.getByType(item.getItemType()));
|
Pair<Item, MapleInventoryType> dueyItem = new Pair<>(item, MapleInventoryType.getByType(item.getItemType()));
|
||||||
Connection con = DatabaseConnection.getConnection();
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
ItemFactory.DUEY.saveItems(Collections.singletonList(dueyItem), packageId, con);
|
ItemFactory.DUEY.saveItems(Collections.singletonList(dueyItem), packageId, con);
|
||||||
con.close();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
sqle.printStackTrace();
|
sqle.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static int addPackageItemFromInventory(int packageId, MapleClient c, byte invTypeId, short itemPos, short amount) {
|
private static int addPackageItemFromInventory(int packageId, MapleClient c, byte invTypeId, short itemPos, short amount) {
|
||||||
if (invTypeId > 0) {
|
if (invTypeId > 0) {
|
||||||
@@ -407,9 +347,9 @@ public class DueyProcessor {
|
|||||||
int channel = c.getWorldServer().find(recipient);
|
int channel = c.getWorldServer().find(recipient);
|
||||||
if (channel > -1) {
|
if (channel > -1) {
|
||||||
Channel rcserv = c.getWorldServer().getChannel(channel);
|
Channel rcserv = c.getWorldServer().getChannel(channel);
|
||||||
if(rcserv != null) {
|
if (rcserv != null) {
|
||||||
MapleCharacter rChr = rcserv.getPlayerStorage().getCharacterByName(recipient);
|
MapleCharacter rChr = rcserv.getPlayerStorage().getCharacterByName(recipient);
|
||||||
if(rChr != null) {
|
if (rChr != null) {
|
||||||
rClient = rChr.getClient();
|
rClient = rChr.getClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -440,9 +380,8 @@ public class DueyProcessor {
|
|||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
DueyPackage dp = null;
|
DueyPackage dp = null;
|
||||||
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
Connection con = DatabaseConnection.getConnection();
|
PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages dp WHERE PackageId = ?")) {
|
||||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages dp WHERE PackageId = ?")) {
|
|
||||||
ps.setInt(1, packageId);
|
ps.setInt(1, packageId);
|
||||||
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
@@ -451,7 +390,6 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
con.close();
|
|
||||||
|
|
||||||
if (dp == null) {
|
if (dp == null) {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
|
||||||
@@ -473,7 +411,7 @@ public class DueyProcessor {
|
|||||||
|
|
||||||
if (!MapleInventoryManipulator.checkSpace(c, dpItem.getItemId(), dpItem.getQuantity(), dpItem.getOwner())) {
|
if (!MapleInventoryManipulator.checkSpace(c, dpItem.getItemId(), dpItem.getQuantity(), dpItem.getOwner())) {
|
||||||
int itemid = dpItem.getItemId();
|
int itemid = dpItem.getItemId();
|
||||||
if(MapleItemInformationProvider.getInstance().isPickupRestricted(itemid) && c.getPlayer().getInventory(ItemConstants.getInventoryType(itemid)).findById(itemid) != null) {
|
if (MapleItemInformationProvider.getInstance().isPickupRestricted(itemid) && c.getPlayer().getInventory(ItemConstants.getInventoryType(itemid)).findById(itemid) != null) {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_RECEIVER_WITH_UNIQUE.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_RECEIVER_WITH_UNIQUE.getCode()));
|
||||||
} else {
|
} else {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_NO_FREE_SLOTS.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_NO_FREE_SLOTS.getCode()));
|
||||||
@@ -501,7 +439,7 @@ public class DueyProcessor {
|
|||||||
if (c.tryacquireClient()) {
|
if (c.tryacquireClient()) {
|
||||||
try {
|
try {
|
||||||
long timeNow = System.currentTimeMillis();
|
long timeNow = System.currentTimeMillis();
|
||||||
if(timeNow - c.getPlayer().getNpcCooldown() < YamlConfig.config.server.BLOCK_NPC_RACE_CONDT) {
|
if (timeNow - c.getPlayer().getNpcCooldown() < YamlConfig.config.server.BLOCK_NPC_RACE_CONDT) {
|
||||||
c.announce(MaplePacketCreator.enableActions());
|
c.announce(MaplePacketCreator.enableActions());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -526,34 +464,30 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void runDueyExpireSchedule() {
|
public static void runDueyExpireSchedule() {
|
||||||
try {
|
|
||||||
Calendar c = Calendar.getInstance();
|
Calendar c = Calendar.getInstance();
|
||||||
c.add(Calendar.DATE, -30);
|
c.add(Calendar.DATE, -30);
|
||||||
|
final Timestamp ts = new Timestamp(c.getTime().getTime());
|
||||||
|
|
||||||
Timestamp ts = new Timestamp(c.getTime().getTime());
|
try (Connection con = DatabaseConnection.getConnection()){
|
||||||
|
List<Integer> toRemove = new LinkedList<>();
|
||||||
Connection con = DatabaseConnection.getConnection();
|
try (PreparedStatement ps = con.prepareStatement("SELECT `PackageId` FROM dueypackages WHERE `TimeStamp` < ?")) {
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT `PackageId` FROM dueypackages WHERE `TimeStamp` < ?");
|
|
||||||
ps.setTimestamp(1, ts);
|
ps.setTimestamp(1, ts);
|
||||||
|
|
||||||
List<Integer> toRemove = new LinkedList<>();
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
toRemove.add(rs.getInt("PackageId"));
|
toRemove.add(rs.getInt("PackageId"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ps.close();
|
}
|
||||||
|
|
||||||
for (Integer pid : toRemove) {
|
for (Integer pid : toRemove) {
|
||||||
removePackageFromDB(pid);
|
removePackageFromDB(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
ps = con.prepareStatement("DELETE FROM dueypackages WHERE `TimeStamp` < ?");
|
try (PreparedStatement ps = con.prepareStatement("DELETE FROM dueypackages WHERE `TimeStamp` < ?")) {
|
||||||
ps.setTimestamp(1, ts);
|
ps.setTimestamp(1, ts);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
}
|
||||||
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,60 +21,41 @@
|
|||||||
*/
|
*/
|
||||||
package net.server.channel.handlers;
|
package net.server.channel.handlers;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import client.*;
|
||||||
import java.sql.PreparedStatement;
|
import client.inventory.*;
|
||||||
import java.sql.ResultSet;
|
import client.keybind.MapleKeyBinding;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
|
import constants.game.GameConstants;
|
||||||
|
import constants.game.ScriptableNPCConstants;
|
||||||
import net.AbstractMaplePacketHandler;
|
import net.AbstractMaplePacketHandler;
|
||||||
import net.server.PlayerBuffValueHolder;
|
import net.server.PlayerBuffValueHolder;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.channel.Channel;
|
import net.server.channel.Channel;
|
||||||
import net.server.channel.CharacterIdChannelPair;
|
import net.server.channel.CharacterIdChannelPair;
|
||||||
|
import net.server.coordinator.session.MapleSessionCoordinator;
|
||||||
|
import net.server.coordinator.world.MapleEventRecallCoordinator;
|
||||||
import net.server.guild.MapleAlliance;
|
import net.server.guild.MapleAlliance;
|
||||||
import net.server.guild.MapleGuild;
|
import net.server.guild.MapleGuild;
|
||||||
import net.server.world.MaplePartyCharacter;
|
import net.server.world.MaplePartyCharacter;
|
||||||
import net.server.world.PartyOperation;
|
import net.server.world.PartyOperation;
|
||||||
import net.server.world.World;
|
import net.server.world.World;
|
||||||
|
import org.apache.mina.core.session.IoSession;
|
||||||
|
import scripting.event.EventInstanceManager;
|
||||||
|
import server.life.MobSkill;
|
||||||
import tools.DatabaseConnection;
|
import tools.DatabaseConnection;
|
||||||
import tools.FilePrinter;
|
import tools.FilePrinter;
|
||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
import tools.Pair;
|
import tools.Pair;
|
||||||
import tools.data.input.SeekableLittleEndianAccessor;
|
import tools.data.input.SeekableLittleEndianAccessor;
|
||||||
import client.BuddyList;
|
|
||||||
import client.BuddylistEntry;
|
|
||||||
import client.CharacterNameAndId;
|
|
||||||
import client.MapleCharacter;
|
|
||||||
import client.MapleClient;
|
|
||||||
import client.MapleDisease;
|
|
||||||
import client.MapleFamily;
|
|
||||||
import client.MapleFamilyEntry;
|
|
||||||
import client.keybind.MapleKeyBinding;
|
|
||||||
import client.MapleMount;
|
|
||||||
import client.SkillFactory;
|
|
||||||
import client.inventory.Equip;
|
|
||||||
import client.inventory.Item;
|
|
||||||
import client.inventory.MapleInventory;
|
|
||||||
import client.inventory.MapleInventoryType;
|
|
||||||
import client.inventory.MaplePet;
|
|
||||||
import constants.game.GameConstants;
|
|
||||||
import constants.game.ScriptableNPCConstants;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import net.server.coordinator.world.MapleEventRecallCoordinator;
|
|
||||||
import net.server.coordinator.session.MapleSessionCoordinator;
|
|
||||||
import org.apache.mina.core.session.IoSession;
|
|
||||||
import server.life.MobSkill;
|
|
||||||
import scripting.event.EventInstanceManager;
|
|
||||||
import tools.packets.Wedding;
|
import tools.packets.Wedding;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||||
|
|
||||||
private static Set<Integer> attemptingLoginAccounts = new HashSet<>();
|
private static Set<Integer> attemptingLoginAccounts = new HashSet<>();
|
||||||
@@ -443,48 +424,22 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void showDueyNotification(MapleClient c, MapleCharacter player) {
|
private static void showDueyNotification(MapleClient c, MapleCharacter player) {
|
||||||
Connection con = null;
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = con.prepareStatement("SELECT Type FROM dueypackages WHERE ReceiverId = ? AND Checked = 1 ORDER BY Type DESC")) {
|
||||||
PreparedStatement pss = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
con = DatabaseConnection.getConnection();
|
|
||||||
ps = con.prepareStatement("SELECT Type FROM dueypackages WHERE ReceiverId = ? AND Checked = 1 ORDER BY Type DESC");
|
|
||||||
ps.setInt(1, player.getId());
|
ps.setInt(1, player.getId());
|
||||||
rs = ps.executeQuery();
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
try {
|
try (PreparedStatement ps2 = con.prepareStatement("UPDATE dueypackages SET Checked = 0 WHERE ReceiverId = ?")){
|
||||||
Connection con2 = DatabaseConnection.getConnection();
|
ps2.setInt(1, player.getId());
|
||||||
pss = con2.prepareStatement("UPDATE dueypackages SET Checked = 0 WHERE ReceiverId = ?");
|
ps2.executeUpdate();
|
||||||
pss.setInt(1, player.getId());
|
|
||||||
pss.executeUpdate();
|
|
||||||
pss.close();
|
|
||||||
con2.close();
|
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.sendDueyParcelNotification(rs.getInt("Type") == 1));
|
c.announce(MaplePacketCreator.sendDueyParcelNotification(rs.getInt("Type") == 1));
|
||||||
} catch (SQLException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (rs != null) {
|
|
||||||
rs.close();
|
|
||||||
}
|
|
||||||
if (pss != null) {
|
|
||||||
pss.close();
|
|
||||||
}
|
|
||||||
if (ps != null) {
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
if (con != null) {
|
|
||||||
con.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user