From f0c10071d902a8669b391d3c901635ff96368637 Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Tue, 17 Oct 2023 22:56:36 -0700 Subject: [PATCH] Implement mail attachments --- .../ClientMailAttachmentItemOuterClass.java | 339 ++++++++++ .../TakeMailAttachmentCsReqOuterClass.java | 381 +++++++++++ .../TakeMailAttachmentScRspOuterClass.java | 601 ++++++++++++++++++ .../java/emu/lunarcore/game/mail/Mail.java | 20 +- .../java/emu/lunarcore/game/mail/Mailbox.java | 26 + .../recv/HandlerTakeMailAttachmentCsReq.java | 25 + .../send/PacketTakeMailAttachmentScRsp.java | 28 + 7 files changed, 1418 insertions(+), 2 deletions(-) create mode 100644 src/generated/main/emu/lunarcore/proto/ClientMailAttachmentItemOuterClass.java create mode 100644 src/generated/main/emu/lunarcore/proto/TakeMailAttachmentCsReqOuterClass.java create mode 100644 src/generated/main/emu/lunarcore/proto/TakeMailAttachmentScRspOuterClass.java create mode 100644 src/main/java/emu/lunarcore/server/packet/recv/HandlerTakeMailAttachmentCsReq.java create mode 100644 src/main/java/emu/lunarcore/server/packet/send/PacketTakeMailAttachmentScRsp.java diff --git a/src/generated/main/emu/lunarcore/proto/ClientMailAttachmentItemOuterClass.java b/src/generated/main/emu/lunarcore/proto/ClientMailAttachmentItemOuterClass.java new file mode 100644 index 0000000..342935e --- /dev/null +++ b/src/generated/main/emu/lunarcore/proto/ClientMailAttachmentItemOuterClass.java @@ -0,0 +1,339 @@ +// Code generated by protocol buffer compiler. Do not edit! +package emu.lunarcore.proto; + +import java.io.IOException; +import us.hebi.quickbuf.FieldName; +import us.hebi.quickbuf.InvalidProtocolBufferException; +import us.hebi.quickbuf.JsonSink; +import us.hebi.quickbuf.JsonSource; +import us.hebi.quickbuf.MessageFactory; +import us.hebi.quickbuf.ProtoMessage; +import us.hebi.quickbuf.ProtoSink; +import us.hebi.quickbuf.ProtoSource; + +public final class ClientMailAttachmentItemOuterClass { + /** + * Protobuf type {@code ClientMailAttachmentItem} + */ + public static final class ClientMailAttachmentItem extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional uint32 FKIPJPLMBFI = 2; + */ + private int fKIPJPLMBFI; + + /** + * optional uint32 ANAFKBMJOBJ = 12; + */ + private int aNAFKBMJOBJ; + + private ClientMailAttachmentItem() { + } + + /** + * @return a new empty instance of {@code ClientMailAttachmentItem} + */ + public static ClientMailAttachmentItem newInstance() { + return new ClientMailAttachmentItem(); + } + + /** + * optional uint32 FKIPJPLMBFI = 2; + * @return whether the fKIPJPLMBFI field is set + */ + public boolean hasFKIPJPLMBFI() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional uint32 FKIPJPLMBFI = 2; + * @return this + */ + public ClientMailAttachmentItem clearFKIPJPLMBFI() { + bitField0_ &= ~0x00000001; + fKIPJPLMBFI = 0; + return this; + } + + /** + * optional uint32 FKIPJPLMBFI = 2; + * @return the fKIPJPLMBFI + */ + public int getFKIPJPLMBFI() { + return fKIPJPLMBFI; + } + + /** + * optional uint32 FKIPJPLMBFI = 2; + * @param value the fKIPJPLMBFI to set + * @return this + */ + public ClientMailAttachmentItem setFKIPJPLMBFI(final int value) { + bitField0_ |= 0x00000001; + fKIPJPLMBFI = value; + return this; + } + + /** + * optional uint32 ANAFKBMJOBJ = 12; + * @return whether the aNAFKBMJOBJ field is set + */ + public boolean hasANAFKBMJOBJ() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional uint32 ANAFKBMJOBJ = 12; + * @return this + */ + public ClientMailAttachmentItem clearANAFKBMJOBJ() { + bitField0_ &= ~0x00000002; + aNAFKBMJOBJ = 0; + return this; + } + + /** + * optional uint32 ANAFKBMJOBJ = 12; + * @return the aNAFKBMJOBJ + */ + public int getANAFKBMJOBJ() { + return aNAFKBMJOBJ; + } + + /** + * optional uint32 ANAFKBMJOBJ = 12; + * @param value the aNAFKBMJOBJ to set + * @return this + */ + public ClientMailAttachmentItem setANAFKBMJOBJ(final int value) { + bitField0_ |= 0x00000002; + aNAFKBMJOBJ = value; + return this; + } + + @Override + public ClientMailAttachmentItem copyFrom(final ClientMailAttachmentItem other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + fKIPJPLMBFI = other.fKIPJPLMBFI; + aNAFKBMJOBJ = other.aNAFKBMJOBJ; + } + return this; + } + + @Override + public ClientMailAttachmentItem mergeFrom(final ClientMailAttachmentItem other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasFKIPJPLMBFI()) { + setFKIPJPLMBFI(other.fKIPJPLMBFI); + } + if (other.hasANAFKBMJOBJ()) { + setANAFKBMJOBJ(other.aNAFKBMJOBJ); + } + return this; + } + + @Override + public ClientMailAttachmentItem clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + fKIPJPLMBFI = 0; + aNAFKBMJOBJ = 0; + return this; + } + + @Override + public ClientMailAttachmentItem clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof ClientMailAttachmentItem)) { + return false; + } + ClientMailAttachmentItem other = (ClientMailAttachmentItem) o; + return bitField0_ == other.bitField0_ + && (!hasFKIPJPLMBFI() || fKIPJPLMBFI == other.fKIPJPLMBFI) + && (!hasANAFKBMJOBJ() || aNAFKBMJOBJ == other.aNAFKBMJOBJ); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 16); + output.writeUInt32NoTag(fKIPJPLMBFI); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 96); + output.writeUInt32NoTag(aNAFKBMJOBJ); + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(fKIPJPLMBFI); + } + if ((bitField0_ & 0x00000002) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(aNAFKBMJOBJ); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public ClientMailAttachmentItem mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 16: { + // fKIPJPLMBFI + fKIPJPLMBFI = input.readUInt32(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 96) { + break; + } + } + case 96: { + // aNAFKBMJOBJ + aNAFKBMJOBJ = input.readUInt32(); + bitField0_ |= 0x00000002; + tag = input.readTag(); + if (tag != 0) { + break; + } + } + case 0: { + return this; + } + default: { + if (!input.skipField(tag)) { + return this; + } + tag = input.readTag(); + break; + } + } + } + } + + @Override + public void writeTo(final JsonSink output) throws IOException { + output.beginObject(); + if ((bitField0_ & 0x00000001) != 0) { + output.writeUInt32(FieldNames.fKIPJPLMBFI, fKIPJPLMBFI); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeUInt32(FieldNames.aNAFKBMJOBJ, aNAFKBMJOBJ); + } + output.endObject(); + } + + @Override + public ClientMailAttachmentItem mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case -581795918: { + if (input.isAtField(FieldNames.fKIPJPLMBFI)) { + if (!input.trySkipNullValue()) { + fKIPJPLMBFI = input.readUInt32(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case 1037527505: { + if (input.isAtField(FieldNames.aNAFKBMJOBJ)) { + if (!input.trySkipNullValue()) { + aNAFKBMJOBJ = input.readUInt32(); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public ClientMailAttachmentItem clone() { + return new ClientMailAttachmentItem().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static ClientMailAttachmentItem parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new ClientMailAttachmentItem(), data).checkInitialized(); + } + + public static ClientMailAttachmentItem parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new ClientMailAttachmentItem(), input).checkInitialized(); + } + + public static ClientMailAttachmentItem parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new ClientMailAttachmentItem(), input).checkInitialized(); + } + + /** + * @return factory for creating ClientMailAttachmentItem messages + */ + public static MessageFactory getFactory() { + return ClientMailAttachmentItemFactory.INSTANCE; + } + + private enum ClientMailAttachmentItemFactory implements MessageFactory { + INSTANCE; + + @Override + public ClientMailAttachmentItem create() { + return ClientMailAttachmentItem.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName fKIPJPLMBFI = FieldName.forField("FKIPJPLMBFI"); + + static final FieldName aNAFKBMJOBJ = FieldName.forField("ANAFKBMJOBJ"); + } + } +} diff --git a/src/generated/main/emu/lunarcore/proto/TakeMailAttachmentCsReqOuterClass.java b/src/generated/main/emu/lunarcore/proto/TakeMailAttachmentCsReqOuterClass.java new file mode 100644 index 0000000..1cd66be --- /dev/null +++ b/src/generated/main/emu/lunarcore/proto/TakeMailAttachmentCsReqOuterClass.java @@ -0,0 +1,381 @@ +// Code generated by protocol buffer compiler. Do not edit! +package emu.lunarcore.proto; + +import java.io.IOException; +import us.hebi.quickbuf.FieldName; +import us.hebi.quickbuf.InvalidProtocolBufferException; +import us.hebi.quickbuf.JsonSink; +import us.hebi.quickbuf.JsonSource; +import us.hebi.quickbuf.MessageFactory; +import us.hebi.quickbuf.ProtoMessage; +import us.hebi.quickbuf.ProtoSink; +import us.hebi.quickbuf.ProtoSource; +import us.hebi.quickbuf.RepeatedInt; + +public final class TakeMailAttachmentCsReqOuterClass { + /** + * Protobuf type {@code TakeMailAttachmentCsReq} + */ + public static final class TakeMailAttachmentCsReq extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional uint32 BBFNEALMHJB = 7; + */ + private int bBFNEALMHJB; + + /** + * repeated uint32 mail_id_list = 12; + */ + private final RepeatedInt mailIdList = RepeatedInt.newEmptyInstance(); + + private TakeMailAttachmentCsReq() { + } + + /** + * @return a new empty instance of {@code TakeMailAttachmentCsReq} + */ + public static TakeMailAttachmentCsReq newInstance() { + return new TakeMailAttachmentCsReq(); + } + + /** + * optional uint32 BBFNEALMHJB = 7; + * @return whether the bBFNEALMHJB field is set + */ + public boolean hasBBFNEALMHJB() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional uint32 BBFNEALMHJB = 7; + * @return this + */ + public TakeMailAttachmentCsReq clearBBFNEALMHJB() { + bitField0_ &= ~0x00000001; + bBFNEALMHJB = 0; + return this; + } + + /** + * optional uint32 BBFNEALMHJB = 7; + * @return the bBFNEALMHJB + */ + public int getBBFNEALMHJB() { + return bBFNEALMHJB; + } + + /** + * optional uint32 BBFNEALMHJB = 7; + * @param value the bBFNEALMHJB to set + * @return this + */ + public TakeMailAttachmentCsReq setBBFNEALMHJB(final int value) { + bitField0_ |= 0x00000001; + bBFNEALMHJB = value; + return this; + } + + /** + * repeated uint32 mail_id_list = 12; + * @return whether the mailIdList field is set + */ + public boolean hasMailIdList() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * repeated uint32 mail_id_list = 12; + * @return this + */ + public TakeMailAttachmentCsReq clearMailIdList() { + bitField0_ &= ~0x00000002; + mailIdList.clear(); + return this; + } + + /** + * repeated uint32 mail_id_list = 12; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableMailIdList()} if you want to modify it. + * + * @return internal storage object for reading + */ + public RepeatedInt getMailIdList() { + return mailIdList; + } + + /** + * repeated uint32 mail_id_list = 12; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public RepeatedInt getMutableMailIdList() { + bitField0_ |= 0x00000002; + return mailIdList; + } + + /** + * repeated uint32 mail_id_list = 12; + * @param value the mailIdList to add + * @return this + */ + public TakeMailAttachmentCsReq addMailIdList(final int value) { + bitField0_ |= 0x00000002; + mailIdList.add(value); + return this; + } + + /** + * repeated uint32 mail_id_list = 12; + * @param values the mailIdList to add + * @return this + */ + public TakeMailAttachmentCsReq addAllMailIdList(final int... values) { + bitField0_ |= 0x00000002; + mailIdList.addAll(values); + return this; + } + + @Override + public TakeMailAttachmentCsReq copyFrom(final TakeMailAttachmentCsReq other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + bBFNEALMHJB = other.bBFNEALMHJB; + mailIdList.copyFrom(other.mailIdList); + } + return this; + } + + @Override + public TakeMailAttachmentCsReq mergeFrom(final TakeMailAttachmentCsReq other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasBBFNEALMHJB()) { + setBBFNEALMHJB(other.bBFNEALMHJB); + } + if (other.hasMailIdList()) { + getMutableMailIdList().addAll(other.mailIdList); + } + return this; + } + + @Override + public TakeMailAttachmentCsReq clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + bBFNEALMHJB = 0; + mailIdList.clear(); + return this; + } + + @Override + public TakeMailAttachmentCsReq clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + mailIdList.clear(); + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof TakeMailAttachmentCsReq)) { + return false; + } + TakeMailAttachmentCsReq other = (TakeMailAttachmentCsReq) o; + return bitField0_ == other.bitField0_ + && (!hasBBFNEALMHJB() || bBFNEALMHJB == other.bBFNEALMHJB) + && (!hasMailIdList() || mailIdList.equals(other.mailIdList)); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 56); + output.writeUInt32NoTag(bBFNEALMHJB); + } + if ((bitField0_ & 0x00000002) != 0) { + for (int i = 0; i < mailIdList.length(); i++) { + output.writeRawByte((byte) 96); + output.writeUInt32NoTag(mailIdList.array()[i]); + } + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(bBFNEALMHJB); + } + if ((bitField0_ & 0x00000002) != 0) { + size += (1 * mailIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(mailIdList); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public TakeMailAttachmentCsReq mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 56: { + // bBFNEALMHJB + bBFNEALMHJB = input.readUInt32(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 98) { + break; + } + } + case 98: { + // mailIdList [packed=true] + input.readPackedUInt32(mailIdList, tag); + bitField0_ |= 0x00000002; + tag = input.readTag(); + if (tag != 0) { + break; + } + } + case 0: { + return this; + } + default: { + if (!input.skipField(tag)) { + return this; + } + tag = input.readTag(); + break; + } + case 96: { + // mailIdList [packed=false] + tag = input.readRepeatedUInt32(mailIdList, tag); + bitField0_ |= 0x00000002; + break; + } + } + } + } + + @Override + public void writeTo(final JsonSink output) throws IOException { + output.beginObject(); + if ((bitField0_ & 0x00000001) != 0) { + output.writeUInt32(FieldNames.bBFNEALMHJB, bBFNEALMHJB); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRepeatedUInt32(FieldNames.mailIdList, mailIdList); + } + output.endObject(); + } + + @Override + public TakeMailAttachmentCsReq mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case 1149456699: { + if (input.isAtField(FieldNames.bBFNEALMHJB)) { + if (!input.trySkipNullValue()) { + bBFNEALMHJB = input.readUInt32(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case -1612269328: + case 1599691450: { + if (input.isAtField(FieldNames.mailIdList)) { + if (!input.trySkipNullValue()) { + input.readRepeatedUInt32(mailIdList); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public TakeMailAttachmentCsReq clone() { + return new TakeMailAttachmentCsReq().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static TakeMailAttachmentCsReq parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new TakeMailAttachmentCsReq(), data).checkInitialized(); + } + + public static TakeMailAttachmentCsReq parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeMailAttachmentCsReq(), input).checkInitialized(); + } + + public static TakeMailAttachmentCsReq parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeMailAttachmentCsReq(), input).checkInitialized(); + } + + /** + * @return factory for creating TakeMailAttachmentCsReq messages + */ + public static MessageFactory getFactory() { + return TakeMailAttachmentCsReqFactory.INSTANCE; + } + + private enum TakeMailAttachmentCsReqFactory implements MessageFactory { + INSTANCE; + + @Override + public TakeMailAttachmentCsReq create() { + return TakeMailAttachmentCsReq.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName bBFNEALMHJB = FieldName.forField("BBFNEALMHJB"); + + static final FieldName mailIdList = FieldName.forField("mailIdList", "mail_id_list"); + } + } +} diff --git a/src/generated/main/emu/lunarcore/proto/TakeMailAttachmentScRspOuterClass.java b/src/generated/main/emu/lunarcore/proto/TakeMailAttachmentScRspOuterClass.java new file mode 100644 index 0000000..5ccffe2 --- /dev/null +++ b/src/generated/main/emu/lunarcore/proto/TakeMailAttachmentScRspOuterClass.java @@ -0,0 +1,601 @@ +// Code generated by protocol buffer compiler. Do not edit! +package emu.lunarcore.proto; + +import java.io.IOException; +import us.hebi.quickbuf.FieldName; +import us.hebi.quickbuf.InvalidProtocolBufferException; +import us.hebi.quickbuf.JsonSink; +import us.hebi.quickbuf.JsonSource; +import us.hebi.quickbuf.MessageFactory; +import us.hebi.quickbuf.ProtoMessage; +import us.hebi.quickbuf.ProtoSink; +import us.hebi.quickbuf.ProtoSource; +import us.hebi.quickbuf.RepeatedInt; +import us.hebi.quickbuf.RepeatedMessage; + +public final class TakeMailAttachmentScRspOuterClass { + /** + * Protobuf type {@code TakeMailAttachmentScRsp} + */ + public static final class TakeMailAttachmentScRsp extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional uint32 retcode = 11; + */ + private int retcode; + + /** + * optional .ItemList attachment = 10; + */ + private final ItemListOuterClass.ItemList attachment = ItemListOuterClass.ItemList.newInstance(); + + /** + * repeated uint32 succ_mail_id_list = 6; + */ + private final RepeatedInt succMailIdList = RepeatedInt.newEmptyInstance(); + + /** + * repeated .ClientMailAttachmentItem fail_mail_list = 13; + */ + private final RepeatedMessage failMailList = RepeatedMessage.newEmptyInstance(ClientMailAttachmentItemOuterClass.ClientMailAttachmentItem.getFactory()); + + private TakeMailAttachmentScRsp() { + } + + /** + * @return a new empty instance of {@code TakeMailAttachmentScRsp} + */ + public static TakeMailAttachmentScRsp newInstance() { + return new TakeMailAttachmentScRsp(); + } + + /** + * optional uint32 retcode = 11; + * @return whether the retcode field is set + */ + public boolean hasRetcode() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional uint32 retcode = 11; + * @return this + */ + public TakeMailAttachmentScRsp clearRetcode() { + bitField0_ &= ~0x00000001; + retcode = 0; + return this; + } + + /** + * optional uint32 retcode = 11; + * @return the retcode + */ + public int getRetcode() { + return retcode; + } + + /** + * optional uint32 retcode = 11; + * @param value the retcode to set + * @return this + */ + public TakeMailAttachmentScRsp setRetcode(final int value) { + bitField0_ |= 0x00000001; + retcode = value; + return this; + } + + /** + * optional .ItemList attachment = 10; + * @return whether the attachment field is set + */ + public boolean hasAttachment() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional .ItemList attachment = 10; + * @return this + */ + public TakeMailAttachmentScRsp clearAttachment() { + bitField0_ &= ~0x00000002; + attachment.clear(); + return this; + } + + /** + * optional .ItemList attachment = 10; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableAttachment()} if you want to modify it. + * + * @return internal storage object for reading + */ + public ItemListOuterClass.ItemList getAttachment() { + return attachment; + } + + /** + * optional .ItemList attachment = 10; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public ItemListOuterClass.ItemList getMutableAttachment() { + bitField0_ |= 0x00000002; + return attachment; + } + + /** + * optional .ItemList attachment = 10; + * @param value the attachment to set + * @return this + */ + public TakeMailAttachmentScRsp setAttachment(final ItemListOuterClass.ItemList value) { + bitField0_ |= 0x00000002; + attachment.copyFrom(value); + return this; + } + + /** + * repeated uint32 succ_mail_id_list = 6; + * @return whether the succMailIdList field is set + */ + public boolean hasSuccMailIdList() { + return (bitField0_ & 0x00000004) != 0; + } + + /** + * repeated uint32 succ_mail_id_list = 6; + * @return this + */ + public TakeMailAttachmentScRsp clearSuccMailIdList() { + bitField0_ &= ~0x00000004; + succMailIdList.clear(); + return this; + } + + /** + * repeated uint32 succ_mail_id_list = 6; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableSuccMailIdList()} if you want to modify it. + * + * @return internal storage object for reading + */ + public RepeatedInt getSuccMailIdList() { + return succMailIdList; + } + + /** + * repeated uint32 succ_mail_id_list = 6; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public RepeatedInt getMutableSuccMailIdList() { + bitField0_ |= 0x00000004; + return succMailIdList; + } + + /** + * repeated uint32 succ_mail_id_list = 6; + * @param value the succMailIdList to add + * @return this + */ + public TakeMailAttachmentScRsp addSuccMailIdList(final int value) { + bitField0_ |= 0x00000004; + succMailIdList.add(value); + return this; + } + + /** + * repeated uint32 succ_mail_id_list = 6; + * @param values the succMailIdList to add + * @return this + */ + public TakeMailAttachmentScRsp addAllSuccMailIdList(final int... values) { + bitField0_ |= 0x00000004; + succMailIdList.addAll(values); + return this; + } + + /** + * repeated .ClientMailAttachmentItem fail_mail_list = 13; + * @return whether the failMailList field is set + */ + public boolean hasFailMailList() { + return (bitField0_ & 0x00000008) != 0; + } + + /** + * repeated .ClientMailAttachmentItem fail_mail_list = 13; + * @return this + */ + public TakeMailAttachmentScRsp clearFailMailList() { + bitField0_ &= ~0x00000008; + failMailList.clear(); + return this; + } + + /** + * repeated .ClientMailAttachmentItem fail_mail_list = 13; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableFailMailList()} if you want to modify it. + * + * @return internal storage object for reading + */ + public RepeatedMessage getFailMailList( + ) { + return failMailList; + } + + /** + * repeated .ClientMailAttachmentItem fail_mail_list = 13; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public RepeatedMessage getMutableFailMailList( + ) { + bitField0_ |= 0x00000008; + return failMailList; + } + + /** + * repeated .ClientMailAttachmentItem fail_mail_list = 13; + * @param value the failMailList to add + * @return this + */ + public TakeMailAttachmentScRsp addFailMailList( + final ClientMailAttachmentItemOuterClass.ClientMailAttachmentItem value) { + bitField0_ |= 0x00000008; + failMailList.add(value); + return this; + } + + /** + * repeated .ClientMailAttachmentItem fail_mail_list = 13; + * @param values the failMailList to add + * @return this + */ + public TakeMailAttachmentScRsp addAllFailMailList( + final ClientMailAttachmentItemOuterClass.ClientMailAttachmentItem... values) { + bitField0_ |= 0x00000008; + failMailList.addAll(values); + return this; + } + + @Override + public TakeMailAttachmentScRsp copyFrom(final TakeMailAttachmentScRsp other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + retcode = other.retcode; + attachment.copyFrom(other.attachment); + succMailIdList.copyFrom(other.succMailIdList); + failMailList.copyFrom(other.failMailList); + } + return this; + } + + @Override + public TakeMailAttachmentScRsp mergeFrom(final TakeMailAttachmentScRsp other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasRetcode()) { + setRetcode(other.retcode); + } + if (other.hasAttachment()) { + getMutableAttachment().mergeFrom(other.attachment); + } + if (other.hasSuccMailIdList()) { + getMutableSuccMailIdList().addAll(other.succMailIdList); + } + if (other.hasFailMailList()) { + getMutableFailMailList().addAll(other.failMailList); + } + return this; + } + + @Override + public TakeMailAttachmentScRsp clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + retcode = 0; + attachment.clear(); + succMailIdList.clear(); + failMailList.clear(); + return this; + } + + @Override + public TakeMailAttachmentScRsp clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + attachment.clearQuick(); + succMailIdList.clear(); + failMailList.clearQuick(); + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof TakeMailAttachmentScRsp)) { + return false; + } + TakeMailAttachmentScRsp other = (TakeMailAttachmentScRsp) o; + return bitField0_ == other.bitField0_ + && (!hasRetcode() || retcode == other.retcode) + && (!hasAttachment() || attachment.equals(other.attachment)) + && (!hasSuccMailIdList() || succMailIdList.equals(other.succMailIdList)) + && (!hasFailMailList() || failMailList.equals(other.failMailList)); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 88); + output.writeUInt32NoTag(retcode); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 82); + output.writeMessageNoTag(attachment); + } + if ((bitField0_ & 0x00000004) != 0) { + for (int i = 0; i < succMailIdList.length(); i++) { + output.writeRawByte((byte) 48); + output.writeUInt32NoTag(succMailIdList.array()[i]); + } + } + if ((bitField0_ & 0x00000008) != 0) { + for (int i = 0; i < failMailList.length(); i++) { + output.writeRawByte((byte) 106); + output.writeMessageNoTag(failMailList.get(i)); + } + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(retcode); + } + if ((bitField0_ & 0x00000002) != 0) { + size += 1 + ProtoSink.computeMessageSizeNoTag(attachment); + } + if ((bitField0_ & 0x00000004) != 0) { + size += (1 * succMailIdList.length()) + ProtoSink.computeRepeatedUInt32SizeNoTag(succMailIdList); + } + if ((bitField0_ & 0x00000008) != 0) { + size += (1 * failMailList.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(failMailList); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public TakeMailAttachmentScRsp mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 88: { + // retcode + retcode = input.readUInt32(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 82) { + break; + } + } + case 82: { + // attachment + input.readMessage(attachment); + bitField0_ |= 0x00000002; + tag = input.readTag(); + if (tag != 50) { + break; + } + } + case 50: { + // succMailIdList [packed=true] + input.readPackedUInt32(succMailIdList, tag); + bitField0_ |= 0x00000004; + tag = input.readTag(); + if (tag != 106) { + break; + } + } + case 106: { + // failMailList + tag = input.readRepeatedMessage(failMailList, tag); + bitField0_ |= 0x00000008; + if (tag != 0) { + break; + } + } + case 0: { + return this; + } + default: { + if (!input.skipField(tag)) { + return this; + } + tag = input.readTag(); + break; + } + case 48: { + // succMailIdList [packed=false] + tag = input.readRepeatedUInt32(succMailIdList, tag); + bitField0_ |= 0x00000004; + break; + } + } + } + } + + @Override + public void writeTo(final JsonSink output) throws IOException { + output.beginObject(); + if ((bitField0_ & 0x00000001) != 0) { + output.writeUInt32(FieldNames.retcode, retcode); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeMessage(FieldNames.attachment, attachment); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeRepeatedUInt32(FieldNames.succMailIdList, succMailIdList); + } + if ((bitField0_ & 0x00000008) != 0) { + output.writeRepeatedMessage(FieldNames.failMailList, failMailList); + } + output.endObject(); + } + + @Override + public TakeMailAttachmentScRsp mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case 1097936398: { + if (input.isAtField(FieldNames.retcode)) { + if (!input.trySkipNullValue()) { + retcode = input.readUInt32(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case -1963501277: { + if (input.isAtField(FieldNames.attachment)) { + if (!input.trySkipNullValue()) { + input.readMessage(attachment); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + case 492844242: + case 1318122903: { + if (input.isAtField(FieldNames.succMailIdList)) { + if (!input.trySkipNullValue()) { + input.readRepeatedUInt32(succMailIdList); + bitField0_ |= 0x00000004; + } + } else { + input.skipUnknownField(); + } + break; + } + case 1034400819: + case -348560827: { + if (input.isAtField(FieldNames.failMailList)) { + if (!input.trySkipNullValue()) { + input.readRepeatedMessage(failMailList); + bitField0_ |= 0x00000008; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public TakeMailAttachmentScRsp clone() { + return new TakeMailAttachmentScRsp().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static TakeMailAttachmentScRsp parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new TakeMailAttachmentScRsp(), data).checkInitialized(); + } + + public static TakeMailAttachmentScRsp parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeMailAttachmentScRsp(), input).checkInitialized(); + } + + public static TakeMailAttachmentScRsp parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeMailAttachmentScRsp(), input).checkInitialized(); + } + + /** + * @return factory for creating TakeMailAttachmentScRsp messages + */ + public static MessageFactory getFactory() { + return TakeMailAttachmentScRspFactory.INSTANCE; + } + + private enum TakeMailAttachmentScRspFactory implements MessageFactory { + INSTANCE; + + @Override + public TakeMailAttachmentScRsp create() { + return TakeMailAttachmentScRsp.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName retcode = FieldName.forField("retcode"); + + static final FieldName attachment = FieldName.forField("attachment"); + + static final FieldName succMailIdList = FieldName.forField("succMailIdList", "succ_mail_id_list"); + + static final FieldName failMailList = FieldName.forField("failMailList", "fail_mail_list"); + } + } +} diff --git a/src/main/java/emu/lunarcore/game/mail/Mail.java b/src/main/java/emu/lunarcore/game/mail/Mail.java index a487c1d..113cc68 100644 --- a/src/main/java/emu/lunarcore/game/mail/Mail.java +++ b/src/main/java/emu/lunarcore/game/mail/Mail.java @@ -1,5 +1,6 @@ package emu.lunarcore.game.mail; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -55,6 +56,13 @@ public class Mail { } } + public void addAttachment(GameItem item) { + if (this.attachments == null) { + this.attachments = new ArrayList<>(); + } + this.attachments.add(item); + } + // Database public void save() { @@ -75,8 +83,16 @@ public class Mail { .setSender(this.getSender()) .setTime(this.getTime()) .setExpireTime(this.getExpiry()) - .setIsRead(this.isRead()) - .setAttachment(ItemList.newInstance()); + .setIsRead(this.isRead()); + + // Add attachments + ItemList list = ItemList.newInstance(); + + if (this.attachments != null) { + this.attachments.stream().map(GameItem::toProto).forEach(list::addItemList); + } + + proto.setAttachment(list); return proto; } diff --git a/src/main/java/emu/lunarcore/game/mail/Mailbox.java b/src/main/java/emu/lunarcore/game/mail/Mailbox.java index d0f054b..8254df7 100644 --- a/src/main/java/emu/lunarcore/game/mail/Mailbox.java +++ b/src/main/java/emu/lunarcore/game/mail/Mailbox.java @@ -1,9 +1,12 @@ package emu.lunarcore.game.mail; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.stream.Stream; import emu.lunarcore.LunarRail; +import emu.lunarcore.game.inventory.GameItem; import emu.lunarcore.game.player.BasePlayerManager; import emu.lunarcore.game.player.Player; import emu.lunarcore.server.packet.send.PacketNewMailScNotify; @@ -56,6 +59,28 @@ public class Mailbox extends BasePlayerManager implements Iterable { // Send packet this.getPlayer().sendPacket(new PacketNewMailScNotify(mail)); } + + public synchronized List takeMailAttachments(RepeatedInt idList) { + List attachments = new ArrayList<>(); + + for (int id : idList) { + Mail mail = getMap().get(id); + if (mail == null || mail.isRead() || mail.getAttachments() == null) { + continue; + } + + // Add attachments to inventory + for (GameItem item : mail.getAttachments()) { + getPlayer().getInventory().addItem(item); + attachments.add(item); + } + + // Set read + mail.setRead(); + } + + return attachments; + } public synchronized IntList deleteMail(RepeatedInt idList) { IntList deleteList = new IntArrayList(); @@ -91,4 +116,5 @@ public class Mailbox extends BasePlayerManager implements Iterable { stream.forEach(this::putMail); } + } diff --git a/src/main/java/emu/lunarcore/server/packet/recv/HandlerTakeMailAttachmentCsReq.java b/src/main/java/emu/lunarcore/server/packet/recv/HandlerTakeMailAttachmentCsReq.java new file mode 100644 index 0000000..9d0c266 --- /dev/null +++ b/src/main/java/emu/lunarcore/server/packet/recv/HandlerTakeMailAttachmentCsReq.java @@ -0,0 +1,25 @@ +package emu.lunarcore.server.packet.recv; + +import java.util.List; + +import emu.lunarcore.game.inventory.GameItem; +import emu.lunarcore.proto.TakeMailAttachmentCsReqOuterClass.TakeMailAttachmentCsReq; +import emu.lunarcore.server.game.GameSession; +import emu.lunarcore.server.packet.CmdId; +import emu.lunarcore.server.packet.Opcodes; +import emu.lunarcore.server.packet.PacketHandler; +import emu.lunarcore.server.packet.send.PacketTakeMailAttachmentScRsp; + +@Opcodes(CmdId.TakeMailAttachmentCsReq) +public class HandlerTakeMailAttachmentCsReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] data) throws Exception { + var req = TakeMailAttachmentCsReq.parseFrom(data); + + List attachments = session.getPlayer().getMailbox().takeMailAttachments(req.getMailIdList()); + + session.send(new PacketTakeMailAttachmentScRsp(req.getMailIdList(), attachments)); + } + +} diff --git a/src/main/java/emu/lunarcore/server/packet/send/PacketTakeMailAttachmentScRsp.java b/src/main/java/emu/lunarcore/server/packet/send/PacketTakeMailAttachmentScRsp.java new file mode 100644 index 0000000..9dbd011 --- /dev/null +++ b/src/main/java/emu/lunarcore/server/packet/send/PacketTakeMailAttachmentScRsp.java @@ -0,0 +1,28 @@ +package emu.lunarcore.server.packet.send; + +import java.util.Collection; + +import emu.lunarcore.game.inventory.GameItem; +import emu.lunarcore.proto.TakeMailAttachmentScRspOuterClass.TakeMailAttachmentScRsp; +import emu.lunarcore.server.packet.BasePacket; +import emu.lunarcore.server.packet.CmdId; +import us.hebi.quickbuf.RepeatedInt; + +public class PacketTakeMailAttachmentScRsp extends BasePacket { + + public PacketTakeMailAttachmentScRsp(RepeatedInt idList, Collection items) { + super(CmdId.TakeMailAttachmentScRsp); + + var data = TakeMailAttachmentScRsp.newInstance(); + + for (int id : idList) { + data.addSuccMailIdList(id); + } + + for (GameItem item : items) { + data.getMutableAttachment().addItemList(item.toProto()); + } + + this.setData(data); + } +}