This commit is contained in:
sirjonasxx 2021-01-03 02:44:05 +01:00
parent 4ae9cc7e58
commit eefd1bade5
2 changed files with 18 additions and 31 deletions

View File

@ -38,10 +38,8 @@ public class UnityCommunicator {
session.setMaxBinaryMessageBufferSize(1024 * 1024 * 10);
}
private int lastType = 2; // 0 = incoming, 1 = outgoing, 2 = expect new
@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)) {
return;
}
@ -49,15 +47,12 @@ public class UnityCommunicator {
if (revision == null) {
revision = new String(b, StandardCharsets.ISO_8859_1);
allowedSession = session.getId();
if (!isLast) {
System.out.println("this is bad");
}
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) {
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);
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);
lastType = isLast ? 2 : 1;
}
else {
proxyProvider.abort();

View File

@ -25,20 +25,15 @@ public class UnityPacketHandler extends PacketHandler {
@Override
public void sendToStream(byte[] buffer) {
synchronized (session) {
byte[] prefix = new byte[]{(direction == HMessage.Direction.TOCLIENT ? ((byte)0) : ((byte)1))};
byte[] combined = ByteArrayUtils.combineByteArrays(prefix, buffer);
session.getAsyncRemote().sendBinary(ByteBuffer.wrap(combined));
}
}
@Override
public void act(byte[] buffer) throws IOException {
HPacket[] packets = payloadBuffer.pushAndReceive(buffer);
for (HPacket hPacket : packets) {
HMessage hMessage = new HMessage(hPacket, direction, currentIndex);
HMessage hMessage = new HMessage(new HPacket(buffer), direction, currentIndex);
OnHMessageHandled afterExtensionIntercept = hMessage1 -> {
notifyListeners(2, hMessage1);
@ -55,4 +50,3 @@ public class UnityPacketHandler extends PacketHandler {
currentIndex++;
}
}
}