From c0d4ca5e09f52ac10d8d9b120e236da92ee2fb0e Mon Sep 17 00:00:00 2001 From: Benjamin Elsdon Date: Mon, 25 Apr 2022 15:41:18 +0800 Subject: [PATCH] Mail read notify --- .../packet/recv/HandlerReadMailNotify.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java new file mode 100644 index 000000000..adf9e54ba --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java @@ -0,0 +1,36 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.Mail; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetAllMailReqOuterClass; +import emu.grasscutter.net.proto.ReadMailNotifyOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketMailChangeNotify; + +import java.util.ArrayList; +import java.util.List; + +@Opcodes(PacketOpcodes.ReadMailNotify) +public class HandlerReadMailNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ReadMailNotifyOuterClass.ReadMailNotify req = ReadMailNotifyOuterClass.ReadMailNotify.parseFrom(payload); + + List updatedMail = new ArrayList<>(); + + for (int mailId : req.getMailIdListList()) { + Mail message = session.getPlayer().getMailById(mailId); + int messageIndex = session.getPlayer().getMailIndex(message); + + message.isRead = true; + + session.getPlayer().replaceMailByIndex(messageIndex, message); + updatedMail.add(message); + } + + session.send(new PacketMailChangeNotify(session.getPlayer(), updatedMail)); + } +}