Merge branch 'unstable' into unstable-quests

This commit is contained in:
KingRainbow44 2023-04-02 21:31:39 -04:00
commit b2c9e8de3e
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
8 changed files with 2064 additions and 250 deletions

View File

@ -13,7 +13,7 @@
* Chiến đấu, giao tranh
* Danh sách bạn bè
* Dịch chuyển
* Hệ thống gacha
* Hệ thống cầu nguyện (gacha)
* *Một phần* của tính năng chơi chung (co-op)
* Gọi ra quái vật từ bảng điều khiển (console)
* Vật phẩm/Nhân vật (nhận vật phẩm/nhân vật, nâng cấp vật phẩm/nhân vật)
@ -26,9 +26,9 @@
* [Java SE - 17](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) hoặc cao hơn
**Ghi chú:** Nếu bạn chỉ cần **sử dụng**, thì cài **jre** là đủ.
**Ghi chú:** Nếu bạn chỉ muốn **sử dụng**, vậy thì cài đặt **jre** là đủ.
* [MongoDB](https://www.mongodb.com/try/download/community) (khuyến khích phiên bản từ 4.0 trở lên)
* [MongoDB](https://www.mongodb.com/try/download/community) (khuyến khích sử dụng phiên bản từ 4.0 trở lên)
* Proxy Daemon: [mitmproxy](https://mitmproxy.org/) (nên sử dụng mitmdump), [Fiddler Classic](https://telerik-fiddler.s3.amazonaws.com/fiddler/FiddlerSetup.exe), v.v.
@ -62,11 +62,11 @@
- [Hosts file](https://github.com/Grasscutters/Grasscutter/wiki/Resources#hosts-file)
2. Cài đặt network proxy thành `127.0.0.1:8080` hoặc cổng proxy bạn đã chỉ định.
2. Cài đặt network proxy thành `127.0.0.1:8080` hoặc cổng proxy bạn đã chỉ định.
- Với mitmproxy: Sau khi thiết lập proxy và cài đặt chứng chỉ, hãy kiểm tra http://mitm.it/ nếu lưu lượng truy cập đi qua mitmproxy.
- Với mitmproxy: Sau khi thiết lập proxy và cài đặt chứng chỉ, hãy kiểm tra http://mitm.it/ để xem liệu lưu lượng có đang thông qua mitmproxy hay không.
**You can also use `start.cmd` to start servers and proxy daemons automatically, but you have to set up `JAVA_HOME` environment and configure the `start_config.cmd` file.**
**Bạn cũng có thể sử dụng `start.cmd` để tự động khởi động máy chủ (servers) và proxy daemons, nhưng trước đó bạn phải thiết lập biến môi trường `JAVA_HOME` và cấu hình tệp `start_config.cmd`.**
### Tự tạo server (Building)
@ -101,6 +101,6 @@ Bạn có thể tìm thấy tệp jar đã được biên dịch tại thư mụ
# Khắc phục nhanh các sụ cố
- Nếu quá trình biên dịch (compile) không thành công, vui lòng kiểm tra cài đặt JDK của bạn (Đảm bảo rằng JDK phải từ phiên bản 17 trở lên và PATH của JDK đã được cài đặt).
- Không thể kết nối, không thể đăng nhập, 4206, v.v... - Cài đặt proxy (proxy daemon) của bạn thường là *vấn đề*. Nếu bạn đang sử dụng Fiddler, hãy đổi port (cổng) mặc định khác 8888.
- Thứ tự cài đặt: MongoDB > Grasscutter > Proxy Daemon (mitmdump, fiddler, v.v.) > Game
- Nếu quá trình biên dịch (compile) không thành công, hãy kiểm tra cài đặt JDK của bạn (Đảm bảo rằng JDK phải từ phiên bản 17 trở lên và PATH của JDK đã được cài đặt).
- Không thể kết nối, không thể đăng nhập, 4206, v.v. - *Vấn đề* thường là do cài đặt proxy (proxy daemon) của bạn. Nếu bạn đang sử dụng Fiddler, hãy đổi cổng (port) mặc định sang bất cứ cổng nào khác 8888.
- Thứ tự khởi động: MongoDB > Grasscutter > Proxy Daemon (mitmdump, fiddler, v.v.) > Game

View File

@ -0,0 +1,547 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: GetAllMailNotify.proto
package emu.grasscutter.net.proto;
public final class GetAllMailNotifyOuterClass {
private GetAllMailNotifyOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface GetAllMailNotifyOrBuilder extends
// @@protoc_insertion_point(interface_extends:GetAllMailNotify)
com.google.protobuf.MessageOrBuilder {
/**
* <code>bool is_collected = 6;</code>
* @return The isCollected.
*/
boolean getIsCollected();
}
/**
* <pre>
* Name: PFHIOOMPNBH
* CmdId: 1442
* </pre>
*
* Protobuf type {@code GetAllMailNotify}
*/
public static final class GetAllMailNotify extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:GetAllMailNotify)
GetAllMailNotifyOrBuilder {
private static final long serialVersionUID = 0L;
// Use GetAllMailNotify.newBuilder() to construct.
private GetAllMailNotify(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private GetAllMailNotify() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new GetAllMailNotify();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private GetAllMailNotify(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 48: {
isCollected_ = input.readBool();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.internal_static_GetAllMailNotify_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.internal_static_GetAllMailNotify_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify.class, emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify.Builder.class);
}
public static final int IS_COLLECTED_FIELD_NUMBER = 6;
private boolean isCollected_;
/**
* <code>bool is_collected = 6;</code>
* @return The isCollected.
*/
@java.lang.Override
public boolean getIsCollected() {
return isCollected_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (isCollected_ != false) {
output.writeBool(6, isCollected_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (isCollected_ != false) {
size += com.google.protobuf.CodedOutputStream
.computeBoolSize(6, isCollected_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify other = (emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify) obj;
if (getIsCollected()
!= other.getIsCollected()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + IS_COLLECTED_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(
getIsCollected());
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* Name: PFHIOOMPNBH
* CmdId: 1442
* </pre>
*
* Protobuf type {@code GetAllMailNotify}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:GetAllMailNotify)
emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotifyOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.internal_static_GetAllMailNotify_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.internal_static_GetAllMailNotify_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify.class, emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify.Builder.class);
}
// Construct using emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
isCollected_ = false;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.internal_static_GetAllMailNotify_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify getDefaultInstanceForType() {
return emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify build() {
emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify buildPartial() {
emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify result = new emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify(this);
result.isCollected_ = isCollected_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify) {
return mergeFrom((emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify other) {
if (other == emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify.getDefaultInstance()) return this;
if (other.getIsCollected() != false) {
setIsCollected(other.getIsCollected());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private boolean isCollected_ ;
/**
* <code>bool is_collected = 6;</code>
* @return The isCollected.
*/
@java.lang.Override
public boolean getIsCollected() {
return isCollected_;
}
/**
* <code>bool is_collected = 6;</code>
* @param value The isCollected to set.
* @return This builder for chaining.
*/
public Builder setIsCollected(boolean value) {
isCollected_ = value;
onChanged();
return this;
}
/**
* <code>bool is_collected = 6;</code>
* @return This builder for chaining.
*/
public Builder clearIsCollected() {
isCollected_ = false;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:GetAllMailNotify)
}
// @@protoc_insertion_point(class_scope:GetAllMailNotify)
private static final emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify();
}
public static emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<GetAllMailNotify>
PARSER = new com.google.protobuf.AbstractParser<GetAllMailNotify>() {
@java.lang.Override
public GetAllMailNotify parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new GetAllMailNotify(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<GetAllMailNotify> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<GetAllMailNotify> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_GetAllMailNotify_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_GetAllMailNotify_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\026GetAllMailNotify.proto\"(\n\020GetAllMailNo" +
"tify\022\024\n\014is_collected\030\006 \001(\010B\033\n\031emu.grassc" +
"utter.net.protob\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_GetAllMailNotify_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_GetAllMailNotify_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_GetAllMailNotify_descriptor,
new java.lang.String[] { "IsCollected", });
}
// @@protoc_insertion_point(outer_class_scope)
}

View File

@ -1,133 +1,163 @@
package emu.grasscutter.game.mail;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Indexed;
import dev.morphia.annotations.Transient;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.Player;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import org.bson.types.ObjectId;
@Entity(value = "mail", useDiscriminator = false)
public class Mail {
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;
@Id private ObjectId id;
@Indexed private int ownerUid;
@Transient private boolean shouldDelete;
public Mail() {
this(
new MailContent(),
new ArrayList<MailItem>(),
(int) Instant.now().getEpochSecond()
+ 604800); // TODO: add expire time to send mail command
}
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime) {
this(mailContent, itemList, expireTime, 0);
}
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.mailContent = mailContent;
this.itemList = itemList;
this.sendTime = (int) Instant.now().getEpochSecond();
this.expireTime = expireTime;
this.importance = importance; // Starred mail, 0 = No star, 1 = Star.
this.isRead = false;
this.isAttachmentGot = false;
this.stateValue = state; // Different mailboxes, 1 = Default, 3 = Gift-box.
}
public ObjectId getId() {
return id;
}
public int getOwnerUid() {
return ownerUid;
}
public void setOwnerUid(int ownerUid) {
this.ownerUid = ownerUid;
}
public void save() {
if (this.expireTime * 1000 < System.currentTimeMillis()) {
DatabaseHelper.deleteMail(this);
} else {
DatabaseHelper.saveMail(this);
}
}
@Entity
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, Player sender) {
this(title, content, sender.getNickname());
}
public MailContent(String title, String content, String sender) {
this.title = title;
this.content = content;
this.sender = sender;
}
}
@Entity
public static class MailItem {
public int itemId;
public int itemCount;
public int itemLevel;
public MailItem() {
this.itemId = 11101;
this.itemCount = 1;
this.itemLevel = 1;
}
public MailItem(int itemId) {
this(itemId, 1);
}
public MailItem(int itemId, int itemCount) {
this(itemId, itemCount, 1);
}
public MailItem(int itemId, int itemCount, int itemLevel) {
this.itemId = itemId;
this.itemCount = itemCount;
this.itemLevel = itemLevel;
}
}
}
package emu.grasscutter.game.mail;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Indexed;
import dev.morphia.annotations.Transient;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.*;
import emu.grasscutter.net.proto.EquipParamOuterClass.EquipParam;
import emu.grasscutter.net.proto.MailCollectStateOuterClass.MailCollectState;
import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent;
import org.bson.types.ObjectId;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import static emu.grasscutter.net.proto.MailItemOuterClass.MailItem.*;
@Entity(value = "mail", useDiscriminator = false)
public final class Mail {
@Id private ObjectId id;
@Indexed private int ownerUid;
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;
@Transient private boolean shouldDelete;
public Mail() {
this(new MailContent(), new ArrayList<MailItem>(), (int) Instant.now().getEpochSecond() + 604800); // TODO: add expire time to send mail command
}
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime) {
this(mailContent, itemList, expireTime, 0);
}
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.mailContent = mailContent;
this.itemList = itemList;
this.sendTime = (int) Instant.now().getEpochSecond();
this.expireTime = expireTime;
this.importance = importance; // Starred mail, 0 = No star, 1 = Star.
this.isRead = false;
this.isAttachmentGot = false;
this.stateValue = state; // Different mailboxes, 1 = Default, 3 = Gift-box.
}
public ObjectId getId() {
return id;
}
public int getOwnerUid() {
return ownerUid;
}
public void setOwnerUid(int ownerUid) {
this.ownerUid = ownerUid;
}
public MailDataOuterClass.MailData toProto(Player player) {
return MailDataOuterClass.MailData.newBuilder()
.setMailId(player.getMailId(this))
.setMailTextContent(this.mailContent.toProto())
.addAllItemList(this.itemList.stream().map(MailItem::toProto).toList())
.setSendTime((int) this.sendTime)
.setExpireTime((int) this.expireTime)
.setImportance(this.importance)
.setIsRead(this.isRead)
.setIsAttachmentGot(this.isAttachmentGot)
.setCollectState(MailCollectState.MAIL_COLLECT_STATE_NOT_COLLECTIBLE)
.build();
}
@Entity
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, Player sender) {
this(title, content, sender.getNickname());
}
public MailContent(String title, String content, String sender) {
this.title = title;
this.content = content;
this.sender = sender;
}
public MailTextContent toProto() {
return MailTextContent.newBuilder()
.setTitle(this.title)
.setContent(this.content)
.setSender(this.sender)
.build();
}
}
@Entity
public static class MailItem {
public int itemId;
public int itemCount;
public int itemLevel;
public MailItem() {
this.itemId = 11101;
this.itemCount = 1;
this.itemLevel = 1;
}
public MailItem(int itemId) {
this(itemId, 1);
}
public MailItem(int itemId, int itemCount) {
this(itemId, itemCount, 1);
}
public MailItem(int itemId, int itemCount, int itemLevel) {
this.itemId = itemId;
this.itemCount = itemCount;
this.itemLevel = itemLevel;
}
public MailItemOuterClass.MailItem toProto() {
return newBuilder().setEquipParam(EquipParam.newBuilder()
.setItemId(this.itemId)
.setItemNum(this.itemCount)
.setItemLevel(this.itemLevel)
.setPromoteLevel(0)//mock
.build())
.build();
}
}
public void save() {
if (this.expireTime * 1000 < System.currentTimeMillis()) {
DatabaseHelper.deleteMail(this);
} else {
DatabaseHelper.saveMail(this);
}
}
}

View File

@ -0,0 +1,17 @@
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetAllMailNotifyOuterClass.GetAllMailNotify;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetAllMailResultNotify;
@Opcodes(PacketOpcodes.GetAllMailNotify)
public final class HandlerGetAllMailNotify extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = GetAllMailNotify.parseFrom(payload);
session.send(new PacketGetAllMailResultNotify(session.getPlayer(), req.getIsCollected()));
}
}

View File

@ -1,19 +0,0 @@
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetAllMailReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetAllMailRsp;
@Opcodes(PacketOpcodes.GetAllMailReq)
public class HandlerGetAllMailReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
GetAllMailReqOuterClass.GetAllMailReq req =
GetAllMailReqOuterClass.GetAllMailReq.parseFrom(payload);
session.send(new PacketGetAllMailRsp(session.getPlayer(), req.getIsCollected()));
}
}

