mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
hashing in Logger & example extension
This commit is contained in:
parent
d14b21af62
commit
c130058694
@ -26,7 +26,7 @@ public class AdminOnConnect extends Extension {
|
||||
|
||||
private boolean done = true;
|
||||
|
||||
protected void init() {
|
||||
protected void initExtension() {
|
||||
intercept(HMessage.Side.TOCLIENT, message -> {
|
||||
if (!done) {
|
||||
HPacket packet = message.getPacket();
|
||||
|
@ -40,7 +40,7 @@
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>extensions.speechcolorizer.SpeechColorizer</mainClass>
|
||||
<mainClass>extensions.happyspeech.HappySpeech</mainClass>
|
||||
<useUniqueVersions>false</useUniqueVersions>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
@ -65,7 +65,7 @@
|
||||
<outputDirectory>${project.build.directory}/bin</outputDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>extensions.speechcolorizer.SpeechColorizer</mainClass>
|
||||
<mainClass>extensions.happyspeech.HappySpeech</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
@ -1,7 +1,8 @@
|
||||
package extensions.speechcolorizer;
|
||||
package extensions.happyspeech;
|
||||
|
||||
import gearth.extensions.Extension;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import gearth.extensions.extra.hashing.HashSupport;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
@ -16,50 +17,43 @@ import java.util.Random;
|
||||
*/
|
||||
|
||||
@ExtensionInfo(
|
||||
Title = "Colorize me!",
|
||||
Description = "Because we like to be weird",
|
||||
Title = "HappySpeech",
|
||||
Description = "Example extension for hashSupport",
|
||||
Version = "1.0",
|
||||
Author = "sirjonasxx"
|
||||
)
|
||||
public class SpeechColorizer extends Extension {
|
||||
public class HappySpeech extends Extension {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpeechColorizer(args).run();
|
||||
new HappySpeech(args).run();
|
||||
}
|
||||
private SpeechColorizer(String[] args) {
|
||||
private HappySpeech(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
private static final int SPEECH_ID = 3373;
|
||||
private static final String[] COLORS = {"red", "blue", "cyan", "green", "purple"};
|
||||
private static final Random r = new Random();
|
||||
|
||||
private HashSupport hashSupport;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
intercept(HMessage.Side.TOSERVER, SPEECH_ID, this::onSendMessage);
|
||||
System.out.println("test");
|
||||
protected void initExtension() {
|
||||
hashSupport = new HashSupport(this);
|
||||
hashSupport.intercept(HMessage.Side.TOSERVER, "RoomUserShout", this::onSendMessage);
|
||||
hashSupport.intercept(HMessage.Side.TOSERVER, "RoomUserTalk", this::onSendMessage);
|
||||
}
|
||||
|
||||
private void onSendMessage(HMessage message) {
|
||||
HPacket packet = message.getPacket();
|
||||
|
||||
String speechtext = packet.readString();
|
||||
System.out.println("you said: " + speechtext);
|
||||
|
||||
message.setBlocked(speechtext.equals("blocked"));
|
||||
packet.replaceString(6, "@" + COLORS[r.nextInt(COLORS.length)] + "@" + speechtext);
|
||||
packet.replaceString(6, "@" + COLORS[r.nextInt(COLORS.length)] + "@" + speechtext + " :)");
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
return "Colorize me!";
|
||||
}
|
||||
protected String getDescription() {
|
||||
return "Because we like to be weird";
|
||||
}
|
||||
protected String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
protected String getAuthor() {
|
||||
return "sirjonasxx";
|
||||
protected void onClick() {
|
||||
//{l}{u:1047}{i:0}{s:text}{i:0}{i:0}{i:0}{i:0}
|
||||
hashSupport.sendToClient("RoomUserTalk", 0, "You clicked on this extension!", 0, 0, 0, 0);
|
||||
}
|
||||
}
|
@ -60,7 +60,8 @@
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<finalName>G-Earth-${project.version}</finalName>
|
||||
<!--<finalName>G-Earth-${project.version}</finalName>-->
|
||||
<finalName>G-Earth</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -156,7 +156,7 @@ public abstract class Extension implements IExtension{
|
||||
flagRequestCallback = null;
|
||||
}
|
||||
else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.INIT) {
|
||||
init();
|
||||
initExtension();
|
||||
}
|
||||
else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.FREEFLOW) {
|
||||
// nothing to be done yet
|
||||
@ -338,7 +338,7 @@ public abstract class Extension implements IExtension{
|
||||
* Gets called when a connection has been established with G-Earth.
|
||||
* This does not imply a connection with Habbo is setup.
|
||||
*/
|
||||
protected void init(){}
|
||||
protected void initExtension(){}
|
||||
|
||||
/**
|
||||
* The application got doubleclicked from the G-Earth interface. Doing something here is optional
|
||||
|
@ -21,7 +21,7 @@ public class ExtensionFormLauncher extends Application{
|
||||
|
||||
extensionForm.extension = new Extension(args) {
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initExtension() {
|
||||
extensionForm.initExtension();
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class HarbleAPI {
|
||||
this.destination = destination;
|
||||
this.headerId = headerId;
|
||||
this.hash = hash;
|
||||
this.name = name;
|
||||
this.name = (name == null || name.equals("null") ? null : name);
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -41,6 +41,11 @@ public class HarbleAPI {
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String s = (headerId+": " + "["+hash+"]" + "["+name+"]");
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, HarbleMessage> headerIdToMessage_incoming = new HashMap<>();
|
||||
@ -52,13 +57,25 @@ public class HarbleAPI {
|
||||
private Map<String, HarbleMessage> nameToMessage_incoming = new HashMap<>();
|
||||
private Map<String, HarbleMessage> nameToMessage_outgoing = new HashMap<>();
|
||||
|
||||
private boolean success = false;
|
||||
|
||||
/**
|
||||
* cache file must be generated first within G-Earth, inb4 20 extensions requesting it at the same time
|
||||
* @param hotelversion
|
||||
*/
|
||||
|
||||
public static HarbleAPI get(String hotelversion) {
|
||||
HarbleAPI wannabe = new HarbleAPI(hotelversion);
|
||||
if (!wannabe.success) {
|
||||
return null;
|
||||
}
|
||||
return wannabe;
|
||||
}
|
||||
|
||||
public HarbleAPI (String hotelversion) {
|
||||
if (Cacher.cacheFileExists(HarbleAPIFetcher.CACHE_PREFIX + hotelversion)) {
|
||||
JSONObject object = Cacher.getCacheContents(HarbleAPIFetcher.CACHE_PREFIX + hotelversion);
|
||||
success = true;
|
||||
parse(object);
|
||||
}
|
||||
}
|
||||
@ -87,29 +104,52 @@ public class HarbleAPI {
|
||||
}
|
||||
}
|
||||
private void parse(JSONObject object) {
|
||||
JSONObject incoming = object.getJSONObject("IncomingMessages");
|
||||
JSONObject outgoing = object.getJSONObject("OutgoingMessages");
|
||||
try {
|
||||
JSONObject incoming = object.getJSONObject("IncomingMessages");
|
||||
JSONObject outgoing = object.getJSONObject("OutgoingMessages");
|
||||
|
||||
if (incoming != null && outgoing != null) {
|
||||
for (String key : incoming.keySet()) {
|
||||
JSONObject inMsg = incoming.getJSONObject(key);
|
||||
String name = inMsg.getString("Name");
|
||||
String hash = inMsg.getString("Hash");
|
||||
Integer headerId = Integer.parseInt(key);
|
||||
HarbleMessage message = new HarbleMessage(HMessage.Side.TOCLIENT, headerId, hash, name);
|
||||
if (incoming != null && outgoing != null) {
|
||||
for (String key : incoming.keySet()) {
|
||||
try {
|
||||
JSONObject inMsg = incoming.getJSONObject(key);
|
||||
String name;
|
||||
try {
|
||||
name = inMsg.getString("Name");
|
||||
}
|
||||
catch (Exception e) {
|
||||
name = null;
|
||||
}
|
||||
String hash = inMsg.getString("Hash");
|
||||
Integer headerId = Integer.parseInt(key);
|
||||
HarbleMessage message = new HarbleMessage(HMessage.Side.TOCLIENT, headerId, hash, name);
|
||||
|
||||
addMessage(message);
|
||||
}
|
||||
for (String key : outgoing.keySet()) {
|
||||
JSONObject outMsg = incoming.getJSONObject(key);
|
||||
String name = outMsg.getString("Name");
|
||||
String hash = outMsg.getString("Hash");
|
||||
Integer headerId = Integer.parseInt(key);
|
||||
HarbleMessage message = new HarbleMessage(HMessage.Side.TOSERVER, headerId, hash, name);
|
||||
addMessage(message);
|
||||
}
|
||||
catch( Exception e) {}
|
||||
}
|
||||
for (String key : outgoing.keySet()) {
|
||||
try {
|
||||
JSONObject outMsg = outgoing.getJSONObject(key);
|
||||
String name;
|
||||
try {
|
||||
name = outMsg.getString("Name");
|
||||
} catch (Exception e) {
|
||||
name = null;
|
||||
}
|
||||
String hash = outMsg.getString("Hash");
|
||||
Integer headerId = Integer.parseInt(key);
|
||||
HarbleMessage message = new HarbleMessage(HMessage.Side.TOSERVER, headerId, hash, name);
|
||||
|
||||
addMessage(message);
|
||||
addMessage(message);
|
||||
}
|
||||
catch( Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public HarbleMessage getHarbleMessageFromHeaderId(HMessage.Side side, int headerId) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gearth.misc.harble_api;
|
||||
|
||||
import gearth.misc.Cacher;
|
||||
import gearth.protocol.HMessage;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
@ -16,11 +17,14 @@ public class HarbleAPIFetcher {
|
||||
public static final String CACHE_PREFIX = "HARBLE_API-";
|
||||
public static final String HARBLE_API_URL = "https://api.harble.net/revisions/$hotelversion$.json";
|
||||
|
||||
public static HarbleAPI fetch(String hotelversion) {
|
||||
//latest fetched
|
||||
public static HarbleAPI HARBLEAPI = null;
|
||||
|
||||
public static void fetch(String hotelversion) {
|
||||
String cacheName = CACHE_PREFIX + hotelversion;
|
||||
|
||||
if (Cacher.cacheFileExists(cacheName)) {
|
||||
return new HarbleAPI(hotelversion);
|
||||
HARBLEAPI = new HarbleAPI(hotelversion);
|
||||
}
|
||||
else {
|
||||
Connection connection = Jsoup.connect(HARBLE_API_URL.replace("$hotelversion$", hotelversion)).ignoreContentType(true);
|
||||
@ -32,20 +36,23 @@ public class HarbleAPIFetcher {
|
||||
s = s.substring(6, s.length() - 7);
|
||||
JSONObject object = new JSONObject(s);
|
||||
Cacher.updateCache(object, cacheName);
|
||||
|
||||
return new HarbleAPI(hotelversion);
|
||||
HARBLEAPI = new HarbleAPI(hotelversion);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
HARBLEAPI = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
HARBLEAPI = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
HarbleAPI api = fetch("PRODUCTION-201810171204-70166177");
|
||||
fetch("PRODUCTION-201810171204-70166177");
|
||||
|
||||
HarbleAPI api = HARBLEAPI;
|
||||
HarbleAPI.HarbleMessage haMessage = api.getHarbleMessageFromHeaderId(HMessage.Side.TOSERVER, 525);
|
||||
System.out.println(haMessage);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package gearth.ui.extensions;
|
||||
|
||||
import gearth.misc.harble_api.HarbleAPIFetcher;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.Button;
|
||||
@ -149,6 +150,7 @@ public class Extensions extends SubForm {
|
||||
|
||||
getHConnection().addStateChangeListener((oldState, newState) -> {
|
||||
if (newState == HConnection.State.CONNECTED) {
|
||||
HarbleAPIFetcher.fetch(getHConnection().getHotelVersion());
|
||||
synchronized (gEarthExtensions) {
|
||||
for (GEarthExtension extension : gEarthExtensions) {
|
||||
extension.sendMessage(
|
||||
|
@ -1,6 +1,5 @@
|
||||
package gearth.ui.logger;
|
||||
|
||||
import gearth.ui.logger.loggerdisplays.UiLogger;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.Button;
|
||||
|
@ -2,6 +2,7 @@ package gearth.ui.logger.loggerdisplays;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.misc.OSValidator;
|
||||
import gearth.ui.logger.loggerdisplays.uilogger.UiLogger;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 04/04/18.
|
||||
|
@ -0,0 +1,14 @@
|
||||
package gearth.ui.logger.loggerdisplays.uilogger;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 17/11/2018.
|
||||
*/
|
||||
class Element {
|
||||
final String text;
|
||||
final String className;
|
||||
|
||||
Element(String text, String className) {
|
||||
this.text = text;
|
||||
this.className = className;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package gearth.ui.logger.loggerdisplays;
|
||||
package gearth.ui.logger.loggerdisplays.uilogger;
|
||||
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.ui.UiLoggerController;
|
||||
import gearth.ui.logger.loggerdisplays.PacketLogger;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
@ -1,5 +1,8 @@
|
||||
package gearth.ui;
|
||||
package gearth.ui.logger.loggerdisplays.uilogger;
|
||||
|
||||
import gearth.misc.harble_api.HarbleAPI;
|
||||
import gearth.misc.harble_api.HarbleAPIFetcher;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.ui.logger.loggerdisplays.PacketLogger;
|
||||
import javafx.application.Platform;
|
||||
@ -27,6 +30,9 @@ public class UiLoggerController implements Initializable {
|
||||
public Label lblAutoScrolll;
|
||||
public CheckMenuItem chkAutoscroll;
|
||||
public CheckMenuItem chkSkipBigPackets;
|
||||
public CheckMenuItem chkMessageName;
|
||||
public CheckMenuItem chkMessageHash;
|
||||
public Label lblHarbleAPI;
|
||||
|
||||
private StyleClassedTextArea area;
|
||||
|
||||
@ -35,7 +41,8 @@ public class UiLoggerController implements Initializable {
|
||||
private boolean displayStructure = true;
|
||||
private boolean autoScroll = true;
|
||||
private boolean skiphugepackets = true;
|
||||
|
||||
private boolean viewMessageName = true;
|
||||
private boolean viewMessageHash = false;
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
private final List<Element> appendLater = new ArrayList<>();
|
||||
@ -86,6 +93,25 @@ public class UiLoggerController implements Initializable {
|
||||
|
||||
String expr = packet.toExpression();
|
||||
|
||||
lblHarbleAPI.setText("HarbleAPI: " + (HarbleAPIFetcher.HARBLEAPI == null ? "False" : "True"));
|
||||
if ((viewMessageName || viewMessageHash) && HarbleAPIFetcher.HARBLEAPI != null) {
|
||||
HarbleAPI api = HarbleAPIFetcher.HARBLEAPI;
|
||||
HarbleAPI.HarbleMessage message = api.getHarbleMessageFromHeaderId(
|
||||
(isIncoming ? HMessage.Side.TOCLIENT : HMessage.Side.TOSERVER),
|
||||
packet.headerId()
|
||||
);
|
||||
|
||||
if (!(viewMessageName && !viewMessageHash && message.getName() == null)) {
|
||||
if (viewMessageName && message.getName() != null) {
|
||||
elements.add(new Element("["+message.getName()+"]", "messageinfo"));
|
||||
}
|
||||
if (viewMessageHash) {
|
||||
elements.add(new Element("["+message.getHash()+"]", "messageinfo"));
|
||||
}
|
||||
elements.add(new Element("\n", ""));
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlocked) elements.add(new Element("[Blocked]\n", "blocked"));
|
||||
else if (isReplaced) elements.add(new Element("[Replaced]\n", "replaced"));
|
||||
|
||||
@ -180,14 +206,12 @@ public class UiLoggerController implements Initializable {
|
||||
public void toggleSkipPackets(ActionEvent actionEvent) {
|
||||
skiphugepackets = !skiphugepackets;
|
||||
}
|
||||
}
|
||||
|
||||
class Element {
|
||||
final String text;
|
||||
final String className;
|
||||
|
||||
Element(String text, String className) {
|
||||
this.text = text;
|
||||
this.className = className;
|
||||
public void toggleMessageName(ActionEvent actionEvent) {
|
||||
viewMessageName = !viewMessageName;
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleMessageHash(ActionEvent actionEvent) {
|
||||
viewMessageHash = !viewMessageHash;
|
||||
}
|
||||
}
|
@ -9,13 +9,15 @@
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.FlowPane?>
|
||||
|
||||
<BorderPane fx:id="borderPane" prefHeight="560.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.UiLoggerController">
|
||||
<BorderPane fx:id="borderPane" prefHeight="560.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.logger.loggerdisplays.uilogger.UiLoggerController">
|
||||
<top>
|
||||
<MenuBar BorderPane.alignment="CENTER">
|
||||
<Menu mnemonicParsing="false" text="View">
|
||||
<Menu mnemonicParsing="false" text="Display Details">
|
||||
<items>
|
||||
<CheckMenuItem fx:id="chkDisplayStructure" mnemonicParsing="false" onAction="#toggleDisplayStructure" selected="true" text="Structure" />
|
||||
<CheckMenuItem fx:id="chkMessageName" mnemonicParsing="false" onAction="#toggleMessageName" selected="true" text="Message Name" />
|
||||
<CheckMenuItem fx:id="chkMessageHash" mnemonicParsing="false" onAction="#toggleMessageHash" text="Message Hash" />
|
||||
</items>
|
||||
</Menu>
|
||||
<CheckMenuItem fx:id="chkViewIncoming" mnemonicParsing="false" onAction="#toggleViewIncoming" selected="true" text="View Incoming">
|
||||
@ -59,7 +61,20 @@
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="lblAutoScrolll" layoutX="151.0" layoutY="11.0" style="-fx-text-fill: black !important" text="Autoscroll: True" />
|
||||
<Label fx:id="lblAutoScrolll" layoutX="151.0" layoutY="11.0" style="-fx-text-fill: black !important" text="Autoscroll: True">
|
||||
<FlowPane.margin>
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin></Label>
|
||||
<Label layoutX="270.0" layoutY="11.0" text="|">
|
||||
<FlowPane.margin>
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="lblHarbleAPI" layoutX="283.0" layoutY="11.0" style="-fx-text-fill: black !important" text="HarbleAPI: False">
|
||||
<FlowPane.margin>
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
</Label>
|
||||
</FlowPane>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
|
@ -3,6 +3,10 @@
|
||||
-fx-fill: #a9a9a9;
|
||||
}
|
||||
|
||||
.messageinfo {
|
||||
-fx-fill: #D0D3D4;
|
||||
}
|
||||
|
||||
.blocked, .replaced {
|
||||
-fx-fill: #ffff00;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user