mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
ok extension support works
This commit is contained in:
parent
83d3de6c6f
commit
2c80e2f2c9
@ -70,6 +70,7 @@ public abstract class Extension {
|
||||
byte[] headerandbody = new byte[length + 4];
|
||||
|
||||
int amountRead = 0;
|
||||
|
||||
while (amountRead < length) {
|
||||
amountRead += dIn.read(headerandbody, 4 + amountRead, Math.min(dIn.available(), length - amountRead));
|
||||
}
|
||||
@ -118,10 +119,6 @@ public abstract class Extension {
|
||||
HMessage habboMessage = new HMessage(stringifiedMessage);
|
||||
HPacket habboPacket = habboMessage.getPacket();
|
||||
|
||||
lastwrapper = packet;
|
||||
lastM = habboMessage;
|
||||
last = habboPacket;
|
||||
|
||||
Map<Integer, List<MessageListener>> listeners =
|
||||
habboMessage.getDestination() == HMessage.Side.TOCLIENT ?
|
||||
incomingMessageListeners :
|
||||
@ -130,12 +127,14 @@ public abstract class Extension {
|
||||
if (listeners.containsKey(-1)) { // registered on all packets
|
||||
for (int i = listeners.get(-1).size() - 1; i >= 0; i--) {
|
||||
listeners.get(-1).get(i).act(habboMessage);
|
||||
habboMessage.getPacket().setReadIndex(6);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
habboMessage.getPacket().setReadIndex(6);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,6 +142,7 @@ public abstract class Extension {
|
||||
response.appendLongString(habboMessage.stringify());
|
||||
|
||||
writeToStream(response.toBytes());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ public abstract class Extension {
|
||||
}
|
||||
|
||||
private void writeToStream(byte[] bytes) throws IOException {
|
||||
synchronized (out) {
|
||||
synchronized (this) {
|
||||
out.write(bytes);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package main.extensions;
|
||||
|
||||
import main.protocol.HMessage;
|
||||
import main.protocol.HPacket;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 24/06/18.
|
||||
*/
|
||||
@ -16,6 +19,22 @@ public class SimpleTestExtension extends Extension {
|
||||
@Override
|
||||
protected void init() {
|
||||
System.out.println("init");
|
||||
|
||||
intercept(HMessage.Side.TOSERVER, 1926, this::onSendMessage);
|
||||
}
|
||||
|
||||
private void onSendMessage(HMessage message) {
|
||||
HPacket packet = message.getPacket();
|
||||
|
||||
String watchasaid = packet.readString();
|
||||
|
||||
System.out.println("you said: " + watchasaid);
|
||||
|
||||
if (watchasaid.equals("blocked")) {
|
||||
message.setBlocked(true);
|
||||
}
|
||||
|
||||
packet.replaceString(6, "@cyan@" + watchasaid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +57,7 @@ public class HMessage implements StringifyAble {
|
||||
|
||||
@Override
|
||||
public void constructFromString(String str) {
|
||||
String[] parts = str.split("\t");
|
||||
String[] parts = str.split("\t", 4);
|
||||
this.isBlocked = parts[0].equals("1");
|
||||
this.index = Integer.parseInt(parts[1]);
|
||||
this.side = parts[2].equals("TOCLIENT") ? Side.TOCLIENT : Side.TOSERVER;
|
||||
|
@ -780,14 +780,15 @@ public class HPacket implements StringifyAble {
|
||||
|
||||
@Override
|
||||
public String stringify() {
|
||||
String st = (isEdited ? "1" : "0") + this.toString();
|
||||
String st = null;
|
||||
st = (isEdited ? "1" : "0") + new String(packetInBytes, StandardCharsets.ISO_8859_1);
|
||||
return st;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void constructFromString(String str) {
|
||||
this.isEdited = str.charAt(0) == '1';
|
||||
packetInBytes = fromStringToBytes(str.substring(1));
|
||||
packetInBytes = str.substring(1).getBytes(StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -797,4 +798,36 @@ public class HPacket implements StringifyAble {
|
||||
HPacket packet2 = (HPacket) object;
|
||||
return Arrays.equals(packetInBytes, packet2.packetInBytes) && (isEdited == packet2.isEdited);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
@ -148,14 +148,14 @@ public class Extensions extends SubForm {
|
||||
@Override
|
||||
public void act(HPacket packet) {
|
||||
if (packet.headerId() == INCOMING_MESSAGES_IDS.MANIPULATEDPACKET) {
|
||||
String stringifiedresponse = packet.readLongString();
|
||||
String stringifiedresponse = packet.readLongString(6);
|
||||
HMessage responseMessage = new HMessage(stringifiedresponse);
|
||||
if (responseMessage.getDestination() == message.getDestination() && responseMessage.getIndex() == message.getIndex()) {
|
||||
if (!message.equals(responseMessage)) {
|
||||
message.constructFromString(stringifiedresponse);
|
||||
if (responseMessage.isBlocked()) {
|
||||
isblock[0] = true;
|
||||
}
|
||||
}
|
||||
if (responseMessage.isBlocked()) {
|
||||
isblock[0] = true;
|
||||
}
|
||||
synchronized (collection) {
|
||||
collection.remove(extension);
|
||||
|
@ -30,7 +30,7 @@ public class GEarthExtension {
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
synchronized (connection.getOutputStream()) {
|
||||
synchronized (connection) {
|
||||
connection.getOutputStream().write((new HPacket(Extensions.OUTGOING_MESSAGES_IDS.INFOREQUEST)).toBytes());
|
||||
}
|
||||
|
||||
@ -96,6 +96,7 @@ public class GEarthExtension {
|
||||
|
||||
for (int i = receiveMessageListeners.size() - 1; i >= 0; i--) {
|
||||
receiveMessageListeners.get(i).act(packet);
|
||||
packet.setReadIndex(6);
|
||||
}
|
||||
|
||||
}
|
||||
@ -150,7 +151,7 @@ public class GEarthExtension {
|
||||
|
||||
public boolean sendMessage(HPacket message) {
|
||||
try {
|
||||
synchronized (connection.getOutputStream()) {
|
||||
synchronized (this) {
|
||||
connection.getOutputStream().write(message.toBytes());
|
||||
}
|
||||
return true;
|
||||
|
@ -9,11 +9,19 @@ import java.net.Socket;
|
||||
*/
|
||||
public class GEarthExtensionsRegistrer {
|
||||
|
||||
final ServerSocket serverSocket;
|
||||
private ServerSocket serverSocket;
|
||||
|
||||
GEarthExtensionsRegistrer(ExtensionRegisterObserver observer) throws IOException {
|
||||
|
||||
serverSocket = new ServerSocket(0);
|
||||
// serverSocket = new ServerSocket(0);
|
||||
int port = 9092;
|
||||
boolean serverSetup = false;
|
||||
while (!serverSetup) {
|
||||
serverSetup = createServer(port);
|
||||
port++;
|
||||
}
|
||||
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
while (!serverSocket.isClosed()) {
|
||||
@ -24,6 +32,15 @@ public class GEarthExtensionsRegistrer {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private boolean createServer(int port) {
|
||||
try {
|
||||
serverSocket = new ServerSocket(port);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return serverSocket.getLocalPort();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user