mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
unity packethandler
This commit is contained in:
parent
5f262cde16
commit
1ddfbbe420
@ -13,6 +13,7 @@ import gearth.protocol.packethandler.unity.UnityPacketHandler;
|
|||||||
import javax.websocket.*;
|
import javax.websocket.*;
|
||||||
import javax.websocket.server.ServerEndpoint;
|
import javax.websocket.server.ServerEndpoint;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ServerEndpoint(value = "/packethandler")
|
@ServerEndpoint(value = "/packethandler")
|
||||||
@ -23,7 +24,9 @@ public class UnityCommunicator {
|
|||||||
private final HConnection hConnection;
|
private final HConnection hConnection;
|
||||||
private final ProxyProvider proxyProvider;
|
private final ProxyProvider proxyProvider;
|
||||||
|
|
||||||
HProxy hProxy = null;
|
private HProxy hProxy = null;
|
||||||
|
private String allowedSession = null;
|
||||||
|
private String revision = null;
|
||||||
|
|
||||||
public UnityCommunicator(HProxySetter proxySetter, HStateSetter stateSetter, HConnection hConnection, ProxyProvider proxyProvider) {
|
public UnityCommunicator(HProxySetter proxySetter, HStateSetter stateSetter, HConnection hConnection, ProxyProvider proxyProvider) {
|
||||||
this.proxySetter = proxySetter;
|
this.proxySetter = proxySetter;
|
||||||
@ -40,6 +43,16 @@ public class UnityCommunicator {
|
|||||||
|
|
||||||
@OnMessage
|
@OnMessage
|
||||||
public void onMessage(byte[] b, Session session) throws IOException {
|
public void onMessage(byte[] b, Session session) throws IOException {
|
||||||
|
if (allowedSession != null && !session.getId().equals(allowedSession)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (revision == null) {
|
||||||
|
revision = new String(b, StandardCharsets.ISO_8859_1);
|
||||||
|
allowedSession = session.getId();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
byte[] packet = Arrays.copyOfRange(b, 1, b.length);
|
byte[] packet = Arrays.copyOfRange(b, 1, b.length);
|
||||||
|
|
||||||
if (hProxy == null && b[0] == 1) {
|
if (hProxy == null && b[0] == 1) {
|
||||||
@ -50,7 +63,7 @@ public class UnityCommunicator {
|
|||||||
hProxy.verifyProxy(
|
hProxy.verifyProxy(
|
||||||
new UnityPacketHandler(hConnection.getExtensionHandler(), hConnection.getTrafficObservables(), session, HMessage.Direction.TOCLIENT),
|
new UnityPacketHandler(hConnection.getExtensionHandler(), hConnection.getTrafficObservables(), session, HMessage.Direction.TOCLIENT),
|
||||||
new UnityPacketHandler(hConnection.getExtensionHandler(), hConnection.getTrafficObservables(), session, HMessage.Direction.TOSERVER),
|
new UnityPacketHandler(hConnection.getExtensionHandler(), hConnection.getTrafficObservables(), session, HMessage.Direction.TOSERVER),
|
||||||
hotelVersion
|
revision
|
||||||
);
|
);
|
||||||
proxySetter.setProxy(hProxy);
|
proxySetter.setProxy(hProxy);
|
||||||
stateSetter.setState(HState.CONNECTED);
|
stateSetter.setState(HState.CONNECTED);
|
||||||
|
@ -46,7 +46,10 @@ public class UnityPacketHandler extends PacketHandler {
|
|||||||
|
|
||||||
OnHMessageHandled afterExtensionIntercept = hMessage1 -> {
|
OnHMessageHandled afterExtensionIntercept = hMessage1 -> {
|
||||||
notifyListeners(2, hMessage1);
|
notifyListeners(2, hMessage1);
|
||||||
sendToStream(hMessage1.getPacket().toBytes());
|
|
||||||
|
if (!hMessage1.isBlocked()) {
|
||||||
|
sendToStream(hMessage1.getPacket().toBytes());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
notifyListeners(0, hMessage);
|
notifyListeners(0, hMessage);
|
||||||
|
Loading…
Reference in New Issue
Block a user