From 1f4ce98998a02dd9ead411b7a99d7c676b73e118 Mon Sep 17 00:00:00 2001 From: P0nk Date: Mon, 26 Dec 2022 16:48:00 +0100 Subject: [PATCH] Show notes using NoteDao --- src/main/java/client/Character.java | 22 +++++++++++----------- src/main/java/tools/PacketCreator.java | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/client/Character.java b/src/main/java/client/Character.java index 660b02db29..3bae79a54d 100644 --- a/src/main/java/client/Character.java +++ b/src/main/java/client/Character.java @@ -41,6 +41,9 @@ import constants.id.MapId; import constants.id.MobId; import constants.inventory.ItemConstants; import constants.skills.*; +import database.DaoException; +import database.NoteDao; +import model.Note; import net.packet.Packet; import net.server.PlayerBuffValueHolder; import net.server.PlayerCoolDownValueHolder; @@ -9641,18 +9644,15 @@ public class Character extends AbstractCharacterObject { } public void showNote() { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT * FROM notes WHERE `to` = ? AND `deleted` = 0", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { - ps.setString(1, this.getName()); - try (ResultSet rs = ps.executeQuery()) { - rs.last(); - int count = rs.getRow(); - rs.first(); - sendPacket(PacketCreator.showNotes(rs, count)); - } - } catch (SQLException e) { - e.printStackTrace(); + final List notes; + try { + notes = NoteDao.findAllByTo(name); + } catch (DaoException e) { + log.error("Failed to find notes for chr name {}", name, e); + return; } + + sendPacket(PacketCreator.showNotes(notes)); } public void silentGiveBuffs(List> buffs) { diff --git a/src/main/java/tools/PacketCreator.java b/src/main/java/tools/PacketCreator.java index c5e352bfe8..2fb79103db 100644 --- a/src/main/java/tools/PacketCreator.java +++ b/src/main/java/tools/PacketCreator.java @@ -40,6 +40,7 @@ import constants.inventory.ItemConstants; import constants.skills.Buccaneer; import constants.skills.Corsair; import constants.skills.ThunderBreaker; +import model.Note; import net.encryption.InitializationVector; import net.opcodes.SendOpcode; import net.packet.ByteBufOutPacket; @@ -5422,18 +5423,17 @@ public class PacketCreator { return p; } - public static Packet showNotes(ResultSet notes, int count) throws SQLException { + public static Packet showNotes(List notes) { final OutPacket p = OutPacket.create(SendOpcode.MEMO_RESULT); p.writeByte(3); - p.writeByte(count); - for (int i = 0; i < count; i++) { - p.writeInt(notes.getInt("id")); - p.writeString(notes.getString("from") + " ");//Stupid nexon forgot space lol - p.writeString(notes.getString("message")); - p.writeLong(getTime(notes.getLong("timestamp"))); - p.writeByte(notes.getByte("fame"));//FAME :D - notes.next(); - } + p.writeByte(notes.size()); + notes.forEach(note -> { + p.writeInt(note.id()); + p.writeString(note.from() + " ");//Stupid nexon forgot space lol + p.writeString(note.message()); + p.writeLong(getTime(note.timestamp())); + p.writeByte(note.fame());//FAME :D + }); return p; }