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