From 6861a56a7bfad3e6f6af451534f12f053b613c5a Mon Sep 17 00:00:00 2001 From: Benjamin Elsdon Date: Mon, 25 Apr 2022 16:11:57 +0800 Subject: [PATCH] Added ChangeMailStarNotify (change importance level) --- .../recv/HandlerChangeMailStarNotify.java | 35 +++++++++++++++++++ .../packet/recv/HandlerGetAllMailReq.java | 1 - 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java new file mode 100644 index 000000000..468ce5b4e --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java @@ -0,0 +1,35 @@ +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.ChangeMailStarNotifyOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketMailChangeNotify; + +import java.util.ArrayList; +import java.util.List; + +@Opcodes(PacketOpcodes.ChangeMailStarNotify) +public class HandlerChangeMailStarNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ChangeMailStarNotifyOuterClass.ChangeMailStarNotify req = ChangeMailStarNotifyOuterClass.ChangeMailStarNotify.parseFrom(payload); + + List updatedMail = new ArrayList<>(); + + for (int mailId : req.getMailIdListList()) { + Mail message = session.getPlayer().getMailById(mailId); + int messageIndex = session.getPlayer().getMailIndex(message); + + message.importance = req.getIsStar() == true ? 1 : 0; + + session.getPlayer().replaceMailByIndex(messageIndex, message); + updatedMail.add(message); + } + + session.send(new PacketMailChangeNotify(session.getPlayer(), updatedMail)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllMailReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllMailReq.java index 7d92f2523..899ba6d95 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllMailReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllMailReq.java @@ -18,5 +18,4 @@ public class HandlerGetAllMailReq extends PacketHandler { GetAllMailReqOuterClass.GetAllMailReq req = GetAllMailReqOuterClass.GetAllMailReq.parseFrom(payload); session.send(new PacketGetAllMailRsp(session.getPlayer(), req.getIsGiftMail())); } - }