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.
This commit is contained in:
Benjamin Elsdon 2022-04-22 19:02:05 +08:00
parent 346652cf5b
commit e24de95d29
6 changed files with 147 additions and 12 deletions

@ -1 +1 @@
Subproject commit 0537e9cc4c7856a7c6f88bbbaa908a80c4ee677e Subproject commit ba0eab7d629b5adeb145bc430e14ffcb4bdf3d6a

View File

@ -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<String> args) {
// This is literally so I can test the notification
sender.getSession().send(new PacketMailChangeNotify(sender));
sender.dropMessage("Check your inbox");
}
}

View File

@ -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()));
}
}

View File

@ -1,39 +1,56 @@
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import com.google.gson.Gson;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DateTimeDeleteOuterClass;
import emu.grasscutter.net.proto.GetAllMailRspOuterClass.GetAllMailRsp; 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.MailDataOuterClass.MailData;
import emu.grasscutter.net.proto.MailItemOuterClass;
import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent; import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent;
import emu.grasscutter.net.proto.MaterialDeleteInfoOuterClass;
import java.time.Instant;
public class PacketGetAllMailRsp extends GenshinPacket { public class PacketGetAllMailRsp extends GenshinPacket {
public PacketGetAllMailRsp(GenshinPlayer player, boolean isGiftMail) { public PacketGetAllMailRsp(GenshinPlayer player, boolean isGiftMail) {
super(PacketOpcodes.GetAllMailRsp); super(PacketOpcodes.GetAllMailRsp);
Grasscutter.getLogger().info(String.valueOf(isGiftMail));
GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder(); GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder();
// Dummy data.
MailTextContent.Builder mailTextContent = MailTextContent.newBuilder(); MailTextContent.Builder mailTextContent = MailTextContent.newBuilder();
mailTextContent.setTitle("System Message"); mailTextContent.setTitle("Hello Traveller..");
mailTextContent.setContent("I'm going to kill you..."); mailTextContent.setContent("You've called me emergency food for the last time. \n Get ready to die!");
mailTextContent.setSender("YOU"); 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.Builder mailData = MailData.newBuilder();
mailData.setMailId(0); mailData.setMailId(100);
mailData.setMailTextContent(mailTextContent.build()); mailData.setMailTextContent(mailTextContent.build());
mailData.setSendTime((int) Instant.now().getEpochSecond()); mailData.addItemList(mailItem.build());
mailData.setExpireTime(999999999); mailData.setSendTime(1634100481);
mailData.setExpireTime(1664498747);
mailData.setImportance(1); mailData.setImportance(1);
mailData.setIsRead(false); mailData.setIsRead(false);
mailData.setIsAttachmentGot(false); mailData.setIsAttachmentGot(false);
maildata. mailData.setStateValue(1);
proto.addMailList(mailData.build()); 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());
} }
} }

View File

@ -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<Integer> 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();
}
}

View File

@ -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());
}
}