THE MAILBOX ACTUALLY WORKS CORRECTLY NOW

This commit is contained in:
Benjamin Elsdon 2022-04-24 19:06:52 +08:00
parent 29a3e64db0
commit a548fe6c52
2 changed files with 63 additions and 40 deletions

View File

@ -47,7 +47,7 @@ public class Mail {
this._id = _id;
this.mailContent = mailContent;
this.itemList = itemList;
this.sendTime = (int) Instant.now().EPOCH.getEpochSecond();
this.sendTime = (int) Instant.now().getEpochSecond();
this.expireTime = expireTime;
this.importance = importance;
this.isRead = false;

View File

@ -11,7 +11,9 @@ import emu.grasscutter.net.proto.GetAllMailRspOuterClass.GetAllMailRsp;
import emu.grasscutter.net.proto.MailDataOuterClass.MailData;
import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
public class PacketGetAllMailRsp extends GenshinPacket {
@ -20,18 +22,30 @@ public class PacketGetAllMailRsp extends GenshinPacket {
super(PacketOpcodes.GetAllMailRsp);
Grasscutter.getLogger().info(String.valueOf(isGiftMail));
GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder();
if (isGiftMail) {
// TODO: Gift Mail
// Make sure to send the stupid empty packet
Base64.Decoder decoder = Base64.getDecoder();
byte[] rsp = decoder.decode("IAE=");
try {
GetAllMailRsp var = GetAllMailRsp.parseFrom(rsp);
this.setData(var.toBuilder().build());
} catch (Exception e) {
}
} else {
if (player.getMail().size() != 0) { // Make sure the player has mail
GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder();
List<MailData> mailDataList = new ArrayList<MailData>();
// Dummy data.
for (Mail message : player.getMail()) {
if(message.stateValue == 1) { //Make sure it isn't a gift
MailTextContent.Builder mailTextContent = MailTextContent.newBuilder();
mailTextContent.setTitle(message.mailContent.title);
mailTextContent.setContent(message.mailContent.content);
mailTextContent.setSender(message.mailContent.sender);
List<MailItemOuterClass.MailItem> mailItems = new ArrayList<MailItemOuterClass.MailItem>();
List<MailItemOuterClass.MailItem> mailItems = new ArrayList<>();
for (Mail.MailItem item : message.itemList) {
MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder();
@ -52,16 +66,25 @@ public class PacketGetAllMailRsp extends GenshinPacket {
mailData.setImportance(message.importance);
mailData.setIsRead(message.isRead);
mailData.setIsAttachmentGot(message.isAttachmentGot);
mailData.setStateValue(message.stateValue);
mailData.setStateValue(1);
mailDataList.add(mailData.build());
}
}
proto.addAllMailList(mailDataList);
//proto.setIsTruncated(true);
Grasscutter.getLogger().info(Grasscutter.getDispatchServer().getGsonFactory().toJson(proto.build()));
proto.setIsTruncated(true);
this.setData(proto.build());
} else {
// Make sure to send the stupid empty packet
Base64.Decoder decoder = Base64.getDecoder();
byte[] rsp = decoder.decode("IAE=");
try {
GetAllMailRsp var = GetAllMailRsp.parseFrom(rsp);
this.setData(var.toBuilder().build());
} catch (Exception e) {}
}
}
}
}