mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 20:34:36 +01:00
Improve next package handling
This commit is contained in:
@@ -505,6 +505,10 @@ public class Player implements GameDatabaseObject {
|
||||
|
||||
// Next packages
|
||||
|
||||
public boolean hasNextPackages() {
|
||||
return this.getNextPackages().size() > 0;
|
||||
}
|
||||
|
||||
public void addNextPackage(int msgId, ProtoMessage<?> proto) {
|
||||
this.getNextPackages().add(new NetMsgPacket(msgId, proto));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import emu.nebula.game.account.Account;
|
||||
import emu.nebula.game.account.AccountHelper;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.proto.Public.MailState;
|
||||
import emu.nebula.proto.Public.Nil;
|
||||
import emu.nebula.util.AeadHelper;
|
||||
import emu.nebula.util.Utils;
|
||||
import lombok.Getter;
|
||||
@@ -140,25 +141,27 @@ public class GameSession {
|
||||
}
|
||||
|
||||
// Packet encoding helper functions
|
||||
|
||||
public byte[] encodeMsg(int msgId, byte[] packet) {
|
||||
return PacketHelper.encodeMsg(msgId, packet);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public byte[] encodeMsg(int msgId, ProtoMessage<?> proto) {
|
||||
// Add any extra data
|
||||
this.addNextPackage(proto);
|
||||
this.addNextPackages(proto);
|
||||
|
||||
// Encode to message like normal
|
||||
return PacketHelper.encodeMsg(msgId, proto);
|
||||
}
|
||||
|
||||
public byte[] encodeMsg(int msgId) {
|
||||
// Create a proto so we can add next packages
|
||||
if (this.getPlayer() != null && this.getPlayer().hasNextPackages()) {
|
||||
return this.encodeMsg(msgId, Nil.newInstance());
|
||||
}
|
||||
|
||||
// Encode simple message
|
||||
return PacketHelper.encodeMsg(msgId);
|
||||
}
|
||||
|
||||
private void addNextPackage(ProtoMessage<?> proto) {
|
||||
private void addNextPackages(ProtoMessage<?> proto) {
|
||||
// Sanity check and make sure proto has a "nextPackage" field
|
||||
if (this.getPlayer() == null || !PacketHelper.hasNextPackageMethod(proto)) {
|
||||
return;
|
||||
|
||||
@@ -10,7 +10,9 @@ public class Handler extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Template
|
||||
// Template hanlder
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.none);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user