Commit cb03b654 authored by Benjamin Elsdon's avatar Benjamin Elsdon
Browse files

Added database support for mail

Send mail command now works from console (to use it from console change the uuid in the 'SendMailCommand' file
parent a326581e
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.Mail;
import emu.grasscutter.server.packet.send.PacketMailChangeNotify; import emu.grasscutter.server.packet.send.PacketMailChangeNotify;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Command(label = "sendmail", usage = "sendmail") @Command(label = "sendmail", usage = "sendmail")
...@@ -12,8 +16,17 @@ public class SendMailCommand implements CommandHandler { ...@@ -12,8 +16,17 @@ public class SendMailCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
// This is literally so I can test the notification // This is literally so I can receive mail for some reason.
sender.getSession().send(new PacketMailChangeNotify(sender)); 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<Mail.MailItem>(){{add(new Mail.MailItem(1062));}},
Instant.now().getEpochSecond() + 4000));
sender.dropMessage("Check your inbox"); sender.dropMessage("Check your inbox");
} }
} }
...@@ -34,28 +34,7 @@ import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; ...@@ -34,28 +34,7 @@ import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.net.proto.WorldPlayerLocationInfoOuterClass.WorldPlayerLocationInfo; import emu.grasscutter.net.proto.WorldPlayerLocationInfoOuterClass.WorldPlayerLocationInfo;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketAbilityInvocationsNotify; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.server.packet.send.PacketAvatarAddNotify;
import emu.grasscutter.server.packet.send.PacketAvatarDataNotify;
import emu.grasscutter.server.packet.send.PacketAvatarGainCostumeNotify;
import emu.grasscutter.server.packet.send.PacketAvatarGainFlycloakNotify;
import emu.grasscutter.server.packet.send.PacketClientAbilityInitFinishNotify;
import emu.grasscutter.server.packet.send.PacketCombatInvocationsNotify;
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
import emu.grasscutter.server.packet.send.PacketOpenStateUpdateNotify;
import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpResultNotify;
import emu.grasscutter.server.packet.send.PacketPlayerDataNotify;
import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
import emu.grasscutter.server.packet.send.PacketPlayerPropNotify;
import emu.grasscutter.server.packet.send.PacketPlayerStoreNotify;
import emu.grasscutter.server.packet.send.PacketPrivateChatNotify;
import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify;
import emu.grasscutter.server.packet.send.PacketSetNameCardRsp;
import emu.grasscutter.server.packet.send.PacketStoreWeightLimitNotify;
import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify;
import emu.grasscutter.server.packet.send.PacketWorldPlayerLocationNotify;
import emu.grasscutter.server.packet.send.PacketWorldPlayerRTTNotify;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
...@@ -94,6 +73,7 @@ public class GenshinPlayer { ...@@ -94,6 +73,7 @@ public class GenshinPlayer {
private MpSettingType mpSetting = MpSettingType.MpSettingEnterAfterApply; private MpSettingType mpSetting = MpSettingType.MpSettingEnterAfterApply;
private boolean showAvatar; private boolean showAvatar;
private ArrayList<AvatarProfileData> shownAvatars; private ArrayList<AvatarProfileData> shownAvatars;
private ArrayList<Mail> mail;
private int sceneId; private int sceneId;
private int regionId; private int regionId;
...@@ -130,7 +110,9 @@ public class GenshinPlayer { ...@@ -130,7 +110,9 @@ public class GenshinPlayer {
this.nameCardList = new HashSet<>(); this.nameCardList = new HashSet<>();
this.flyCloakList = new HashSet<>(); this.flyCloakList = new HashSet<>();
this.costumeList = new HashSet<>(); this.costumeList = new HashSet<>();
this.mail = new ArrayList<>();
this.setSceneId(3); this.setSceneId(3);
this.setRegionId(1); this.setRegionId(1);
this.sceneState = SceneLoadState.NONE; this.sceneState = SceneLoadState.NONE;
...@@ -582,6 +564,16 @@ public class GenshinPlayer { ...@@ -582,6 +564,16 @@ public class GenshinPlayer {
public void sendMessage(GenshinPlayer sender, Object message) { public void sendMessage(GenshinPlayer sender, Object message) {
this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString())); this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString()));
} }
public List<Mail> 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) { public void interactWith(int gadgetEntityId) {
GenshinEntity entity = getScene().getEntityById(gadgetEntityId); GenshinEntity entity = getScene().getEntityById(gadgetEntityId);
......
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<MailItem> 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<MailItem> itemList, long expireTime) {
this(mailContent, itemList, expireTime, 1);
}
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance) {
this(mailContent, itemList, expireTime, importance, 1);
}
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance, int state) {
this(0, mailContent, itemList, expireTime, importance, state);
}
public Mail(int _id, MailContent mailContent, List<MailItem> 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;
}
}
}
...@@ -3,15 +3,16 @@ package emu.grasscutter.server.packet.send; ...@@ -3,15 +3,16 @@ package emu.grasscutter.server.packet.send;
import com.google.gson.Gson; import com.google.gson.Gson;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.Mail;
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.*;
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.util.ArrayList;
import java.util.List;
public class PacketGetAllMailRsp extends GenshinPacket { public class PacketGetAllMailRsp extends GenshinPacket {
...@@ -21,33 +22,43 @@ public class PacketGetAllMailRsp extends GenshinPacket { ...@@ -21,33 +22,43 @@ public class PacketGetAllMailRsp extends GenshinPacket {
GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder(); GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder();
List<MailData> mailDataList = new ArrayList<MailData>();
// Dummy data. // Dummy data.
MailTextContent.Builder mailTextContent = MailTextContent.newBuilder(); for(Mail message : player.getMail()) {
mailTextContent.setTitle("Hello Traveller.."); MailTextContent.Builder mailTextContent = MailTextContent.newBuilder();
mailTextContent.setContent("You've called me emergency food for the last time. \n Get ready to die!"); mailTextContent.setTitle(message.mailContent.title);
mailTextContent.setSender("P·A·I·M·O·N"); 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<MailItemOuterClass.MailItem> mailItems = new ArrayList<MailItemOuterClass.MailItem>();
itemParam.setItemId(1062); for(Mail.MailItem item : message.itemList) {
itemParam.setCount(1); MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder();
mailItem.setItemParam(itemParam.build()); ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder();
itemParam.setItemId(item.itemId);
MailData.Builder mailData = MailData.newBuilder(); itemParam.setCount(item.itemCount);
mailData.setMailId(100); mailItem.setItemParam(itemParam.build());
mailData.setMailTextContent(mailTextContent.build());
mailData.addItemList(mailItem.build()); mailItems.add(mailItem.build());
mailData.setSendTime(1634100481); }
mailData.setExpireTime(1664498747);
mailData.setImportance(1); MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder();
mailData.setIsRead(false); mailData.setMailId(message._id);
mailData.setIsAttachmentGot(false); mailData.setMailTextContent(mailTextContent.build());
mailData.setStateValue(1); mailData.addAllItemList(mailItems);
mailData.setSendTime((int)message.sendTime);
proto.addMailList(mailData.build()); mailData.setExpireTime((int)message.expireTime);
proto.addMailList(mailData.setMailId(101).build()); mailData.setImportance(message.importance);
proto.setIsTruncated(true); 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())); Grasscutter.getLogger().info(Grasscutter.getDispatchServer().getGsonFactory().toJson(proto.build()));
......
...@@ -2,42 +2,48 @@ package emu.grasscutter.server.packet.send; ...@@ -2,42 +2,48 @@ package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.Mail;
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.*; import emu.grasscutter.net.proto.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class PacketMailChangeNotify extends GenshinPacket { public class PacketMailChangeNotify extends GenshinPacket {
public PacketMailChangeNotify(GenshinPlayer player) { public PacketMailChangeNotify(GenshinPlayer player, Mail message) {
super(PacketOpcodes.MailChangeNotify); super(PacketOpcodes.MailChangeNotify);
MailChangeNotifyOuterClass.MailChangeNotify.Builder proto = MailChangeNotifyOuterClass.MailChangeNotify.newBuilder(); MailChangeNotifyOuterClass.MailChangeNotify.Builder proto = MailChangeNotifyOuterClass.MailChangeNotify.newBuilder();
// Dummy data.
MailTextContentOuterClass.MailTextContent.Builder mailTextContent = MailTextContentOuterClass.MailTextContent.newBuilder(); MailTextContentOuterClass.MailTextContent.Builder mailTextContent = MailTextContentOuterClass.MailTextContent.newBuilder();
mailTextContent.setTitle("System Message"); mailTextContent.setTitle(message.mailContent.title);
mailTextContent.setContent("I'm going to kill you..."); mailTextContent.setContent(message.mailContent.content);
mailTextContent.setSender("YOU"); mailTextContent.setSender(message.mailContent.sender);
MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder(); List<MailItemOuterClass.MailItem> mailItems = new ArrayList<MailItemOuterClass.MailItem>();
ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder();
itemParam.setItemId(1062); for(Mail.MailItem item : message.itemList) {
itemParam.setCount(1); MailItemOuterClass.MailItem.Builder mailItem = MailItemOuterClass.MailItem.newBuilder();
mailItem.setItemParam(itemParam.build()); 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(); MailDataOuterClass.MailData.Builder mailData = MailDataOuterClass.MailData.newBuilder();
mailData.setMailId(100); mailData.setMailId(message._id);
mailData.setMailTextContent(mailTextContent.build()); mailData.setMailTextContent(mailTextContent.build());
mailData.addItemList(mailItem.build()); mailData.addAllItemList(mailItems);
mailData.setSendTime(1634100481); mailData.setSendTime((int)message.sendTime);
mailData.setExpireTime(1664498747); mailData.setExpireTime((int)message.expireTime);
mailData.setImportance(1); mailData.setImportance(message.importance);
mailData.setIsRead(false); mailData.setIsRead(false);
mailData.setIsAttachmentGot(false); mailData.setIsAttachmentGot(false);
mailData.setStateValue(1); mailData.setStateValue(message.stateValue);
proto.addMailList(mailData.build()); proto.addMailList(mailData.build());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment