mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 00:40:51 +01:00
potential bugfix
This commit is contained in:
parent
21583072df
commit
c2fcee21b9
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user