potential bugfix

This commit is contained in:
sirjonasxx 2021-10-26 13:14:09 +02:00
parent 21583072df
commit c2fcee21b9
6 changed files with 28 additions and 93 deletions

View File

@ -140,6 +140,7 @@ public class HConnection {
public boolean sendToClient(HPacket packet) {
HProxy proxy = this.proxy;
if (proxy == null) return false;
if (!packet.isPacketComplete()) {
@ -149,10 +150,10 @@ public class HConnection {
if (!packet.isPacketComplete() || !packet.canSendToClient()) return false;
}
proxy.getPacketSenderQueue().queueToClient(packet);
return true;
return proxy.sendToClient(packet);
}
public boolean sendToServer(HPacket packet) {
HProxy proxy = this.proxy;
if (proxy == null) return false;
if (!packet.isPacketComplete()) {
@ -162,8 +163,7 @@ public class HConnection {
if (!packet.isPacketComplete() || !packet.canSendToServer()) return false;
}
proxy.getPacketSenderQueue().queueToServer(packet);
return true;
return proxy.sendToServer(packet);
}
public String getClientHost() {

View File

@ -1,5 +1,6 @@
package gearth.protocol.connection;
import gearth.protocol.HPacket;
import gearth.services.packet_info.PacketInfoManager;
import gearth.protocol.packethandler.PacketHandler;
@ -25,8 +26,6 @@ public class HProxy {
private volatile String clientIdentifier = "";
private volatile PacketInfoManager packetInfoManager = 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;
this.input_domain = input_domain;
@ -46,7 +45,20 @@ public class HProxy {
this.hotelVersion = hotelVersion;
this.clientIdentifier = clientIdentifier;
this.packetInfoManager = PacketInfoManager.fromHotelVersion(hotelVersion, hClient);
this.packetSenderQueue = new PacketSenderQueue(this);
}
public boolean sendToServer(HPacket packet) {
if (outHandler != null) {
return outHandler.sendToStream(packet.toBytes());
}
return false;
}
public boolean sendToClient(HPacket packet) {
if (inHandler != null) {
return inHandler.sendToStream(packet.toBytes());
}
return false;
}
public String getClientIdentifier() {
@ -89,10 +101,6 @@ public class HProxy {
return hotelVersion;
}
public PacketSenderQueue getPacketSenderQueue() {
return packetSenderQueue;
}
public HClient gethClient() {
return hClient;
}

View File

@ -1,78 +0,0 @@
package gearth.protocol.connection;
import gearth.protocol.HPacket;
import java.util.LinkedList;
import java.util.Queue;
public class PacketSenderQueue {
private final HProxy proxy;
private final Queue<HPacket> sendToClientQueue = new LinkedList<>();
private final Queue<HPacket> sendToServerQueue = new LinkedList<>();
PacketSenderQueue(HProxy proxy) {
this.proxy = proxy;
new Thread(() -> {
while (true) {
HPacket packet;
synchronized (sendToClientQueue) {
while ((packet = sendToClientQueue.poll()) != null) {
sendToClient(packet);
}
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(() -> {
while (true) {
HPacket packet;
synchronized (sendToServerQueue) {
while ((packet = sendToServerQueue.poll()) != null) {
sendToServer(packet);
}
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
private void sendToClient(HPacket message) {
proxy.getInHandler().sendToStream(message.toBytes());
}
private void sendToServer(HPacket message) {
proxy.getOutHandler().sendToStream(message.toBytes());
}
public void queueToClient(HPacket message) {
synchronized (sendToClientQueue) {
sendToClientQueue.add(message);
}
}
public void queueToServer(HPacket message) {
synchronized (sendToServerQueue) {
sendToServerQueue.add(message);
}
}
public void clear() {
synchronized (sendToClientQueue) {
sendToClientQueue.clear();
}
synchronized (sendToServerQueue) {
sendToServerQueue.clear();
}
}
}

View File

@ -20,7 +20,7 @@ public abstract class PacketHandler {
}
public abstract void sendToStream(byte[] buffer);
public abstract boolean sendToStream(byte[] buffer);
public abstract void act(byte[] buffer) throws IOException;

View File

@ -51,7 +51,9 @@ public abstract class FlashPacketHandler extends PacketHandler {
public void act(byte[] buffer) throws IOException {
if (!isDataStream) {
out.write(buffer);
synchronized (sendLock) {
out.write(buffer);
}
return;
}
@ -113,7 +115,7 @@ public abstract class FlashPacketHandler extends PacketHandler {
isTempBlocked = false;
}
public void sendToStream(byte[] buffer) {
public boolean sendToStream(byte[] buffer) {
synchronized (sendLock) {
try {
out.write(
@ -121,8 +123,10 @@ public abstract class FlashPacketHandler extends PacketHandler {
? buffer
: encryptcipher.rc4(buffer)
);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}

View File

@ -23,11 +23,12 @@ public class UnityPacketHandler extends PacketHandler {
}
@Override
public void sendToStream(byte[] buffer) {
public boolean sendToStream(byte[] buffer) {
byte[] prefix = new byte[]{(direction == HMessage.Direction.TOCLIENT ? ((byte)0) : ((byte)1))};
byte[] combined = ByteArrayUtils.combineByteArrays(prefix, buffer);
session.getAsyncRemote().sendBinary(ByteBuffer.wrap(combined));
return true;
}
@Override