From d0538f7aee755e8c4a37cde3b834842c7be53aa2 Mon Sep 17 00:00:00 2001 From: Benjamin Elsdon Date: Fri, 22 Apr 2022 19:02:05 +0800 Subject: [PATCH] Added GetMailItemReq/Rsp & PacketMailChangeNotify Mail still doesn't work for whatever reason. I also added a temporary SendMailCommand just to receive PacketMailChangeNotify. I feel like I'm about to lose my mind. --- Grasscutter-Protos | 2 +- .../command/commands/SendMailCommand.java | 19 ++++++++ .../packet/recv/HandlerGetMailItemReq.java | 22 +++++++++ .../packet/send/PacketGetAllMailRsp.java | 39 +++++++++++----- .../packet/send/PacketGetMailItemRsp.java | 31 +++++++++++++ .../packet/send/PacketMailChangeNotify.java | 46 +++++++++++++++++++ 6 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 src/main/java/emu/grasscutter/command/commands/SendMailCommand.java create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java diff --git a/Grasscutter-Protos b/Grasscutter-Protos index 0537e9cc4..ba0eab7d6 160000 --- a/Grasscutter-Protos +++ b/Grasscutter-Protos @@ -1 +1 @@ -Subproject commit 0537e9cc4c7856a7c6f88bbbaa908a80c4ee677e +Subproject commit ba0eab7d629b5adeb145bc430e14ffcb4bdf3d6a diff --git a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java new file mode 100644 index 000000000..fd45235b5 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java @@ -0,0 +1,19 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.server.packet.send.PacketMailChangeNotify; + +import java.util.List; + +@Command(label = "sendmail", usage = "sendmail") +public class SendMailCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + // This is literally so I can test the notification + sender.getSession().send(new PacketMailChangeNotify(sender)); + sender.dropMessage("Check your inbox"); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java new file mode 100644 index 000000000..2fed31974 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java @@ -0,0 +1,22 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetMailItemReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetAllMailRsp; +import emu.grasscutter.server.packet.send.PacketGetMailItemRsp; + +@Opcodes(PacketOpcodes.GetMailItemReq) +public class HandlerGetMailItemReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + Grasscutter.getLogger().info("Mail Item Req"); + GetMailItemReqOuterClass.GetMailItemReq req = GetMailItemReqOuterClass.GetMailItemReq.parseFrom(payload); + session.send(new PacketGetMailItemRsp(session.getPlayer(), req.getMailIdListList())); + } + +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java index d2362862c..82a567d67 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java @@ -1,39 +1,56 @@ package emu.grasscutter.server.packet.send; +import com.google.gson.Gson; +import emu.grasscutter.Grasscutter; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DateTimeDeleteOuterClass; import emu.grasscutter.net.proto.GetAllMailRspOuterClass.GetAllMailRsp; +import emu.grasscutter.net.proto.ItemParamOuterClass; import emu.grasscutter.net.proto.MailDataOuterClass.MailData; +import emu.grasscutter.net.proto.MailItemOuterClass; import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent; - -import java.time.Instant; +import emu.grasscutter.net.proto.MaterialDeleteInfoOuterClass; public class PacketGetAllMailRsp extends GenshinPacket { public PacketGetAllMailRsp(GenshinPlayer player, boolean isGiftMail) { super(PacketOpcodes.GetAllMailRsp); + Grasscutter.getLogger().info(String.valueOf(isGiftMail)); GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder(); + // Dummy data. MailTextContent.Builder mailTextContent = MailTextContent.newBuilder(); - mailTextContent.setTitle("System Message"); - mailTextContent.setContent("I'm going to kill you..."); - mailTextContent.setSender("YOU"); + mailTextContent.setTitle("Hello Traveller.."); + mailTextContent.setContent("You've called me emergency food for the last time. \n Get ready to die!"); + mailTextContent.setSender("P·A·I·M·O·N"); + + MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); + ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder(); + + itemParam.setItemId(1062); + itemParam.setCount(1); + mailItem.setItemParam(itemParam.build()); MailData.Builder mailData = MailData.newBuilder(); - mailData.setMailId(0); + mailData.setMailId(100); mailData.setMailTextContent(mailTextContent.build()); - mailData.setSendTime((int) Instant.now().getEpochSecond()); - mailData.setExpireTime(999999999); + mailData.addItemList(mailItem.build()); + mailData.setSendTime(1634100481); + mailData.setExpireTime(1664498747); mailData.setImportance(1); mailData.setIsRead(false); mailData.setIsAttachmentGot(false); - maildata. + mailData.setStateValue(1); proto.addMailList(mailData.build()); - proto.setIsTruncated(false); + proto.addMailList(mailData.setMailId(101).build()); + proto.setIsTruncated(true); - this.setData(proto); + Grasscutter.getLogger().info(Grasscutter.getDispatchServer().getGsonFactory().toJson(proto.build())); + + this.setData(proto.build()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java new file mode 100644 index 000000000..468e98885 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java @@ -0,0 +1,31 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.net.proto.MailItemOuterClass; + +import java.util.List; + +public class PacketGetMailItemRsp extends GenshinPacket { + + public PacketGetMailItemRsp(GenshinPlayer player, List mailList) { + super(PacketOpcodes.GetMailItemRsp); + + //I'm assuming that this is to receive the attachments on the message. + // TODO: This. + + //GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder(); + + //MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); + + //ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder(); + + //mailItem.setItemParam(itemParam); + + //proto.addAllMailIdList(mailList); + //proto.addItemList(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java new file mode 100644 index 000000000..bedd191e1 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java @@ -0,0 +1,46 @@ +package emu.grasscutter.server.packet.send; + + +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.*; + +import java.util.List; + +public class PacketMailChangeNotify extends GenshinPacket { + + public PacketMailChangeNotify(GenshinPlayer player) { + super(PacketOpcodes.MailChangeNotify); + + MailChangeNotifyOuterClass.MailChangeNotify.Builder proto = MailChangeNotifyOuterClass.MailChangeNotify.newBuilder(); + + // Dummy data. + MailTextContentOuterClass.MailTextContent.Builder mailTextContent = MailTextContentOuterClass.MailTextContent.newBuilder(); + mailTextContent.setTitle("System Message"); + mailTextContent.setContent("I'm going to kill you..."); + mailTextContent.setSender("YOU"); + + MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); + ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder(); + + itemParam.setItemId(1062); + itemParam.setCount(1); + mailItem.setItemParam(itemParam.build()); + + MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder(); + mailData.setMailId(100); + mailData.setMailTextContent(mailTextContent.build()); + mailData.addItemList(mailItem.build()); + mailData.setSendTime(1634100481); + mailData.setExpireTime(1664498747); + mailData.setImportance(1); + mailData.setIsRead(false); + mailData.setIsAttachmentGot(false); + mailData.setStateValue(1); + + proto.addMailList(mailData.build()); + + this.setData(proto.build()); + } +} \ No newline at end of file