View File

@ -0,0 +1,40 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetAllMailResultNotifyOuterClass.GetAllMailResultNotify;
import emu.grasscutter.utils.Utils;
import java.time.Instant;
import java.util.List;
public final class PacketGetAllMailResultNotify extends BasePacket {
/**
* @param player The player to fetch the mail for.
* @param gifts Is the mail for gifts?
*/
public PacketGetAllMailResultNotify(Player player, boolean gifts) {
super(PacketOpcodes.GetAllMailResultNotify);
var packet = GetAllMailResultNotify.newBuilder()
.setTransaction(player.getUid() + "-" + Utils.getCurrentSeconds() + "-" + 0)
.setIsCollected(gifts)
.setPacketBeSentNum(1)
.setPacketNum(1);
var inbox = player.getAllMail();
if (!gifts && inbox.size() > 0) {
packet.addAllMailList(inbox.stream()
.filter(mail -> mail.stateValue == 1)
.filter(mail -> mail.expireTime > Instant.now().getEpochSecond())
.map(mail -> mail.toProto(player)).toList());
} else {
// Empty mailbox.
// TODO: Implement the gift mailbox.
packet.addAllMailList(List.of());
}
this.setData(packet.build());
}
}

View File

@ -1,89 +0,0 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.mail.Mail;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.EquipParamOuterClass;
import emu.grasscutter.net.proto.GetAllMailRspOuterClass.GetAllMailRsp;
import emu.grasscutter.net.proto.MailDataOuterClass;
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 java.util.ArrayList;
import java.util.List;
public class PacketGetAllMailRsp extends BasePacket {
public PacketGetAllMailRsp(Player player, boolean isGiftMail) {
super(PacketOpcodes.GetAllMailRsp);
GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder();
if (isGiftMail) {
proto.setIsCollected(true);
} else {
proto.setIsCollected(false);
if (player.getAllMail().size() != 0) { // Make sure the player has mail
List<MailData> mailDataList = new ArrayList<MailData>();
for (Mail message : player.getAllMail()) {
if (message.stateValue == 1) { // Make sure it isn't a gift
if (message.expireTime
> (int)
Instant.now()
.getEpochSecond()) { // Make sure the message isn't expired (The game won't
// show expired mail, but I don't want to send
// unnecessary information).
if (mailDataList.size()
<= 1000) { // Make sure that there isn't over 1000 messages in the mailbox. (idk
// what will happen if there is but the game probably won't like it.)
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<>();
for (Mail.MailItem item : message.itemList) {
MailItemOuterClass.MailItem.Builder mailItem =
MailItemOuterClass.MailItem.newBuilder();
EquipParamOuterClass.EquipParam.Builder itemParam =
EquipParamOuterClass.EquipParam.newBuilder();
itemParam.setItemId(item.itemId);
itemParam.setItemNum(item.itemCount);
mailItem.setEquipParam(itemParam.build());
mailItems.add(mailItem.build());
}
MailDataOuterClass.MailData.Builder mailData =
MailDataOuterClass.MailData.newBuilder();
mailData.setMailId(player.getMailId(message));
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.setCollectStateValue(1);
mailDataList.add(mailData.build());
}
}
}
}
proto.addAllMailList(mailDataList);
proto.setIsTruncated(
mailDataList.size()
> 1000); // When enabled this will send a notification to the user telling them
// their inbox is full and they should delete old messages when opening the
// mailbox.
}
}
this.setData(proto.build());
}
}