mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
remove fixed packetlength values
This commit is contained in:
parent
065504f6cd
commit
71a2a385c9
@ -185,6 +185,46 @@ public class HPacket implements StringifyAble {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public boolean structureEquals(String structure) {
|
||||
if (isCorrupted()) return false;
|
||||
|
||||
int indexbuffer = readIndex;
|
||||
readIndex = 6;
|
||||
|
||||
String[] split = structure.split(",");
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
|
||||
if (s.equals("s")) {
|
||||
if (readUshort(readIndex) + 2 + readIndex > getBytesLength()) return false;
|
||||
readString();
|
||||
}
|
||||
else if (s.equals("i")) {
|
||||
if (readIndex + 4 > getBytesLength()) return false;
|
||||
readInteger();
|
||||
}
|
||||
else if (s.equals("u")) {
|
||||
if (readIndex + 2 > getBytesLength()) return false;
|
||||
readUshort();
|
||||
}
|
||||
else if (s.equals("b")) {
|
||||
if (readIndex + 1 > getBytesLength()) return false;
|
||||
readBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = (isEOF() == 1);
|
||||
readIndex = indexbuffer;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int isEOF() {
|
||||
if (readIndex < getBytesLength()) return 0;
|
||||
if (readIndex == getBytesLength()) return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public byte[] toBytes() {
|
||||
return packetInBytes;
|
||||
}
|
||||
@ -800,34 +840,5 @@ public class HPacket implements StringifyAble {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// HPacket packet = new HPacket("{l}{u:500}{i:4}{s:heey}{b:false}");
|
||||
// System.out.println(packet);
|
||||
//
|
||||
// String stringified = packet.stringify();
|
||||
// System.out.println("stringified: " + stringified);
|
||||
// System.out.println(stringified.length());
|
||||
//
|
||||
//
|
||||
// HPacket packet1 = new HPacket(new byte[0]);
|
||||
// packet1.constructFromString(stringified);
|
||||
//
|
||||
// System.out.println(packet1);
|
||||
// System.out.println(packet.equals(packet1));
|
||||
|
||||
HPacket packet = new HPacket(555);
|
||||
for (int i = -128; i < 128; i++) {
|
||||
packet.appendByte((byte)i);
|
||||
}
|
||||
System.out.println(packet);
|
||||
|
||||
String stringified = packet.stringify();
|
||||
System.out.println(stringified.length());
|
||||
|
||||
|
||||
HPacket packet1 = new HPacket(new byte[0]);
|
||||
packet1.constructFromString(stringified);
|
||||
|
||||
System.out.println(packet1);
|
||||
System.out.println(packet.equals(packet1));
|
||||
}
|
||||
}
|
@ -104,15 +104,12 @@ public abstract class Handler {
|
||||
* @param message
|
||||
*/
|
||||
void notifyListeners(HMessage message) {
|
||||
for (TrafficListener listener : (List<TrafficListener>)listeners[0]) {
|
||||
listener.onCapture(message);
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int i = ((List<TrafficListener>)listeners[x]).size() - 1; i >= 0; i--) {
|
||||
((List<TrafficListener>)listeners[x]).get(i).onCapture(message);
|
||||
}
|
||||
for (TrafficListener listener : (List<TrafficListener>)listeners[1]) {
|
||||
listener.onCapture(message);
|
||||
}
|
||||
for (TrafficListener listener : (List<TrafficListener>)listeners[2]) {
|
||||
listener.onCapture(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendToStream(byte[] buffer) {
|
||||
|
@ -10,16 +10,22 @@ import java.util.List;
|
||||
|
||||
public class IncomingHandler extends Handler {
|
||||
|
||||
private volatile boolean onlyOnce = true;
|
||||
public IncomingHandler(OutputStream outputStream, Object[] listeners) {
|
||||
super(outputStream, listeners);
|
||||
|
||||
((List<TrafficListener>)listeners[0]).add(message -> {
|
||||
if (isDataStream && onlyOnce && (message.getPacket().length() == 261 || message.getPacket().length() == 517)) {
|
||||
onlyOnce = false;
|
||||
isEncryptedStream = message.getPacket().readBoolean(message.getPacket().length() + 3);
|
||||
TrafficListener listener = new TrafficListener() {
|
||||
@Override
|
||||
public void onCapture(HMessage message) {
|
||||
if (isDataStream && message.getPacket().structureEquals("s,b")) {
|
||||
((List<TrafficListener>)listeners[0]).remove(this);
|
||||
HPacket packet = message.getPacket();
|
||||
packet.readString();
|
||||
isEncryptedStream = packet.readBoolean();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
((List<TrafficListener>)listeners[0]).add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user