diff --git a/G-Earth/src/main/java/gearth/misc/Cacher.java b/G-Earth/src/main/java/gearth/misc/Cacher.java index c5a8000..882c4ab 100644 --- a/G-Earth/src/main/java/gearth/misc/Cacher.java +++ b/G-Earth/src/main/java/gearth/misc/Cacher.java @@ -85,6 +85,11 @@ public class Cacher { object.put(key, val); updateCache(object, cache_filename); } + public static void remove(String key, String cache_filename) { + JSONObject object = getCacheContents(cache_filename); + if (object.has(key)) object.remove(key); + updateCache(object, cache_filename); + } public static Object get(String key, String cache_filename) { JSONObject object = getCacheContents(cache_filename); if (object.has(key)) return object.get(key); @@ -113,6 +118,9 @@ public class Cacher { public static void put(String key, Object val) { put(key, val, DEFAULT_CACHE_FILENAME); } + public static void remove(String key) { + remove(key, DEFAULT_CACHE_FILENAME); + } public static Object get(String key) { return get(key, DEFAULT_CACHE_FILENAME); } diff --git a/G-Earth/src/main/java/gearth/protocol/HConnection.java b/G-Earth/src/main/java/gearth/protocol/HConnection.java index 1a20f9b..417e79f 100644 --- a/G-Earth/src/main/java/gearth/protocol/HConnection.java +++ b/G-Earth/src/main/java/gearth/protocol/HConnection.java @@ -162,14 +162,15 @@ public class HConnection { return proxy.sendToServer(packet); } - private boolean canSendPacket(HMessage.Direction direction, HPacket packet) { + public boolean canSendPacket(HMessage.Direction direction, HPacket packet) { return isPacketSendingAllowed(direction, packet) && (developerMode || isPacketSendingSafe(direction, packet)); } public boolean isPacketSendingAllowed(HMessage.Direction direction, HPacket packet) { + if (state != HState.CONNECTED) return false; + HProxy proxy = this.proxy; if (proxy == null) return false; - if (packet.isCorrupted()) return false; if (!packet.isPacketComplete()) { @@ -185,8 +186,9 @@ public class HConnection { } public boolean isPacketSendingSafe(HMessage.Direction direction, HPacket packet) { + if (proxy == null) return true; // do not mark unsafe, but won't pass "isPacketSendingAllowed()" check String hotelVersion = proxy.getHotelVersion(); - if (hotelVersion == null) return false; + if (hotelVersion == null) return true; SafePacketsContainer packetsContainer = PacketSafetyManager.PACKET_SAFETY_MANAGER.getPacketContainer(hotelVersion); return packetsContainer.isPacketSafe(packet.headerId(), direction); diff --git a/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java b/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java index a1c552d..7b5a2f6 100644 --- a/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java +++ b/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java @@ -132,11 +132,15 @@ public class ExtraController extends SubForm implements SocksConfiguration { } private void saveSocksConfig() { - JSONObject jsonObject = new JSONObject(); - jsonObject.put(SOCKS_IP, getSocksHost()); - jsonObject.put(SOCKS_PORT, getSocksPort()); -// jsonObject.put(IGNORE_ONCE, cbx_socksUseIfNeeded.isSelected()); - Cacher.put(SOCKS_CACHE_KEY, jsonObject); + if (txt_socksIp.getText().contains(":")) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(SOCKS_IP, getSocksHost()); + jsonObject.put(SOCKS_PORT, getSocksPort()); + Cacher.put(SOCKS_CACHE_KEY, jsonObject); + } + else { + Cacher.remove(SOCKS_CACHE_KEY); + } } private void updateAdvancedUI() { @@ -160,7 +164,11 @@ public class ExtraController extends SubForm implements SocksConfiguration { @Override public int getSocksPort() { - return Integer.parseInt(txt_socksIp.getText().split(":")[1]); + String socksString = txt_socksIp.getText(); + if (socksString.contains(":")) { + return Integer.parseInt(socksString.split(":")[1]); + } + return 1337; } @Override diff --git a/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java b/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java index dc4120d..bb40ca6 100644 --- a/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java +++ b/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java @@ -1,10 +1,10 @@ package gearth.ui.subforms.injection; -import gearth.GEarth; import gearth.misc.Cacher; -import gearth.services.packet_info.PacketInfoManager; +import gearth.protocol.HConnection; import gearth.protocol.HMessage; -import gearth.protocol.connection.HState; +import gearth.protocol.HPacket; +import gearth.ui.SubForm; import gearth.ui.translations.LanguageBundle; import gearth.ui.translations.TranslatableString; import javafx.application.Platform; @@ -14,8 +14,6 @@ import javafx.scene.input.MouseButton; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.text.Text; -import gearth.protocol.HPacket; -import gearth.ui.SubForm; import java.util.ArrayList; import java.util.Arrays; @@ -109,6 +107,7 @@ public class InjectionController extends SubForm { private void updateUI() { boolean dirty = false; + corruption.setFormat("%s: %s"); corruption.setKey(1, "tab.injection.corrupted.false"); lbl_corruption.getStyleClass().clear(); lbl_corruption.getStyleClass().add("not-corrupted-label"); @@ -140,27 +139,45 @@ public class InjectionController extends SubForm { } if (!dirty) { - PacketInfoManager packetInfoManager = getHConnection().getPacketInfoManager(); - for (HPacket packet : packets) { - packet.completePacket(packetInfoManager); - } + HConnection connection = getHConnection(); boolean canSendToClient = Arrays.stream(packets).allMatch(packet -> - packet.isPacketComplete() && packet.canSendToClient()); + connection.canSendPacket(HMessage.Direction.TOCLIENT, packet)); boolean canSendToServer = Arrays.stream(packets).allMatch(packet -> - packet.isPacketComplete() && packet.canSendToServer()); + connection.canSendPacket(HMessage.Direction.TOSERVER, packet)); + + btn_sendToClient.setDisable(!canSendToClient); + btn_sendToServer.setDisable(!canSendToServer); + + // mark packet sending unsafe if there is any packet that is unsafe for both TOSERVER and TOCLIENT + boolean isUnsafe = Arrays.stream(packets).anyMatch(packet -> + !connection.isPacketSendingSafe(HMessage.Direction.TOCLIENT, packet) && + !connection.isPacketSendingSafe(HMessage.Direction.TOSERVER, packet)); - btn_sendToClient.setDisable(!canSendToClient || getHConnection().getState() != HState.CONNECTED); - btn_sendToServer.setDisable(!canSendToServer || getHConnection().getState() != HState.CONNECTED); if (packets.length == 1) { - pcktInfo.setFormatAndKeys("%s (%s: " + packets[0].headerId() + ", %s: " + packets[0].length() + ")", - "tab.injection.description.header", - "tab.injection.description.id", - "tab.injection.description.length"); + HPacket packet = packets[0]; + if (isUnsafe) { + pcktInfo.setFormatAndKeys("%s (%s: " + packet.headerId() + ", %s: " + packet.length() + "), %s", + "tab.injection.description.header", + "tab.injection.description.id", + "tab.injection.description.length", + "tab.injection.description.unsafe"); + } + else { + pcktInfo.setFormatAndKeys("%s (%s: " + packet.headerId() + ", %s: " + packet.length() + ")", + "tab.injection.description.header", + "tab.injection.description.id", + "tab.injection.description.length"); + } } else { - lbl_pcktInfo.setText(""); + if (isUnsafe) { + pcktInfo.setFormatAndKeys("%s", "tab.injection.description.unsafe"); + } + else { + pcktInfo.setFormatAndKeys(""); + } } } else { if (packets.length == 1) { diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_de.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_de.properties index 7fd8c59..0b74316 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_de.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_de.properties @@ -30,6 +30,7 @@ tab.injection.description.header=Header tab.injection.description.packets=Pakete tab.injection.description.id=ID tab.injection.description.length=Länge +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Zum Server senden tab.injection.send.toclient=Zum Client senden tab.injection.history=Verlauf: diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_en.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_en.properties index b040a16..9b4c080 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_en.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_en.properties @@ -28,6 +28,7 @@ tab.injection.description.header=header tab.injection.description.packets=packets tab.injection.description.id=id tab.injection.description.length=length +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Send to server tab.injection.send.toclient=Send to client tab.injection.history=History: diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_es.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_es.properties index dabdf44..89d04b2 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_es.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_es.properties @@ -28,6 +28,7 @@ tab.injection.description.header=header tab.injection.description.packets=packets tab.injection.description.id=id tab.injection.description.length=longitud +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Enviar al servidor tab.injection.send.toclient=Enviar a cliente tab.injection.history=Historial diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_fi.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_fi.properties index 8206ab0..0137b9e 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_fi.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_fi.properties @@ -28,6 +28,7 @@ tab.injection.description.header=otsake tab.injection.description.packets=paketit tab.injection.description.id=id tab.injection.description.length=pituus +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Lähetä palvelimelle tab.injection.send.toclient=Lähetä asiakkaalle tab.injection.history=Historia: diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_fr.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_fr.properties index b1c8f26..ccdfbc7 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_fr.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_fr.properties @@ -31,6 +31,7 @@ tab.injection.description.header=header tab.injection.description.packets=packets tab.injection.description.id=id tab.injection.description.length=taille +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Envoyer au serveur tab.injection.send.toclient=Envoyer au client tab.injection.history=Historique: diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_it.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_it.properties index 0dcb04a..45ef73a 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_it.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_it.properties @@ -28,6 +28,7 @@ tab.injection.description.header=header tab.injection.description.packets=packets tab.injection.description.id=id tab.injection.description.length=lunghezza +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Manda al server tab.injection.send.toclient=Manda al client tab.injection.history=Cronologia: diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_nl.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_nl.properties index 45c926a..19f8303 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_nl.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_nl.properties @@ -28,6 +28,7 @@ tab.injection.description.header=header tab.injection.description.packets=packets tab.injection.description.id=id tab.injection.description.length=lengte +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Stuur naar server tab.injection.send.toclient=Stuur naar client tab.injection.history=Geschiedenis: diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_pt.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_pt.properties index cf28715..3fd2dab 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_pt.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_pt.properties @@ -28,6 +28,7 @@ tab.injection.description.header=cabeçalho tab.injection.description.packets=pacotes tab.injection.description.id=id tab.injection.description.length=comprimento +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Enviar para o servidor tab.injection.send.toclient=Enviar para o cliente tab.injection.history=Histórico: diff --git a/G-Earth/src/main/resources/gearth/ui/translations/messages_tr.properties b/G-Earth/src/main/resources/gearth/ui/translations/messages_tr.properties index 556bbe5..a18cf8f 100644 --- a/G-Earth/src/main/resources/gearth/ui/translations/messages_tr.properties +++ b/G-Earth/src/main/resources/gearth/ui/translations/messages_tr.properties @@ -28,6 +28,7 @@ tab.injection.description.header=header tab.injection.description.packets=paketler tab.injection.description.id=id tab.injection.description.length=uzunluk +tab.injection.description.unsafe=UNSAFE tab.injection.send.toserver=Server a yolla tab.injection.send.toclient=Client a yolla tab.injection.history=Geçmiş: