diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index f24cf6f..7e22131 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -108,6 +108,15 @@ public class HPacket implements StringifyAble { isEdited = wasEdited; } + public void maybeCompletePacket(PacketInfoManager packetInfoManager) { + if (canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && !canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) { + completePacket(HMessage.Direction.TOCLIENT, packetInfoManager); + } + else if (!canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) { + completePacket(HMessage.Direction.TOSERVER, packetInfoManager); + } + } + public boolean canComplete(HMessage.Direction direction, PacketInfoManager packetInfoManager) { if (isCorrupted() || identifier == null) return false; diff --git a/G-Earth/src/main/java/gearth/services/extensionhandler/ExtensionHandler.java b/G-Earth/src/main/java/gearth/services/extensionhandler/ExtensionHandler.java index 951b9cc..df15f66 100644 --- a/G-Earth/src/main/java/gearth/services/extensionhandler/ExtensionHandler.java +++ b/G-Earth/src/main/java/gearth/services/extensionhandler/ExtensionHandler.java @@ -231,13 +231,7 @@ public class ExtensionHandler { @Override protected void stringToPacketRequest(String string) { HPacket packet = new HPacket(string); - PacketInfoManager packetInfoManager = hConnection.getPacketInfoManager(); - if (packet.canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && !packet.canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) { - packet.completePacket(HMessage.Direction.TOCLIENT, packetInfoManager); - } - else if (!packet.canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && packet.canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) { - packet.completePacket(HMessage.Direction.TOSERVER, packetInfoManager); - } + packet.maybeCompletePacket(hConnection.getPacketInfoManager()); extension.stringToPacketResponse(packet); } }; diff --git a/G-Earth/src/main/java/gearth/ui/injection/InjectionController.java b/G-Earth/src/main/java/gearth/ui/injection/InjectionController.java index f162a3a..0f20b41 100644 --- a/G-Earth/src/main/java/gearth/ui/injection/InjectionController.java +++ b/G-Earth/src/main/java/gearth/ui/injection/InjectionController.java @@ -153,13 +153,7 @@ public class InjectionController extends SubForm { // complete packet to show correct headerId if (!packets[0].isPacketComplete()) { - HPacket packet = packets[0]; - if (packet.canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && !packet.canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) { - packet.completePacket(HMessage.Direction.TOCLIENT, packetInfoManager); - } - else if (!packet.canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && packet.canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) { - packet.completePacket(HMessage.Direction.TOSERVER, packetInfoManager); - } + packets[0].maybeCompletePacket(packetInfoManager); } lbl_pcktInfo.setText("header (id:" + packets[0].headerId() + ", length:" +