aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/chat/Message.java6
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java2
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/client/Config.java1
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java43
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java5
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java12
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java5
7 files changed, 48 insertions, 26 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);
}
diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java
index 0b970b4..d06cfb4 100644
--- a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java
+++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java
@@ -315,6 +315,11 @@ public class BBsentialsConfigScreemFactory {
.setTooltip(Text.of("Detailed Dev Mode"))
.setSaveConsumer(newValue -> BBsentials.config.detailedDevMode = newValue)
.build());
+ dev.addEntry(entryBuilder.startBooleanToggle(Text.of("Dev Security"), BBsentials.config.devSecurity)
+ .setDefaultValue(true)
+ .setTooltip(Text.of("Shows dev debug even when its sensetive information"))
+ .setSaveConsumer(newValue -> BBsentials.config.devSecurity = newValue)
+ .build());
}
if (BBsentials.config.hasBBRoles("splasher")) {
ConfigCategory dev = builder.getOrCreateCategory(Text.of("§dSplashes"));
diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java
index ce2c0bb..a0f04d2 100644
--- a/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java
+++ b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java
@@ -1,6 +1,7 @@
package de.hype.bbsentials.fabric;
import com.mojang.authlib.exceptions.AuthenticationException;
+import de.hype.bbsentials.common.chat.Chat;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.PositionedSoundInstance;
@@ -53,8 +54,15 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils {
try {
MinecraftClient.getInstance().getSessionService().joinServer(MinecraftClient.getInstance().getGameProfile().getId(), MinecraftClient.getInstance().getSession().getAccessToken(), serverId);
success = true;
- } catch (AuthenticationException ignored) {
-
+ } catch (AuthenticationException e) {
+ try {
+ Thread.sleep(1000);
+ }catch (Exception ignored){
+ }
+ if (tries==0){
+ Chat.sendPrivateMessageToSelfError("Could not authenticate at mojang: "+e.getMessage());
+ e.printStackTrace();
+ }
}
}
return serverId;
diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java
index 2e7b4fe..92868d7 100644
--- a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java
+++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java
@@ -84,6 +84,11 @@ public class ModInitialiser implements ClientModInitializer {
connectToBBserver();
return 1;
}))
+ .then(ClientCommandManager.literal("disconnect")
+ .executes((context) -> {
+ connection.close();
+ return 1;
+ }))
.then(ClientCommandManager.literal("reconnect-stable-server")
.executes((context) -> {
connectToBBserver(false);