diff options
12 files changed, 115 insertions, 25 deletions
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 50f898d..91b4418 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 @@ -32,6 +32,7 @@ public class Config implements Serializable { // Set via load / default you may change these public boolean overrideBingoTime = false; public boolean connectToBeta = false; + public boolean useMojangAuth = false; public String bbServerURL = "localhost"; public String apiKey = ""; diff --git a/common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java b/common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java index eaf3ee1..74a7757 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java @@ -7,15 +7,15 @@ import java.util.List; public interface DebugThread extends Runnable { @Override - public default void run() { + default void run() { loop(); //place a breakpoint for only this thread here. } - public default void loop() { + default void loop() { } - public default List<String> test() { + default List<String> test() { return Collections.singletonList(""); } } 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 6dd9edb..69be09b 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 @@ -17,6 +17,7 @@ import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.io.*; +import java.math.BigInteger; import java.net.Socket; import java.net.SocketException; import java.security.KeyManagementException; @@ -27,6 +28,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.Arrays; +import java.util.Random; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -45,7 +47,6 @@ public class BBsentialConnection { } - public static boolean isCommandSafe(String command) { if (command.startsWith("/p ") || command.startsWith("/party ") || command.startsWith("/boop ") || command.startsWith("/msg ") || command.startsWith("/hub ")) { return true; @@ -66,7 +67,6 @@ public class BBsentialConnection { } - public void connect(String serverIP, int serverPort) { // Enable SSL handshake debugging System.setProperty("javax.net.debug", "ssl,handshake"); @@ -234,15 +234,6 @@ public class BBsentialConnection { public void onMessageReceived(String message) { if (!PacketUtils.handleIfPacket(this, message)) { if (message.startsWith("H-")) { - if (message.equals("H-BB-Login: ")) { - Chat.sendPrivateMessageToSelfSuccess("Logging into BBsentials-online"); - try { - Thread.sleep(100); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - sendPacket(new RequestConnectPacket(BBsentials.config.getMCUUID(), BBsentials.getConfig().getApiKey(), BBsentials.getConfig().getApiVersion(), AuthenticationConstants.DATABASE)); - } } else { Chat.sendPrivateMessageToSelfSuccess("BB: " + message); @@ -295,8 +286,9 @@ public class BBsentialConnection { } public void onSplashNotifyPacket(SplashNotifyPacket packet) { + //influencing the delay in any way is disallowed! int waitTime; - if (packet.splasherUsername.equals(BBsentials.config.getUsername())&& BBsentials.config.autoSplashStatusUpdates) { + if (packet.splasherUsername.equals(BBsentials.config.getUsername()) && BBsentials.config.autoSplashStatusUpdates) { Chat.sendPrivateMessageToSelfInfo("The Splash Update Statuses will be updatet automatically for you. If you need to do something manually go into Discord Splash Dashboard"); SplashStatusUpdateListener splashStatusUpdateListener = new SplashStatusUpdateListener(this, packet); BBsentials.splashStatusUpdateListener = splashStatusUpdateListener; @@ -336,7 +328,7 @@ public class BBsentialConnection { if (!(packet.extraMessage == null || packet.extraMessage.isEmpty())) { tellrawText = tellrawText.replace("@extramessage", " : " + packet.extraMessage); } - Chat.sendPrivateMessageToSelfText(new Message(tellrawText,"")); + Chat.sendPrivateMessageToSelfText(new Message(tellrawText, "")); } } else { @@ -348,7 +340,8 @@ public class BBsentialConnection { public void onMiningEventPacket(MiningEventPacket packet) { if (!BBsentials.config.toDisplayConfig.getValue("disableAll")) { //its will returns false cause disabled is checked already before. - if (BBsentials.config.toDisplayConfig.blockChEvents && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) return; + if (BBsentials.config.toDisplayConfig.blockChEvents && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) + return; if (!(BBsentials.config.toDisplayConfig.allEvents)) { if (packet.event.equals(MiningEvents.RAFFLE)) { if (!BBsentials.config.toDisplayConfig.raffle) return; @@ -483,7 +476,7 @@ public class BBsentialConnection { Chat.sendCommand("/p " + packet.type + String.join(" ", packet.users)); } else { - Chat.sendPrivateMessageToSelfImportantInfo("Blocked a Party Command from the Server: "+packet.type+" : "+String.join(" ", packet.users)); + Chat.sendPrivateMessageToSelfImportantInfo("Blocked a Party Command from the Server: " + packet.type + " : " + String.join(" ", packet.users)); } } @@ -499,20 +492,50 @@ public class BBsentialConnection { } } + public void onRequestAuthentication(RequestAuthentication packet) { + Chat.sendPrivateMessageToSelfSuccess("Logging into BBsentials-online"); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + Random r1 = new Random(); + Random r2 = new Random(System.identityHashCode(new Object())); + BigInteger random1Bi = new BigInteger(128, r1); + BigInteger random2Bi = new BigInteger(128, r2); + BigInteger serverBi = random1Bi.xor(random2Bi); + String clientRandom = serverBi.toString(16); + + String serverId = clientRandom + packet.serverIdSuffix; + if (BBsentials.config.useMojangAuth) { + String serverID = EnvironmentCore.mcUtils.mojangAuth(serverId); + sendPacket(new RequestConnectPacket(BBsentials.config.getMCUUID(), serverID, BBsentials.getConfig().getApiVersion(), AuthenticationConstants.MOJANG)); + } + else { + sendPacket(new RequestConnectPacket(BBsentials.config.getMCUUID(), BBsentials.getConfig().getApiKey(), BBsentials.getConfig().getApiVersion(), AuthenticationConstants.DATABASE)); + } + } + public boolean showChChest(ChChestItem[] items) { if (BBsentials.config.toDisplayConfig.allChChestItem) return true; for (ChChestItem item : items) { if (BBsentials.config.toDisplayConfig.customChChestItem && item.isCustom()) return true; if (BBsentials.config.toDisplayConfig.allRoboPart && item.isRoboPart()) return true; - if (BBsentials.config.toDisplayConfig.prehistoricEgg && item.equals(ChChestItems.PrehistoricEgg)) return true; - if (BBsentials.config.toDisplayConfig.pickonimbus2000 && item.equals(ChChestItems.Pickonimbus2000)) return true; + if (BBsentials.config.toDisplayConfig.prehistoricEgg && item.equals(ChChestItems.PrehistoricEgg)) + return true; + if (BBsentials.config.toDisplayConfig.pickonimbus2000 && item.equals(ChChestItems.Pickonimbus2000)) + return true; if (BBsentials.config.toDisplayConfig.controlSwitch && item.equals(ChChestItems.ControlSwitch)) return true; if (BBsentials.config.toDisplayConfig.electronTransmitter && item.equals(ChChestItems.ElectronTransmitter)) return true; - if (BBsentials.config.toDisplayConfig.robotronReflector && item.equals(ChChestItems.RobotronReflector)) return true; - if (BBsentials.config.toDisplayConfig.superliteMotor && item.equals(ChChestItems.SuperliteMotor)) return true; - if (BBsentials.config.toDisplayConfig.syntheticHeart && item.equals(ChChestItems.SyntheticHeart)) return true; - if (BBsentials.config.toDisplayConfig.flawlessGemstone && item.equals(ChChestItems.FlawlessGemstone)) return true; + if (BBsentials.config.toDisplayConfig.robotronReflector && item.equals(ChChestItems.RobotronReflector)) + return true; + if (BBsentials.config.toDisplayConfig.superliteMotor && item.equals(ChChestItems.SuperliteMotor)) + return true; + if (BBsentials.config.toDisplayConfig.syntheticHeart && item.equals(ChChestItems.SyntheticHeart)) + return true; + if (BBsentials.config.toDisplayConfig.flawlessGemstone && item.equals(ChChestItems.FlawlessGemstone)) + return true; if (BBsentials.config.toDisplayConfig.jungleHeart && item.equals(ChChestItems.JungleHeart)) return true; } return false; diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java index 52f1ea1..ebc844c 100644 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java +++ b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java @@ -4,4 +4,5 @@ public class AuthenticationConstants { //Authentication Types public static final String MOJANG = "MOJANG"; public static final String DATABASE = "DATABASE"; + public static final String REGISTER = "REGISTER"; } diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java index 43835c6..9b9a976 100644 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java +++ b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java @@ -10,5 +10,8 @@ public enum InternalReasonConstants { INVALID_LOGIN, KICKED, ANOTHER_LOGIN, - SERVER_RESTART + SERVER_RESTART, + NOT_REGISTERED, + ON_COOLDOWN, + OTHER } diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java index 493785a..c007d31 100644 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java +++ b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java @@ -13,4 +13,6 @@ public interface MCUtils { void playsound(String eventName); int getPotTime(); + + String mojangAuth(String serverId); } diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java b/common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java index 23368d8..8d8eaec 100644 --- a/common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java +++ b/common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java @@ -36,6 +36,7 @@ public class PacketManager { packets.add(new Packet<>(SplashNotifyPacket.class, connection::onSplashNotifyPacket)); packets.add(new Packet<>(SystemMessagePacket.class, connection::onSystemMessagePacket)); packets.add(new Packet<>(WelcomeClientPacket.class, connection::onWelcomePacket)); + packets.add(new Packet<>(RequestAuthentication.class, connection::onRequestAuthentication)); } // Method to handle a received packet diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/RequestAuthentication.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/RequestAuthentication.java new file mode 100644 index 0000000..81ea9fe --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/common/packets/packets/RequestAuthentication.java @@ -0,0 +1,15 @@ +package de.hype.bbsentials.common.packets.packets; + +import de.hype.bbsentials.common.packets.AbstractPacket; + +public class RequestAuthentication extends AbstractPacket { + + public final String serverIdSuffix; + public final int serverVersion; + + public RequestAuthentication(String serverIdSuffix, int serverVersion) { + super(1, 1); //Min and Max supported Version + this.serverIdSuffix = serverIdSuffix; + this.serverVersion = serverVersion; + } +} 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 5cfcbe3..0b970b4 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java @@ -67,6 +67,11 @@ public class BBsentialsConfigScreemFactory { .setTooltip(Text.of("Makes you connect to the Test Server instead of the Main Server. Keep in mind that all announces may be tests and the main announces are not transferred over to here!")) // Optional: Shown when the user hover over this option .setSaveConsumer(newValue -> BBsentials.config.connectToBeta = newValue) .build()); + server.addEntry(entryBuilder.startBooleanToggle(Text.of("Mojang Auth"), BBsentials.config.useMojangAuth) + .setDefaultValue(false) + .setTooltip(Text.of("Uses mojang as authenticator instead of api key")) + .setSaveConsumer(newValue -> BBsentials.config.useMojangAuth = newValue) + .build()); server.addEntry(entryBuilder.startBooleanToggle(Text.of("Override Bingo Time"), BBsentials.config.overrideBingoTime) .setDefaultValue(false) .setTooltip(Text.of("Override the Bingo Time and connect always to the Server. (Bingo time is 14 days cause Extreme Bingo)")) diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java b/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java index 1752492..6d5d8d3 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java @@ -3,9 +3,18 @@ package de.hype.bbsentials.fabric; import java.util.List; public class DebugThread implements de.hype.bbsentials.common.client.DebugThread { + boolean doTest = false; + @Override public void loop() { + if (doTest) { + doTest = false; + test(); + } + } + public void doOnce() { + doTest = true; } @Override 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 149b72a..d3a8ae3 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java @@ -1,5 +1,6 @@ package de.hype.bbsentials.fabric; +import com.mojang.authlib.exceptions.AuthenticationException; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.sound.PositionedSoundInstance; @@ -9,6 +10,8 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; import java.io.File; +import java.math.BigInteger; +import java.util.Random; public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { public boolean isWindowFocused() { @@ -32,6 +35,7 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance .master(SoundEvent.of(new Identifier(eventName)), 1.0F, 1.0F)); } + public int getPotTime() { int remainingDuration = 0; StatusEffectInstance potTimeRequest = MinecraftClient.getInstance().player.getStatusEffect(StatusEffects.STRENGTH); @@ -42,4 +46,13 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { } return remainingDuration; } + + public String mojangAuth(String serverId) { + try { + MinecraftClient.getInstance().getSessionService().joinServer(MinecraftClient.getInstance().getGameProfile().getId(), MinecraftClient.getInstance().getSession().getAccessToken(), serverId); + } catch (AuthenticationException ignored) { + return ""; + } + return serverId; + } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java index a9334d5..424eded 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java @@ -1,5 +1,6 @@ package de.hype.bbsentials.forge; +import com.mojang.authlib.exceptions.AuthenticationException; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.potion.Potion; @@ -8,6 +9,8 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.Display; import java.io.File; +import java.math.BigInteger; +import java.util.Random; public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { public boolean isWindowFocused() { @@ -41,4 +44,18 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { } return remainingDuration; } + + + public String mojangAuth(String serverId) { + try { + Minecraft.getMinecraft().getSessionService().joinServer(Minecraft + .getMinecraft() + .getSession() + .getProfile(), Minecraft.getMinecraft().getSession().getToken(), serverId); + } catch (AuthenticationException e) { + return null; + } + return serverId; + } + } |