mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
fixes but still dont work
This commit is contained in:
parent
2eef54600a
commit
83d3de6c6f
@ -51,6 +51,11 @@ public abstract class Extension {
|
||||
}
|
||||
}
|
||||
|
||||
HPacket lastwrapper = null;
|
||||
HMessage lastM = null;
|
||||
HPacket last = null;
|
||||
|
||||
|
||||
Socket gEarthExtensionServer = null;
|
||||
try {
|
||||
gEarthExtensionServer = new Socket("localhost", port);
|
||||
@ -63,9 +68,11 @@ public abstract class Extension {
|
||||
|
||||
int length = dIn.readInt();
|
||||
byte[] headerandbody = new byte[length + 4];
|
||||
int amountRead = dIn.read(headerandbody, 4, length);
|
||||
|
||||
if (amountRead != length) break;
|
||||
int amountRead = 0;
|
||||
while (amountRead < length) {
|
||||
amountRead += dIn.read(headerandbody, 4 + amountRead, Math.min(dIn.available(), length - amountRead));
|
||||
}
|
||||
|
||||
HPacket packet = new HPacket(headerandbody);
|
||||
packet.fixLength();
|
||||
@ -107,13 +114,13 @@ public abstract class Extension {
|
||||
onDoubleClick();
|
||||
}
|
||||
else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.PACKETINTERCEPT) {
|
||||
String stringifiedMessage = packet.readString();
|
||||
String stringifiedMessage = packet.readLongString();
|
||||
HMessage habboMessage = new HMessage(stringifiedMessage);
|
||||
HPacket habboPacket = habboMessage.getPacket();
|
||||
//
|
||||
// System.out.println("----------");
|
||||
// System.out.println(stringifiedMessage);
|
||||
// System.out.println(habboPacket);
|
||||
|
||||
lastwrapper = packet;
|
||||
lastM = habboMessage;
|
||||
last = habboPacket;
|
||||
|
||||
Map<Integer, List<MessageListener>> listeners =
|
||||
habboMessage.getDestination() == HMessage.Side.TOCLIENT ?
|
||||
@ -125,6 +132,7 @@ public abstract class Extension {
|
||||
listeners.get(-1).get(i).act(habboMessage);
|
||||
}
|
||||
}
|
||||
|
||||
if (listeners.containsKey(habboPacket.headerId())) {
|
||||
for (int i = listeners.get(habboPacket.headerId()).size() - 1; i >= 0; i--) {
|
||||
listeners.get(habboPacket.headerId()).get(i).act(habboMessage);
|
||||
@ -132,16 +140,15 @@ public abstract class Extension {
|
||||
}
|
||||
|
||||
HPacket response = new HPacket(Extensions.INCOMING_MESSAGES_IDS.MANIPULATEDPACKET);
|
||||
response.appendString(habboMessage.stringify());
|
||||
response.appendLongString(habboMessage.stringify());
|
||||
|
||||
writeToStream(response.toBytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
System.out.println("ERROR");
|
||||
} catch (IOException | ArrayIndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
if (gEarthExtensionServer != null && !gEarthExtensionServer.isClosed()) {
|
||||
@ -157,7 +164,6 @@ public abstract class Extension {
|
||||
private void writeToStream(byte[] bytes) throws IOException {
|
||||
synchronized (out) {
|
||||
out.write(bytes);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,27 +280,37 @@ public class HPacket implements StringifyAble {
|
||||
}
|
||||
|
||||
public String readString() {
|
||||
int length = readUshort();
|
||||
byte[] x = new byte[length];
|
||||
for (int i = 0; i < x.length; i++) x[i] = readByte();
|
||||
String r = readString(readIndex);
|
||||
readIndex += (2 + r.length());
|
||||
return r;
|
||||
}
|
||||
public String readString(int index) {
|
||||
int length = readUshort(index);
|
||||
index+=2;
|
||||
|
||||
return readString(index, length);
|
||||
}
|
||||
|
||||
private String readString(int index, int length) {
|
||||
byte[] x = new byte[length];
|
||||
for (int i = 0; i < x.length; i++) { x[i] = readByte(index); index++; }
|
||||
try {
|
||||
return new String(x, "ISO-8859-1");
|
||||
} catch (UnsupportedEncodingException e) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
public String readString(int index) {
|
||||
int length = readUshort(index);
|
||||
index+=2;
|
||||
byte[] x = new byte[length];
|
||||
for (int i = 0; i < x.length; i++) { x[i] = readByte(index); index++; }
|
||||
|
||||
try {
|
||||
return new String(x, "ISO-8859-1");
|
||||
} catch (UnsupportedEncodingException e) { }
|
||||
public String readLongString() {
|
||||
String r = readLongString(readIndex);
|
||||
readIndex += (4 + r.length());
|
||||
return r;
|
||||
}
|
||||
public String readLongString(int index) {
|
||||
int length = readInteger(index);
|
||||
index += 4;
|
||||
|
||||
return null;
|
||||
return readString(index, length);
|
||||
}
|
||||
|
||||
public boolean readBoolean() {
|
||||
@ -466,6 +476,12 @@ public class HPacket implements StringifyAble {
|
||||
appendBytes(s.getBytes(StandardCharsets.ISO_8859_1));
|
||||
return this;
|
||||
}
|
||||
public HPacket appendLongString(String s) {
|
||||
isEdited = true;
|
||||
appendInt(s.length());
|
||||
appendBytes(s.getBytes(StandardCharsets.ISO_8859_1));
|
||||
return this;
|
||||
}
|
||||
|
||||
public HPacket removeFrom(int index) {
|
||||
return removeRange(index, packetInBytes.length - index);
|
||||
|
@ -20,7 +20,6 @@ public class IncomingHandler extends Handler {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(buffer);
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -38,7 +37,6 @@ public class IncomingHandler extends Handler {
|
||||
|
||||
if (!hMessage.isBlocked()) {
|
||||
out.write(hMessage.getPacket().toBytes());
|
||||
out.flush();
|
||||
}
|
||||
currentIndex++;
|
||||
}
|
||||
|
@ -64,7 +64,6 @@ public class OutgoingHandler extends Handler {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(servercipher.rc4(buffer));
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -104,7 +103,6 @@ public class OutgoingHandler extends Handler {
|
||||
currentIndex < encryptOffset ? hMessage.getPacket().toBytes() :
|
||||
servercipher.rc4(hMessage.getPacket().toBytes())
|
||||
);
|
||||
out.flush();
|
||||
}
|
||||
currentIndex ++;
|
||||
}
|
||||
|
@ -139,16 +139,16 @@ public class Extensions extends SubForm {
|
||||
|
||||
String stringified = message.stringify();
|
||||
HPacket manipulatePacketRequest = new HPacket(OUTGOING_MESSAGES_IDS.PACKETINTERCEPT);
|
||||
manipulatePacketRequest.appendString(stringified);
|
||||
manipulatePacketRequest.appendLongString(stringified);
|
||||
|
||||
boolean[] isblock = new boolean[1];
|
||||
|
||||
for (GEarthExtension extension : gEarthExtensions) {
|
||||
for (GEarthExtension extension : collection) {
|
||||
GEarthExtension.ReceiveMessageListener respondCallback = new GEarthExtension.ReceiveMessageListener() {
|
||||
@Override
|
||||
public void act(HPacket packet) {
|
||||
if (packet.headerId() == INCOMING_MESSAGES_IDS.MANIPULATEDPACKET) {
|
||||
String stringifiedresponse = packet.readString();
|
||||
String stringifiedresponse = packet.readLongString();
|
||||
HMessage responseMessage = new HMessage(stringifiedresponse);
|
||||
if (responseMessage.getDestination() == message.getDestination() && responseMessage.getIndex() == message.getIndex()) {
|
||||
if (!message.equals(responseMessage)) {
|
||||
@ -157,7 +157,10 @@ public class Extensions extends SubForm {
|
||||
isblock[0] = true;
|
||||
}
|
||||
}
|
||||
synchronized (collection) {
|
||||
collection.remove(extension);
|
||||
}
|
||||
|
||||
extension.removeOnReceiveMessageListener(this);
|
||||
}
|
||||
}
|
||||
@ -171,6 +174,8 @@ public class Extensions extends SubForm {
|
||||
//block untill all extensions have responded
|
||||
List<GEarthExtension> willdelete = new ArrayList<>();
|
||||
while (!collection.isEmpty()) {
|
||||
|
||||
synchronized (collection) {
|
||||
for (GEarthExtension extension : collection) {
|
||||
if (!gEarthExtensions.contains(extension)) willdelete.add(extension);
|
||||
}
|
||||
@ -178,6 +183,7 @@ public class Extensions extends SubForm {
|
||||
collection.remove(willdelete.get(i));
|
||||
willdelete.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
try {Thread.sleep(1);} catch (InterruptedException e) {e.printStackTrace();}
|
||||
}
|
||||
|
@ -5,9 +5,11 @@ import main.protocol.HPacket;
|
||||
import main.protocol.packethandler.PayloadBuffer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -28,8 +30,9 @@ public class GEarthExtension {
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
synchronized (connection.getOutputStream()) {
|
||||
connection.getOutputStream().write((new HPacket(Extensions.OUTGOING_MESSAGES_IDS.INFOREQUEST)).toBytes());
|
||||
connection.getOutputStream().flush();
|
||||
}
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
DataInputStream dIn = new DataInputStream(inputStream);
|
||||
@ -38,9 +41,12 @@ public class GEarthExtension {
|
||||
|
||||
int length = dIn.readInt();
|
||||
byte[] headerandbody = new byte[length + 4];
|
||||
int amountRead = dIn.read(headerandbody, 4, length);
|
||||
|
||||
if (amountRead != length) break;
|
||||
int amountRead = 0;
|
||||
while (amountRead < length) {
|
||||
amountRead += dIn.read(headerandbody, 4 + amountRead, Math.min(dIn.available(), length - amountRead));
|
||||
}
|
||||
|
||||
HPacket packet = new HPacket(headerandbody);
|
||||
packet.fixLength();
|
||||
|
||||
@ -79,9 +85,12 @@ public class GEarthExtension {
|
||||
while (!connection.isClosed()) {
|
||||
int length = dIn.readInt();
|
||||
byte[] headerandbody = new byte[length + 4];
|
||||
int amountRead = dIn.read(headerandbody, 4, length);
|
||||
|
||||
if (amountRead != length) break;
|
||||
int amountRead = 0;
|
||||
while (amountRead < length) {
|
||||
amountRead += dIn.read(headerandbody, 4 + amountRead, Math.min(dIn.available(), length - amountRead));
|
||||
}
|
||||
|
||||
HPacket packet = new HPacket(headerandbody);
|
||||
packet.fixLength();
|
||||
|
||||
@ -90,16 +99,16 @@ public class GEarthExtension {
|
||||
}
|
||||
|
||||
}
|
||||
onDisconnectedCallback.act(selff);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// An extension disconnected, which is OK
|
||||
} finally {
|
||||
onDisconnectedCallback.act(selff);
|
||||
if (!connection.isClosed()) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -141,8 +150,9 @@ public class GEarthExtension {
|
||||
|
||||
public boolean sendMessage(HPacket message) {
|
||||
try {
|
||||
synchronized (connection.getOutputStream()) {
|
||||
connection.getOutputStream().write(message.toBytes());
|
||||
connection.getOutputStream().flush();
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user