mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
Expose packet<->string functionality to (network) extension interface
preparation for python extensions
This commit is contained in:
parent
4b54af927d
commit
1d1831cc94
@ -212,6 +212,27 @@ public class ExtensionHandler {
|
|||||||
protected void manipulatedPacket(HMessage hMessage) {
|
protected void manipulatedPacket(HMessage hMessage) {
|
||||||
onExtensionRespond(extension, hMessage);
|
onExtensionRespond(extension, hMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void packetToStringRequest(HPacket packet) {
|
||||||
|
String s = "";
|
||||||
|
String expression = "s";
|
||||||
|
try {
|
||||||
|
s = packet.toString();
|
||||||
|
if (packet.length() > 3000) {
|
||||||
|
expression = packet.toExpression();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
extension.packetToStringResponse(s, expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void stringToPacketRequest(String string) {
|
||||||
|
HPacket packet = new HPacket(string);
|
||||||
|
extension.stringToPacketResponse(packet);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extension.getExtensionObservable().addListener(listener);
|
extension.getExtensionObservable().addListener(listener);
|
||||||
|
@ -12,4 +12,7 @@ public abstract class ExtensionListener {
|
|||||||
protected void log(String text) {}
|
protected void log(String text) {}
|
||||||
protected void hasClosed() {}
|
protected void hasClosed() {}
|
||||||
|
|
||||||
|
protected void packetToStringRequest(HPacket packet) {}
|
||||||
|
protected void stringToPacketRequest(String string) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import gearth.services.extensionhandler.extensions.listeners.OmRemoveClickListen
|
|||||||
import gearth.services.extensionhandler.extensions.listeners.OnClickListener;
|
import gearth.services.extensionhandler.extensions.listeners.OnClickListener;
|
||||||
import gearth.services.extensionhandler.extensions.listeners.OnDeleteListener;
|
import gearth.services.extensionhandler.extensions.listeners.OnDeleteListener;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public abstract class GEarthExtension {
|
public abstract class GEarthExtension {
|
||||||
|
|
||||||
|
|
||||||
@ -40,6 +42,8 @@ public abstract class GEarthExtension {
|
|||||||
public abstract void connectionEnd();
|
public abstract void connectionEnd();
|
||||||
public abstract void init();
|
public abstract void init();
|
||||||
public abstract void close();
|
public abstract void close();
|
||||||
|
public abstract void packetToStringResponse(String string, String expression);
|
||||||
|
public abstract void stringToPacketResponse(HPacket packet);
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@ -78,6 +82,19 @@ public abstract class GEarthExtension {
|
|||||||
protected void hasClosed() {
|
protected void hasClosed() {
|
||||||
extensionObservable.fireEvent(ExtensionListener::hasClosed);
|
extensionObservable.fireEvent(ExtensionListener::hasClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void packetToStringRequest(HPacket packet) {
|
||||||
|
int orgIndex = packet.getReadIndex();
|
||||||
|
extensionObservable.fireEvent(listener -> {
|
||||||
|
packet.setReadIndex(6);
|
||||||
|
listener.packetToStringRequest(packet);
|
||||||
|
});
|
||||||
|
packet.setReadIndex(orgIndex);
|
||||||
|
}
|
||||||
|
protected void stringToPacketRequest(String string) {
|
||||||
|
extensionObservable.fireEvent(l -> l.stringToPacketRequest(string));
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,6 +88,14 @@ public class NetworkExtension extends GEarthExtension {
|
|||||||
else if (message.headerId() == NetworkExtensionInfo.INCOMING_MESSAGES_IDS.EXTENSIONCONSOLELOG) {
|
else if (message.headerId() == NetworkExtensionInfo.INCOMING_MESSAGES_IDS.EXTENSIONCONSOLELOG) {
|
||||||
log(message.readString());
|
log(message.readString());
|
||||||
}
|
}
|
||||||
|
else if (message.headerId() == NetworkExtensionInfo.INCOMING_MESSAGES_IDS.PACKETTOSTRING_REQUEST) {
|
||||||
|
HPacket p = new HPacket(new byte[0]);
|
||||||
|
p.constructFromString(message.readLongString());
|
||||||
|
packetToStringRequest(p);
|
||||||
|
}
|
||||||
|
else if (message.headerId() == NetworkExtensionInfo.INCOMING_MESSAGES_IDS.STRINGTOPACKET_REQUEST) {
|
||||||
|
stringToPacketRequest(message.readLongString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,4 +219,19 @@ public class NetworkExtension extends GEarthExtension {
|
|||||||
connection.close();
|
connection.close();
|
||||||
} catch (IOException ignored) { }
|
} catch (IOException ignored) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void packetToStringResponse(String string, String expression) {
|
||||||
|
HPacket packet = new HPacket(NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.PACKETTOSTRING_RESPONSE);
|
||||||
|
packet.appendLongString(string);
|
||||||
|
packet.appendLongString(expression);
|
||||||
|
sendMessage(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stringToPacketResponse(HPacket packetFromString) {
|
||||||
|
HPacket packet = new HPacket(NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.STRINGTOPACKET_RESPONSE);
|
||||||
|
packet.appendLongString(packet.stringify());
|
||||||
|
sendMessage(packet);
|
||||||
|
}
|
||||||
}
|
}
|
@ -87,6 +87,9 @@ public class NetworkExtensionInfo {
|
|||||||
public static final int CONNECTIONSTART = 5;
|
public static final int CONNECTIONSTART = 5;
|
||||||
public static final int CONNECTIONEND = 6;
|
public static final int CONNECTIONEND = 6;
|
||||||
public static final int INIT = 7;
|
public static final int INIT = 7;
|
||||||
|
|
||||||
|
public static final int PACKETTOSTRING_RESPONSE = 20;
|
||||||
|
public static final int STRINGTOPACKET_RESPONSE = 21;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -95,6 +98,10 @@ public class NetworkExtensionInfo {
|
|||||||
public static final int MANIPULATEDPACKET = 2;
|
public static final int MANIPULATEDPACKET = 2;
|
||||||
public static final int REQUESTFLAGS = 3;
|
public static final int REQUESTFLAGS = 3;
|
||||||
public static final int SENDMESSAGE = 4;
|
public static final int SENDMESSAGE = 4;
|
||||||
|
|
||||||
|
public static final int PACKETTOSTRING_REQUEST = 20;
|
||||||
|
public static final int STRINGTOPACKET_REQUEST = 21;
|
||||||
|
|
||||||
public static final int EXTENSIONCONSOLELOG = 98;
|
public static final int EXTENSIONCONSOLELOG = 98;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package gearth.services.extensionhandler.extensions.implementations.simple;
|
package gearth.services.extensionhandler.extensions.implementations.simple;
|
||||||
|
|
||||||
import gearth.protocol.HMessage;
|
import gearth.protocol.HMessage;
|
||||||
|
import gearth.protocol.HPacket;
|
||||||
import gearth.services.extensionhandler.extensions.GEarthExtension;
|
import gearth.services.extensionhandler.extensions.GEarthExtension;
|
||||||
|
|
||||||
public class ExampleExtension extends GEarthExtension {
|
public class ExampleExtension extends GEarthExtension {
|
||||||
@ -105,4 +106,18 @@ public class ExampleExtension extends GEarthExtension {
|
|||||||
// finish up and call "hasClosed()"
|
// finish up and call "hasClosed()"
|
||||||
hasClosed();
|
hasClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ignore these
|
||||||
|
@Override
|
||||||
|
public void packetToStringResponse(String string, String expression) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stringToPacketResponse(HPacket packet) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user