diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-10-17 20:57:10 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-10-17 20:57:10 +0200 |
commit | 8aa2e47c4a63fb2669e1635a5a508672ee800159 (patch) | |
tree | cf29916521d8f2d0bad6ecfff031bf4f7005219c /common | |
parent | 12b944de4e1b69eaf5ffc0627191f984d94a2f40 (diff) | |
download | BBsentials-8aa2e47c4a63fb2669e1635a5a508672ee800159.tar.gz BBsentials-8aa2e47c4a63fb2669e1635a5a508672ee800159.tar.bz2 BBsentials-8aa2e47c4a63fb2669e1635a5a508672ee800159.zip |
more changes (fixes)
Diffstat (limited to 'common')
4 files changed, 28 insertions, 24 deletions
diff --git a/common/src/main/java/de/hype/bbsentials/common/chat/Message.java b/common/src/main/java/de/hype/bbsentials/common/chat/Message.java index 7d4b62d..a71b851 100644 --- a/common/src/main/java/de/hype/bbsentials/common/chat/Message.java +++ b/common/src/main/java/de/hype/bbsentials/common/chat/Message.java @@ -20,8 +20,10 @@ public class Message { this.string=string; this.actionBar = actionbar; } - public static Message of(String string){ - return new Message("{\"text\":\""+string+"\"}",string); + public static Message of(String string) { + String escapedString = string.replace("\\", "\\\\").replace("\"", "\\\""); + String json = "{\"text\":\"" + escapedString + "\"}"; + return new Message(json, string); } // public String getJson() { diff --git a/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java b/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java index b694add..7d0a1e6 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java @@ -44,7 +44,9 @@ public class BBsentials { public static void connectToBBserver(boolean beta) { if (connection != null) { connection.sendHiddenMessage("exit"); + connection.close(); } + connection=null; if (bbthread != null) { if (bbthread.isAlive()) { bbthread.interrupt(); diff --git a/common/src/main/java/de/hype/bbsentials/common/client/Config.java b/common/src/main/java/de/hype/bbsentials/common/client/Config.java index 91b4418..47809d9 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/Config.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/Config.java @@ -16,6 +16,7 @@ public class Config implements Serializable { public boolean allowServerPartyInvite = true; public boolean devMode = false; public boolean detailedDevMode = false; + public boolean devSecurity = true; //You can change again // set automatically diff --git a/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java b/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java index 42bc29c..a524fb2 100644 --- a/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java +++ b/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java @@ -168,6 +168,7 @@ public class BBsentialConnection { try { while (true) { String message = messageQueue.take(); + if (BBsentials.config.isDetailedDevModeEnabled()) Chat.sendPrivateMessageToSelfDebug("BBs: "+message); writer.println(message); } } catch (InterruptedException e) { @@ -199,28 +200,20 @@ public class BBsentialConnection { } public void sendHiddenMessage(String message) { - if (BBsentials.getConfig().isDetailedDevModeEnabled()) { - Chat.sendPrivateMessageToSelfDebug("BBDev-s: " + message); - } - try { - if (socket.isConnected() && writer != null) { - writer.println(message); + if (isConnected()) { + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + Chat.sendPrivateMessageToSelfDebug("BBDev-s: " + message); + } + try { + if (socket.isConnected() && writer != null) { + if (BBsentials.config.isDetailedDevModeEnabled()) Chat.sendPrivateMessageToSelfDebug("BBHs: "+message); + writer.println(message); + } + } catch (NullPointerException ignored) { } - } catch (NullPointerException ignored) { } } - public void sendCommand(String message) { - if (BBsentials.getConfig().isDetailedDevModeEnabled()) { - Chat.sendPrivateMessageToSelfDebug("BBDev-s: " + message); - } - if (socket.isConnected() && writer != null) { - writer.println(message); - } - else { - Chat.sendPrivateMessageToSelfFatal("BB: It seems like the connection was lost. Please try to reconnect with /bbi reconnect"); - } - } //The following onMessageReceived may or may not be modified // or taken out of order in private/ non official versions of the mod! @@ -263,7 +256,7 @@ public class BBsentialConnection { public <E extends AbstractPacket> void sendPacket(E packet) { String packetName = packet.getClass().getSimpleName(); String rawjson = PacketUtils.parsePacketToJson(packet); - if (BBsentials.getConfig().isDetailedDevModeEnabled() && !(packet.getClass().equals(RequestConnectPacket.class))) { + if (BBsentials.getConfig().isDetailedDevModeEnabled() && !(packet.getClass().equals(RequestConnectPacket.class)&&BBsentials.config.devSecurity)) { Chat.sendPrivateMessageToSelfDebug("BBDev-sP: " + packetName + ": " + rawjson); } if (socket.isConnected() && writer != null) { @@ -488,7 +481,7 @@ public class BBsentialConnection { public void onRequestAuthentication(RequestAuthentication packet) { Chat.sendPrivateMessageToSelfSuccess("Logging into BBsentials-online"); try { - Thread.sleep(100); + Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -537,8 +530,7 @@ public class BBsentialConnection { public boolean isConnected() { try { - socket.isConnected(); - return true; + return socket.isConnected() && !socket.isClosed(); } catch (Exception e) { return false; } @@ -568,6 +560,13 @@ public class BBsentialConnection { } } + public void close() { + try { + socket.close(); + } catch (IOException ignored) { + } + } + public interface MessageReceivedCallback { void onMessageReceived(String message); } |