Show notes using NoteDao

This commit is contained in:
P0nk
2022-12-26 16:48:00 +01:00
parent 605f2e212e
commit 1f4ce98998
2 changed files with 21 additions and 21 deletions

View File

@@ -41,6 +41,9 @@ import constants.id.MapId;
import constants.id.MobId; import constants.id.MobId;
import constants.inventory.ItemConstants; import constants.inventory.ItemConstants;
import constants.skills.*; import constants.skills.*;
import database.DaoException;
import database.NoteDao;
import model.Note;
import net.packet.Packet; import net.packet.Packet;
import net.server.PlayerBuffValueHolder; import net.server.PlayerBuffValueHolder;
import net.server.PlayerCoolDownValueHolder; import net.server.PlayerCoolDownValueHolder;
@@ -9641,18 +9644,15 @@ public class Character extends AbstractCharacterObject {
} }
public void showNote() { public void showNote() {
try (Connection con = DatabaseConnection.getConnection(); final List<Note> notes;
PreparedStatement ps = con.prepareStatement("SELECT * FROM notes WHERE `to` = ? AND `deleted` = 0", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { try {
ps.setString(1, this.getName()); notes = NoteDao.findAllByTo(name);
try (ResultSet rs = ps.executeQuery()) { } catch (DaoException e) {
rs.last(); log.error("Failed to find notes for chr name {}", name, e);
int count = rs.getRow(); return;
rs.first();
sendPacket(PacketCreator.showNotes(rs, count));
}
} catch (SQLException e) {
e.printStackTrace();
} }
sendPacket(PacketCreator.showNotes(notes));
} }
public void silentGiveBuffs(List<Pair<Long, PlayerBuffValueHolder>> buffs) { public void silentGiveBuffs(List<Pair<Long, PlayerBuffValueHolder>> buffs) {

View File

@@ -40,6 +40,7 @@ import constants.inventory.ItemConstants;
import constants.skills.Buccaneer; import constants.skills.Buccaneer;
import constants.skills.Corsair; import constants.skills.Corsair;
import constants.skills.ThunderBreaker; import constants.skills.ThunderBreaker;
import model.Note;
import net.encryption.InitializationVector; import net.encryption.InitializationVector;
import net.opcodes.SendOpcode; import net.opcodes.SendOpcode;
import net.packet.ByteBufOutPacket; import net.packet.ByteBufOutPacket;
@@ -5422,18 +5423,17 @@ public class PacketCreator {
return p; return p;
} }
public static Packet showNotes(ResultSet notes, int count) throws SQLException { public static Packet showNotes(List<Note> notes) {
final OutPacket p = OutPacket.create(SendOpcode.MEMO_RESULT); final OutPacket p = OutPacket.create(SendOpcode.MEMO_RESULT);
p.writeByte(3); p.writeByte(3);
p.writeByte(count); p.writeByte(notes.size());
for (int i = 0; i < count; i++) { notes.forEach(note -> {
p.writeInt(notes.getInt("id")); p.writeInt(note.id());
p.writeString(notes.getString("from") + " ");//Stupid nexon forgot space lol p.writeString(note.from() + " ");//Stupid nexon forgot space lol
p.writeString(notes.getString("message")); p.writeString(note.message());
p.writeLong(getTime(notes.getLong("timestamp"))); p.writeLong(getTime(note.timestamp()));
p.writeByte(notes.getByte("fame"));//FAME :D p.writeByte(note.fame());//FAME :D
notes.next(); });
}
return p; return p;
} }