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,12 +43,17 @@ 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 {
|
||||||
|
|
||||||
public enum Actions {
|
public enum Actions {
|
||||||
TOSERVER_RECV_ITEM(0x00),
|
TOSERVER_RECV_ITEM(0x00),
|
||||||
TOSERVER_SEND_ITEM(0x02),
|
TOSERVER_SEND_ITEM(0x02),
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,90 +87,56 @@ public class DueyProcessor {
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
c.announce(MaplePacketCreator.sendDueyParcelReceived(rs.getString("SenderName"), rs.getInt("Type") == 1));
|
||||||
pss.close();
|
}
|
||||||
con2.close();
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deletePackageFromInventoryDB(Connection con, int packageId) throws SQLException {
|
private static void deletePackageFromInventoryDB(Connection con, int packageId) throws SQLException {
|
||||||
ItemFactory.DUEY.saveItems(new LinkedList<Pair<Item, MapleInventoryType>>(), packageId, con);
|
ItemFactory.DUEY.saveItems(new LinkedList<Pair<Item, MapleInventoryType>>(), packageId, con);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
@@ -184,123 +145,102 @@ public class DueyProcessor {
|
|||||||
private static DueyPackage getPackageFromDB(ResultSet rs) {
|
private static DueyPackage getPackageFromDB(ResultSet rs) {
|
||||||
try {
|
try {
|
||||||
int packageId = rs.getInt("PackageId");
|
int packageId = rs.getInt("PackageId");
|
||||||
|
|
||||||
List<Pair<Item, MapleInventoryType>> dueyItems = ItemFactory.DUEY.loadItems(packageId, false);
|
List<Pair<Item, MapleInventoryType>> dueyItems = ItemFactory.DUEY.loadItems(packageId, false);
|
||||||
DueyPackage dueypack;
|
DueyPackage dueypack;
|
||||||
|
|
||||||
if (!dueyItems.isEmpty()) { // in a duey package there's only one item
|
if (!dueyItems.isEmpty()) { // in a duey package there's only one item
|
||||||
dueypack = new DueyPackage(packageId, dueyItems.get(0).getLeft());
|
dueypack = new DueyPackage(packageId, dueyItems.get(0).getLeft());
|
||||||
} else {
|
} else {
|
||||||
dueypack = new DueyPackage(packageId);
|
dueypack = new DueyPackage(packageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
dueypack.setSender(rs.getString("SenderName"));
|
dueypack.setSender(rs.getString("SenderName"));
|
||||||
dueypack.setMesos(rs.getInt("Mesos"));
|
dueypack.setMesos(rs.getInt("Mesos"));
|
||||||
dueypack.setSentTime(rs.getTimestamp("TimeStamp"), rs.getBoolean("Type"));
|
dueypack.setSentTime(rs.getTimestamp("TimeStamp"), rs.getBoolean("Type"));
|
||||||
dueypack.setMessage(rs.getString("Message"));
|
dueypack.setMessage(rs.getString("Message"));
|
||||||
|
|
||||||
return dueypack;
|
return dueypack;
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
sqle.printStackTrace();
|
sqle.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
return packages;
|
return packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int createPackage(int mesos, String message, String sender, int toCid, boolean quick) {
|
|
||||||
try {
|
|
||||||
Connection con = null;
|
|
||||||
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.setString(2, sender);
|
|
||||||
ps.setInt(3, mesos);
|
|
||||||
ps.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
|
|
||||||
ps.setString(5, message);
|
|
||||||
ps.setInt(6, quick ? 1 : 0);
|
|
||||||
|
|
||||||
int updateRows = ps.executeUpdate();
|
private static int createPackage(int mesos, String message, String sender, int toCid, boolean quick) {
|
||||||
if (updateRows < 1) {
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Error trying to create package [mesos: " + mesos + ", " + sender + ", quick: " + quick + ", to CharacterId: " + toCid + "]");
|
PreparedStatement ps = con.prepareStatement("INSERT INTO `dueypackages` (ReceiverId, SenderName, Mesos, TimeStamp, Message, Type, Checked) VALUES (?, ?, ?, ?, ?, ?, 1)", Statement.RETURN_GENERATED_KEYS)) {
|
||||||
return -1;
|
ps.setInt(1, toCid);
|
||||||
}
|
ps.setString(2, sender);
|
||||||
|
ps.setInt(3, mesos);
|
||||||
int packageId;
|
ps.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
|
||||||
rs = ps.getGeneratedKeys();
|
ps.setString(5, message);
|
||||||
|
ps.setInt(6, quick ? 1 : 0);
|
||||||
|
|
||||||
|
int updateRows = ps.executeUpdate();
|
||||||
|
if (updateRows < 1) {
|
||||||
|
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Error trying to create package [mesos: " + mesos + ", " + sender + ", quick: " + quick + ", to CharacterId: " + toCid + "]");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int packageId;
|
||||||
|
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;
|
|
||||||
} finally {
|
|
||||||
if (rs != null && !rs.isClosed()) {
|
|
||||||
rs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ps != null && !ps.isClosed()) {
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (con != null && !con.isClosed()) {
|
|
||||||
con.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return packageId;
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
sqle.printStackTrace();
|
sqle.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()));
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
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) {
|
||||||
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
||||||
|
|
||||||
MapleInventoryType invType = MapleInventoryType.getByType(invTypeId);
|
MapleInventoryType invType = MapleInventoryType.getByType(invTypeId);
|
||||||
MapleInventory inv = c.getPlayer().getInventory(invType);
|
MapleInventory inv = c.getPlayer().getInventory(invType);
|
||||||
|
|
||||||
@@ -326,18 +266,18 @@ public class DueyProcessor {
|
|||||||
} finally {
|
} finally {
|
||||||
inv.unlockInventory();
|
inv.unlockInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
MapleKarmaManipulator.toggleKarmaFlagToUntradeable(item);
|
MapleKarmaManipulator.toggleKarmaFlagToUntradeable(item);
|
||||||
item.setQuantity(amount);
|
item.setQuantity(amount);
|
||||||
|
|
||||||
if (!insertPackageItem(packageId, item)) {
|
if (!insertPackageItem(packageId, item)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dueySendItem(MapleClient c, byte invTypeId, short itemPos, short amount, int sendMesos, String sendMessage, String recipient, boolean quick) {
|
public static void dueySendItem(MapleClient c, byte invTypeId, short itemPos, short amount, int sendMesos, String sendMessage, String recipient, boolean quick) {
|
||||||
if (c.tryacquireClient()) {
|
if (c.tryacquireClient()) {
|
||||||
try {
|
try {
|
||||||
@@ -350,7 +290,7 @@ public class DueyProcessor {
|
|||||||
c.disconnect(true, false);
|
c.disconnect(true, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long finalcost = (long) sendMesos + fee;
|
long finalcost = (long) sendMesos + fee;
|
||||||
if (finalcost < 0 || finalcost > Integer.MAX_VALUE || (amount < 1 && sendMesos == 0)) {
|
if (finalcost < 0 || finalcost > Integer.MAX_VALUE || (amount < 1 && sendMesos == 0)) {
|
||||||
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
|
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
|
||||||
@@ -358,7 +298,7 @@ public class DueyProcessor {
|
|||||||
c.disconnect(true, false);
|
c.disconnect(true, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<Integer, Integer> accIdCid;
|
Pair<Integer, Integer> accIdCid;
|
||||||
if (c.getPlayer().getMeso() >= finalcost) {
|
if (c.getPlayer().getMeso() >= finalcost) {
|
||||||
accIdCid = getAccountCharacterIdFromCNAME(recipient);
|
accIdCid = getAccountCharacterIdFromCNAME(recipient);
|
||||||
@@ -376,24 +316,24 @@ public class DueyProcessor {
|
|||||||
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NOT_ENOUGH_MESOS.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NOT_ENOUGH_MESOS.getCode()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int recipientCid = accIdCid.getRight();
|
int recipientCid = accIdCid.getRight();
|
||||||
if (recipientCid == -1) {
|
if (recipientCid == -1) {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quick) {
|
if (quick) {
|
||||||
MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5330000, (short) 1, false, false);
|
MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5330000, (short) 1, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int packageId = createPackage(sendMesos, sendMessage, c.getPlayer().getName(), recipientCid, quick);
|
int packageId = createPackage(sendMesos, sendMessage, c.getPlayer().getName(), recipientCid, quick);
|
||||||
if (packageId == -1) {
|
if (packageId == -1) {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_ENABLE_ACTIONS.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_ENABLE_ACTIONS.getCode()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c.getPlayer().gainMeso((int) -finalcost, false);
|
c.getPlayer().gainMeso((int) -finalcost, false);
|
||||||
|
|
||||||
int res = addPackageItemFromInventory(packageId, c, invTypeId, itemPos, amount);
|
int res = addPackageItemFromInventory(packageId, c, invTypeId, itemPos, amount);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
|
||||||
@@ -402,19 +342,19 @@ public class DueyProcessor {
|
|||||||
} else {
|
} else {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_INCORRECT_REQUEST.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_INCORRECT_REQUEST.getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
MapleClient rClient = null;
|
MapleClient rClient = null;
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rClient != null && rClient.isLoggedIn() && !rClient.getPlayer().isAwayFromWorld()) {
|
if (rClient != null && rClient.isLoggedIn() && !rClient.getPlayer().isAwayFromWorld()) {
|
||||||
showDueyNotification(rClient, rClient.getPlayer());
|
showDueyNotification(rClient, rClient.getPlayer());
|
||||||
}
|
}
|
||||||
@@ -423,7 +363,7 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dueyRemovePackage(MapleClient c, int packageid, boolean playerRemove) {
|
public static void dueyRemovePackage(MapleClient c, int packageid, boolean playerRemove) {
|
||||||
if (c.tryacquireClient()) {
|
if (c.tryacquireClient()) {
|
||||||
try {
|
try {
|
||||||
@@ -434,31 +374,29 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dueyClaimPackage(MapleClient c, int packageId) {
|
public static void dueyClaimPackage(MapleClient c, int packageId) {
|
||||||
if (c.tryacquireClient()) {
|
if (c.tryacquireClient()) {
|
||||||
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()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
dp = getPackageFromDB(rs);
|
dp = getPackageFromDB(rs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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()));
|
||||||
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to receive package from duey with id " + packageId);
|
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to receive package from duey with id " + packageId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dp.isDeliveringTime()) {
|
if (dp.isDeliveringTime()) {
|
||||||
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
|
||||||
return;
|
return;
|
||||||
@@ -470,10 +408,10 @@ public class DueyProcessor {
|
|||||||
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
|
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()));
|
||||||
@@ -484,9 +422,9 @@ public class DueyProcessor {
|
|||||||
MapleInventoryManipulator.addFromDrop(c, dpItem, false);
|
MapleInventoryManipulator.addFromDrop(c, dpItem, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.getPlayer().gainMeso(dp.getMesos(), false);
|
c.getPlayer().gainMeso(dp.getMesos(), false);
|
||||||
|
|
||||||
dueyRemovePackage(c, packageId, false);
|
dueyRemovePackage(c, packageId, false);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -496,17 +434,17 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dueySendTalk(MapleClient c, boolean quickDelivery) {
|
public static void dueySendTalk(MapleClient c, boolean quickDelivery) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
c.getPlayer().setNpcCooldown(timeNow);
|
c.getPlayer().setNpcCooldown(timeNow);
|
||||||
|
|
||||||
if (quickDelivery) {
|
if (quickDelivery) {
|
||||||
c.announce(MaplePacketCreator.sendDuey(0x1A, null));
|
c.announce(MaplePacketCreator.sendDuey(0x1A, null));
|
||||||
} else {
|
} else {
|
||||||
@@ -517,43 +455,39 @@ public class DueyProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dueyCreatePackage(Item item, int mesos, String sender, int recipientCid) {
|
public static void dueyCreatePackage(Item item, int mesos, String sender, int recipientCid) {
|
||||||
int packageId = createPackage(mesos, null, sender, recipientCid, false);
|
int packageId = createPackage(mesos, null, sender, recipientCid, false);
|
||||||
if (packageId != -1) {
|
if (packageId != -1) {
|
||||||
insertPackageItem(packageId, item);
|
insertPackageItem(packageId, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()){
|
||||||
|
|
||||||
Connection con = DatabaseConnection.getConnection();
|
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT `PackageId` FROM dueypackages WHERE `TimeStamp` < ?");
|
|
||||||
ps.setTimestamp(1, ts);
|
|
||||||
|
|
||||||
List<Integer> toRemove = new LinkedList<>();
|
List<Integer> toRemove = new LinkedList<>();
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (PreparedStatement ps = con.prepareStatement("SELECT `PackageId` FROM dueypackages WHERE `TimeStamp` < ?")) {
|
||||||
while (rs.next()) {
|
ps.setTimestamp(1, ts);
|
||||||
toRemove.add(rs.getInt("PackageId"));
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
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();
|
|
||||||
if (rs.next()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
try {
|
if (rs.next()) {
|
||||||
Connection con2 = DatabaseConnection.getConnection();
|
try (PreparedStatement ps2 = con.prepareStatement("UPDATE dueypackages SET Checked = 0 WHERE ReceiverId = ?")){
|
||||||
pss = con2.prepareStatement("UPDATE dueypackages SET Checked = 0 WHERE ReceiverId = ?");
|
ps2.setInt(1, player.getId());
|
||||||
pss.setInt(1, player.getId());
|
ps2.executeUpdate();
|
||||||
pss.executeUpdate();
|
|
||||||
pss.close();
|
c.announce(MaplePacketCreator.sendDueyParcelNotification(rs.getInt("Type") == 1));
|
||||||
con2.close();
|
}
|
||||||
|
|
||||||
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