Refactor how next packages are handled

This commit is contained in:
Melledy committed 2025-11-02 22:23:35 -08:00
1 parent d5c112bcf9
commit e0dc291def
4 files changed
+71 -5

No files matched your search

+36 -5
View File
@@ -167,13 +167,44 @@ public class GameSession {
this.getPlayer().getMailbox().clearNewState();
// Send mail state notify
byte[] nextPackage = PacketHelper.encodeMsg(
NetMsgId.mail_state_notify,
MailState.newInstance().setNew(true)
this.getPlayer().addNextPackage(
NetMsgId.mail_state_notify,
MailState.newInstance().setNew(true)
);
}
// Set next package
if (this.getPlayer().getNextPackages().size() > 0) {
// Set current package
NetMsgPacket curPacket = null;
// Set via reflection
PacketHelper.setNextPackage(proto, nextPackage);
// Chain link next packages
while (getPlayer().getNextPackages().size() > 0) {
// Make sure the current packet has a nextPackage field
if (curPacket != null && !PacketHelper.hasNextPackageMethod(curPacket.getProto())) {
break;
}
// Get current package
var nextPacket = getPlayer().getNextPackages().pop();
// Set cur packet if its null
if (curPacket == null) {
curPacket = nextPacket;
continue;
}
// Set next package
PacketHelper.setNextPackage(nextPacket.getProto(), curPacket.toByteArray());
// Update next packet
curPacket = nextPacket;
}
// Set next package of current proto via reflection
if (curPacket != null) {
PacketHelper.setNextPackage(proto, curPacket.toByteArray());
}
}
}
}
@@ -0,0 +1,19 @@
package emu.nebula.net;
import lombok.Getter;
import us.hebi.quickbuf.ProtoMessage;
@Getter
public class NetMsgPacket {
private int msgId;
private ProtoMessage<?> proto;
public NetMsgPacket(int msgId, ProtoMessage<?> proto) {
this.msgId = msgId;
this.proto = proto;
}
public byte[] toByteArray() {
return PacketHelper.encodeMsg(this.getMsgId(), this.getProto());
}
}
@@ -14,6 +14,8 @@ import us.hebi.quickbuf.ProtoSink;
public class PacketHelper {
private static Object2IntMap<Class<?>> methodIndexCache = new Object2IntOpenHashMap<>();
// Next packages
public static void cacheProtos() {
var classes = new Reflections(Nebula.class.getPackage().getName()).getSubTypesOf(ProtoMessage.class);