mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-26 18:30:52 +01:00
stuff
This commit is contained in:
parent
4ae9cc7e58
commit
eefd1bade5
@ -38,10 +38,8 @@ public class UnityCommunicator {
|
|||||||
session.setMaxBinaryMessageBufferSize(1024 * 1024 * 10);
|
session.setMaxBinaryMessageBufferSize(1024 * 1024 * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int lastType = 2; // 0 = incoming, 1 = outgoing, 2 = expect new
|
|
||||||
|
|
||||||
@OnMessage
|
@OnMessage
|
||||||
public void onMessage(byte[] b, boolean isLast, Session session) throws IOException {
|
public void onMessage(byte[] b, Session session) throws IOException {
|
||||||
if (allowedSession != null && !session.getId().equals(allowedSession)) {
|
if (allowedSession != null && !session.getId().equals(allowedSession)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -49,15 +47,12 @@ public class UnityCommunicator {
|
|||||||
if (revision == null) {
|
if (revision == null) {
|
||||||
revision = new String(b, StandardCharsets.ISO_8859_1);
|
revision = new String(b, StandardCharsets.ISO_8859_1);
|
||||||
allowedSession = session.getId();
|
allowedSession = session.getId();
|
||||||
if (!isLast) {
|
|
||||||
System.out.println("this is bad");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
byte[] packet = lastType == 2 ? Arrays.copyOfRange(b, 1, b.length) : b;
|
byte[] packet = Arrays.copyOfRange(b, 1, b.length);
|
||||||
|
|
||||||
if (hProxy == null && b[0] == 1) {
|
if (hProxy == null && b[0] == 1) {
|
||||||
HPacket maybe = new HPacket(packet);
|
HPacket maybe = new HPacket(packet);
|
||||||
@ -74,13 +69,11 @@ public class UnityCommunicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (hProxy != null && ((lastType == 2 && b[0] == 0) || lastType == 0)) {
|
if (hProxy != null && b[0] == 0) {
|
||||||
hProxy.getInHandler().act(packet);
|
hProxy.getInHandler().act(packet);
|
||||||
lastType = isLast ? 2 : 0;
|
|
||||||
}
|
}
|
||||||
else if (hProxy != null && ((lastType == 2 && b[0] == 1) || lastType == 1)) {
|
else if (hProxy != null && b[0] == 1) {
|
||||||
hProxy.getOutHandler().act(packet);
|
hProxy.getOutHandler().act(packet);
|
||||||
lastType = isLast ? 2 : 1;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
proxyProvider.abort();
|
proxyProvider.abort();
|
||||||
|
@ -25,34 +25,28 @@ public class UnityPacketHandler extends PacketHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendToStream(byte[] buffer) {
|
public void sendToStream(byte[] buffer) {
|
||||||
synchronized (session) {
|
byte[] prefix = new byte[]{(direction == HMessage.Direction.TOCLIENT ? ((byte)0) : ((byte)1))};
|
||||||
byte[] prefix = new byte[]{(direction == HMessage.Direction.TOCLIENT ? ((byte)0) : ((byte)1))};
|
byte[] combined = ByteArrayUtils.combineByteArrays(prefix, buffer);
|
||||||
byte[] combined = ByteArrayUtils.combineByteArrays(prefix, buffer);
|
|
||||||
|
|
||||||
session.getAsyncRemote().sendBinary(ByteBuffer.wrap(combined));
|
session.getAsyncRemote().sendBinary(ByteBuffer.wrap(combined));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void act(byte[] buffer) throws IOException {
|
public void act(byte[] buffer) throws IOException {
|
||||||
HPacket[] packets = payloadBuffer.pushAndReceive(buffer);
|
HMessage hMessage = new HMessage(new HPacket(buffer), direction, currentIndex);
|
||||||
|
|
||||||
for (HPacket hPacket : packets) {
|
OnHMessageHandled afterExtensionIntercept = hMessage1 -> {
|
||||||
HMessage hMessage = new HMessage(hPacket, direction, currentIndex);
|
notifyListeners(2, hMessage1);
|
||||||
|
|
||||||
OnHMessageHandled afterExtensionIntercept = hMessage1 -> {
|
if (!hMessage1.isBlocked()) {
|
||||||
notifyListeners(2, hMessage1);
|
sendToStream(hMessage1.getPacket().toBytes());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!hMessage1.isBlocked()) {
|
notifyListeners(0, hMessage);
|
||||||
sendToStream(hMessage1.getPacket().toBytes());
|
notifyListeners(1, hMessage);
|
||||||
}
|
extensionHandler.handle(hMessage, afterExtensionIntercept);
|
||||||
};
|
|
||||||
|
|
||||||
notifyListeners(0, hMessage);
|
currentIndex++;
|
||||||
notifyListeners(1, hMessage);
|
|
||||||
extensionHandler.handle(hMessage, afterExtensionIntercept);
|
|
||||||
|
|
||||||
currentIndex++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user