diff --git a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java index fd45235b5..ac6593529 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java @@ -1,10 +1,14 @@ package emu.grasscutter.command.commands; +import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.Mail; import emu.grasscutter.server.packet.send.PacketMailChangeNotify; +import java.time.Instant; +import java.util.ArrayList; import java.util.List; @Command(label = "sendmail", usage = "sendmail") @@ -12,8 +16,17 @@ 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)); + // This is literally so I can receive mail for some reason. + if(sender == null) { + // This is my uuid in my test server. This is just for testing. + // If someone pulled this please put your uuid to receive mail using /sendmail + // until I actually make a proper /sendmail command. + sender = Grasscutter.getGameServer().getPlayerByUid(7006); + } + sender.sendMail(new Mail(new Mail.MailContent("Test", "This is a test"), + new ArrayList(){{add(new Mail.MailItem(1062));}}, + Instant.now().getEpochSecond() + 4000)); + sender.dropMessage("Check your inbox"); } } diff --git a/src/main/java/emu/grasscutter/game/GenshinPlayer.java b/src/main/java/emu/grasscutter/game/GenshinPlayer.java index 3c68f04c2..3f8fe70ae 100644 --- a/src/main/java/emu/grasscutter/game/GenshinPlayer.java +++ b/src/main/java/emu/grasscutter/game/GenshinPlayer.java @@ -74,6 +74,8 @@ public class GenshinPlayer { private boolean showAvatar; private ArrayList shownAvatars; private Set rewardedLevels; + + private ArrayList mail; private int sceneId; private int regionId; @@ -112,6 +114,8 @@ public class GenshinPlayer { this.flyCloakList = new HashSet<>(); this.costumeList = new HashSet<>(); + this.mail = new ArrayList<>(); + this.setSceneId(3); this.setRegionId(1); this.sceneState = SceneLoadState.NONE; @@ -569,6 +573,16 @@ public class GenshinPlayer { this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString())); } + public List getMail() { return mail; } + + public void sendMail(Mail message) { + + this.mail.add(message); + message._id = this.mail.size() + 1; + this.save(); + this.sendPacket(new PacketMailChangeNotify(this, message)); + } + public void interactWith(int gadgetEntityId) { GenshinEntity entity = getScene().getEntityById(gadgetEntityId); diff --git a/src/main/java/emu/grasscutter/game/Mail.java b/src/main/java/emu/grasscutter/game/Mail.java new file mode 100644 index 000000000..2dc4ef688 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/Mail.java @@ -0,0 +1,99 @@ +package emu.grasscutter.game; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +public class Mail { + + public int _id; + public MailContent mailContent; + public List itemList; + public long sendTime; + public long expireTime; + public int importance; + public boolean isRead; + public boolean isAttachmentGot; + public int stateValue; + + public Mail() { + _id = 1; + mailContent = new MailContent("No title set...", "No content set..."); + itemList = new ArrayList<>(); + sendTime = 0; + expireTime = 0; + importance = 1; + isRead = true; + isAttachmentGot = true; + stateValue = 1; + } + + public Mail(MailContent mailContent, List itemList, long expireTime) { + this(mailContent, itemList, expireTime, 1); + } + + public Mail(MailContent mailContent, List itemList, long expireTime, int importance) { + this(mailContent, itemList, expireTime, importance, 1); + } + + public Mail(MailContent mailContent, List itemList, long expireTime, int importance, int state) { + this(0, mailContent, itemList, expireTime, importance, state); + } + + public Mail(int _id, MailContent mailContent, List itemList, long expireTime, int importance, int state) { + this._id = _id; + this.mailContent = mailContent; + this.itemList = itemList; + this.sendTime = (int) Instant.now().EPOCH.getEpochSecond(); + this.expireTime = expireTime; + this.importance = importance; + this.isRead = false; + this.isAttachmentGot = false; + this.stateValue = state; + } + + public static class MailContent { + public String title; + public String content; + public String sender; + + public MailContent() { + this.title = ""; + this.content = "loading..."; + this.sender = "loading"; + } + + public MailContent(String title, String content) { + this(title, content, "Server"); + } + + public MailContent(String title, String content, GenshinPlayer sender) { + this(title, content, sender.getNickname()); + } + + public MailContent(String title, String content, String sender) { + this.title = title; + this.content = content; + this.sender = sender; + } + } + + public static class MailItem { + public int itemId; + public int itemCount; + + public MailItem() { + this.itemId = 11101; + this.itemCount = 1; + } + + public MailItem(int itemId) { + this(itemId, 1); + } + + public MailItem(int itemId, int itemCount) { + this.itemId = itemId; + this.itemCount = itemCount; + } + } +} 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 82a567d67..00cd263b9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java @@ -3,15 +3,16 @@ package emu.grasscutter.server.packet.send; import com.google.gson.Gson; import emu.grasscutter.Grasscutter; import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.Mail; import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DateTimeDeleteOuterClass; +import emu.grasscutter.net.proto.*; 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 emu.grasscutter.net.proto.MaterialDeleteInfoOuterClass; + +import java.util.ArrayList; +import java.util.List; public class PacketGetAllMailRsp extends GenshinPacket { @@ -21,33 +22,43 @@ public class PacketGetAllMailRsp extends GenshinPacket { GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder(); + List mailDataList = new ArrayList(); + // Dummy data. - MailTextContent.Builder mailTextContent = MailTextContent.newBuilder(); - 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"); + for(Mail message : player.getMail()) { + MailTextContent.Builder mailTextContent = MailTextContent.newBuilder(); + mailTextContent.setTitle(message.mailContent.title); + mailTextContent.setContent(message.mailContent.content); + mailTextContent.setSender(message.mailContent.sender); - MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); - ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder(); + List mailItems = new ArrayList(); - itemParam.setItemId(1062); - itemParam.setCount(1); - mailItem.setItemParam(itemParam.build()); + for(Mail.MailItem item : message.itemList) { + MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); + ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder(); + itemParam.setItemId(item.itemId); + itemParam.setCount(item.itemCount); + mailItem.setItemParam(itemParam.build()); - MailData.Builder mailData = 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); + mailItems.add(mailItem.build()); + } - proto.addMailList(mailData.build()); - proto.addMailList(mailData.setMailId(101).build()); - proto.setIsTruncated(true); + MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder(); + mailData.setMailId(message._id); + mailData.setMailTextContent(mailTextContent.build()); + mailData.addAllItemList(mailItems); + mailData.setSendTime((int)message.sendTime); + mailData.setExpireTime((int)message.expireTime); + mailData.setImportance(message.importance); + mailData.setIsRead(message.isRead); + mailData.setIsAttachmentGot(message.isAttachmentGot); + mailData.setStateValue(message.stateValue); + + mailDataList.add(mailData.build()); + } + + proto.addAllMailList(mailDataList); + //proto.setIsTruncated(true); Grasscutter.getLogger().info(Grasscutter.getDispatchServer().getGsonFactory().toJson(proto.build())); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java index bedd191e1..a0bdc5c3e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java @@ -2,42 +2,48 @@ package emu.grasscutter.server.packet.send; import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.Mail; import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.*; +import java.util.ArrayList; import java.util.List; public class PacketMailChangeNotify extends GenshinPacket { - public PacketMailChangeNotify(GenshinPlayer player) { + public PacketMailChangeNotify(GenshinPlayer player, Mail message) { 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"); + mailTextContent.setTitle(message.mailContent.title); + mailTextContent.setContent(message.mailContent.content); + mailTextContent.setSender(message.mailContent.sender); - MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); - ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder(); + List mailItems = new ArrayList(); - itemParam.setItemId(1062); - itemParam.setCount(1); - mailItem.setItemParam(itemParam.build()); + for(Mail.MailItem item : message.itemList) { + MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); + ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder(); + itemParam.setItemId(item.itemId); + itemParam.setCount(item.itemCount); + mailItem.setItemParam(itemParam.build()); + + mailItems.add(mailItem.build()); + } MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder(); - mailData.setMailId(100); + mailData.setMailId(message._id); mailData.setMailTextContent(mailTextContent.build()); - mailData.addItemList(mailItem.build()); - mailData.setSendTime(1634100481); - mailData.setExpireTime(1664498747); - mailData.setImportance(1); + mailData.addAllItemList(mailItems); + mailData.setSendTime((int)message.sendTime); + mailData.setExpireTime((int)message.expireTime); + mailData.setImportance(message.importance); mailData.setIsRead(false); mailData.setIsAttachmentGot(false); - mailData.setStateValue(1); + mailData.setStateValue(message.stateValue); proto.addMailList(mailData.build());