From 1c3193ec573f9df6f68d692cb5ef45c6a177eaed Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 27 Apr 2021 22:08:08 +0200 Subject: [PATCH] some renaming --- .../java/gearth/protocol/HConnection.java | 8 ++--- .../gearth/protocol/connection/HProxy.java | 8 ++--- ...cketSender.java => PacketSenderQueue.java} | 36 +++++++++---------- .../extensionhandler/ExtensionHandler.java | 4 +-- .../ui/injection/InjectionController.java | 9 ++--- .../ui/scheduler/SchedulerController.java | 2 -- 6 files changed, 30 insertions(+), 37 deletions(-) rename G-Earth/src/main/java/gearth/protocol/connection/{AsyncPacketSender.java => PacketSenderQueue.java} (56%) diff --git a/G-Earth/src/main/java/gearth/protocol/HConnection.java b/G-Earth/src/main/java/gearth/protocol/HConnection.java index aa917c9..6c12766 100644 --- a/G-Earth/src/main/java/gearth/protocol/HConnection.java +++ b/G-Earth/src/main/java/gearth/protocol/HConnection.java @@ -137,7 +137,7 @@ public class HConnection { } - public boolean sendToClientAsync(HPacket message) { + public boolean sendToClient(HPacket message) { if (proxy == null) return false; if (!message.isPacketComplete()) { @@ -147,10 +147,10 @@ public class HConnection { if (!message.isPacketComplete()) return false; } - proxy.getAsyncPacketSender().sendToClientAsync(message); + proxy.getPacketSenderQueue().queueToClient(message); return true; } - public boolean sendToServerAsync(HPacket message) { + public boolean sendToServer(HPacket message) { if (proxy == null) return false; if (!message.isPacketComplete()) { @@ -160,7 +160,7 @@ public class HConnection { if (!message.isPacketComplete()) return false; } - proxy.getAsyncPacketSender().sendToServerAsync(message); + proxy.getPacketSenderQueue().queueToServer(message); return true; } diff --git a/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java b/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java index 13548a3..9b90790 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java @@ -25,7 +25,7 @@ public class HProxy { private volatile String clientIdentifier = ""; private volatile PacketInfoManager packetInfoManager = null; - private volatile AsyncPacketSender asyncPacketSender = null; + private volatile PacketSenderQueue packetSenderQueue = null; public HProxy(HClient hClient, String input_domain, String actual_domain, int actual_port, int intercept_port, String intercept_host) { this.hClient = hClient; @@ -46,7 +46,7 @@ public class HProxy { this.hotelVersion = hotelVersion; this.clientIdentifier = clientIdentifier; this.packetInfoManager = PacketInfoManager.fromHotelVersion(hotelVersion, hClient); - this.asyncPacketSender = new AsyncPacketSender(this); + this.packetSenderQueue = new PacketSenderQueue(this); } public String getClientIdentifier() { @@ -89,8 +89,8 @@ public class HProxy { return hotelVersion; } - public AsyncPacketSender getAsyncPacketSender() { - return asyncPacketSender; + public PacketSenderQueue getPacketSenderQueue() { + return packetSenderQueue; } public HClient gethClient() { diff --git a/G-Earth/src/main/java/gearth/protocol/connection/AsyncPacketSender.java b/G-Earth/src/main/java/gearth/protocol/connection/PacketSenderQueue.java similarity index 56% rename from G-Earth/src/main/java/gearth/protocol/connection/AsyncPacketSender.java rename to G-Earth/src/main/java/gearth/protocol/connection/PacketSenderQueue.java index 8c54e87..bef2d2b 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/AsyncPacketSender.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/PacketSenderQueue.java @@ -5,19 +5,19 @@ import gearth.protocol.HPacket; import java.util.LinkedList; import java.util.Queue; -public class AsyncPacketSender { +public class PacketSenderQueue { private final HProxy proxy; - private final Queue sendToClientAsyncQueue = new LinkedList<>(); - private final Queue sendToServerAsyncQueue = new LinkedList<>(); + private final Queue sendToClientQueue = new LinkedList<>(); + private final Queue sendToServerQueue = new LinkedList<>(); - AsyncPacketSender(HProxy proxy) { + PacketSenderQueue(HProxy proxy) { this.proxy = proxy; new Thread(() -> { while (true) { HPacket packet; - synchronized (sendToClientAsyncQueue) { - while ((packet = sendToClientAsyncQueue.poll()) != null) { + synchronized (sendToClientQueue) { + while ((packet = sendToClientQueue.poll()) != null) { sendToClient(packet); } } @@ -32,8 +32,8 @@ public class AsyncPacketSender { new Thread(() -> { while (true) { HPacket packet; - synchronized (sendToServerAsyncQueue) { - while ((packet = sendToServerAsyncQueue.poll()) != null) { + synchronized (sendToServerQueue) { + while ((packet = sendToServerQueue.poll()) != null) { sendToServer(packet); } } @@ -55,24 +55,24 @@ public class AsyncPacketSender { proxy.getOutHandler().sendToStream(message.toBytes()); } - public void sendToClientAsync(HPacket message) { - synchronized (sendToClientAsyncQueue) { - sendToClientAsyncQueue.add(message); + public void queueToClient(HPacket message) { + synchronized (sendToClientQueue) { + sendToClientQueue.add(message); } } - public void sendToServerAsync(HPacket message) { - synchronized (sendToServerAsyncQueue) { - sendToServerAsyncQueue.add(message); + public void queueToServer(HPacket message) { + synchronized (sendToServerQueue) { + sendToServerQueue.add(message); } } public void clear() { - synchronized (sendToClientAsyncQueue) { - sendToClientAsyncQueue.clear(); + synchronized (sendToClientQueue) { + sendToClientQueue.clear(); } - synchronized (sendToServerAsyncQueue) { - sendToServerAsyncQueue.clear(); + synchronized (sendToServerQueue) { + sendToServerQueue.clear(); } } } 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 5f26af8..951b9cc 100644 --- a/G-Earth/src/main/java/gearth/services/extensionhandler/ExtensionHandler.java +++ b/G-Earth/src/main/java/gearth/services/extensionhandler/ExtensionHandler.java @@ -191,10 +191,10 @@ public class ExtensionHandler { @Override public void sendMessage(HMessage.Direction direction, HPacket packet) { if (direction == HMessage.Direction.TOCLIENT) { - hConnection.sendToClientAsync(packet); + hConnection.sendToClient(packet); } else { - hConnection.sendToServerAsync(packet); + hConnection.sendToServer(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 91168fe..f162a3a 100644 --- a/G-Earth/src/main/java/gearth/ui/injection/InjectionController.java +++ b/G-Earth/src/main/java/gearth/ui/injection/InjectionController.java @@ -6,23 +6,18 @@ import gearth.protocol.HMessage; import gearth.protocol.connection.HState; import javafx.application.Platform; import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.input.MouseButton; -import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.text.Text; import gearth.protocol.HPacket; import gearth.ui.SubForm; -import sun.misc.Cache; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import java.util.function.Function; import java.util.stream.Collectors; public class InjectionController extends SubForm { @@ -190,7 +185,7 @@ public class InjectionController extends SubForm { public void sendToServer_clicked(ActionEvent actionEvent) { HPacket[] packets = parsePackets(inputPacket.getText()); for (HPacket packet : packets) { - getHConnection().sendToServerAsync(packet); + getHConnection().sendToServer(packet); writeToLog(Color.BLUE, "SS -> packet with id: " + packet.headerId()); } @@ -200,7 +195,7 @@ public class InjectionController extends SubForm { public void sendToClient_clicked(ActionEvent actionEvent) { HPacket[] packets = parsePackets(inputPacket.getText()); for (HPacket packet : packets) { - getHConnection().sendToClientAsync(packet); + getHConnection().sendToClient(packet); writeToLog(Color.RED, "CS -> packet with id: " + packet.headerId()); } diff --git a/G-Earth/src/main/java/gearth/ui/scheduler/SchedulerController.java b/G-Earth/src/main/java/gearth/ui/scheduler/SchedulerController.java index 8972996..2eef5a1 100644 --- a/G-Earth/src/main/java/gearth/ui/scheduler/SchedulerController.java +++ b/G-Earth/src/main/java/gearth/ui/scheduler/SchedulerController.java @@ -115,7 +115,6 @@ public class SchedulerController extends SubForm { scheduler.size(), false, new Interval(txt_delay.getText()), - new HPacket(txt_packet.getText()), txt_packet.getText(), rb_incoming.isSelected() ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER); @@ -123,7 +122,6 @@ public class SchedulerController extends SubForm { } else { - isBeingEdited.getPacketProperty().set(new HPacket(txt_packet.getText())); isBeingEdited.getPacketAsStringProperty().set(txt_packet.getText()); isBeingEdited.getDelayProperty().set(new Interval(txt_delay.getText())); isBeingEdited.getDestinationProperty().set(rb_incoming.isSelected() ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER);