From 73219e1ad3b77ee62aef53d4ce3e979365f6365a Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 4 Oct 2024 21:01:23 +0200 Subject: [PATCH] refactor branch names to be central --- .forgejo/workflows/build-client.yml | 18 +++++++++--------- Client/build.gradle | 4 ++-- .../java/de/com/baseband/client/BaseBand.java | 3 ++- .../java/de/com/baseband/client/DevStub.java | 3 ++- .../feature/background/ServerSafeguard.java | 4 +++- .../client/util/net/WebServiceClient.java | 2 +- .../java/de/com/baseband/launcher/Loader.java | 6 +++--- Server/baseband_receiver.sh | 2 +- .../de/com/baseband/server/BuildNames.java | 13 +++++++++++++ .../de/com/baseband/server/LoaderHandler.java | 8 ++++---- .../main/java/de/com/baseband/server/Main.java | 18 +++++++++--------- scripts/push_local.sh | 4 ++-- 12 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 Server/src/main/java/de/com/baseband/server/BuildNames.java diff --git a/.forgejo/workflows/build-client.yml b/.forgejo/workflows/build-client.yml index 5b84b10..37d6eaa 100644 --- a/.forgejo/workflows/build-client.yml +++ b/.forgejo/workflows/build-client.yml @@ -9,7 +9,7 @@ on: jobs: make: - name: Build BaseBand DSM & Broadway + name: Build BaseBand runs-on: 'docker' @@ -40,16 +40,16 @@ jobs: run: | bash scripts/gen_hash.sh ./gradlew Client:build - - name: Obfuscate DSM + - name: Obfuscate main if: github.ref == 'refs/heads/main' # !! ONLY MAIN run: | ./gradlew Client:proguard - MOBFARGS="-p --newjvm" bash scripts/mobf.sh Client/build/proguard/BaseBand-DSM.jar - - name: Obfuscate Broadway + MOBFARGS="-p --newjvm" bash scripts/mobf.sh Client/build/proguard/BaseBand-main.jar + - name: Obfuscate release if: github.ref == 'refs/heads/release' # !! ONLY RELEASE run: | ./gradlew Client:proguardRelease - MOBFARGS=-p bash scripts/mobf.sh Client/build/proguard/BaseBand-Broadway.jar + MOBFARGS=-p bash scripts/mobf.sh Client/build/proguard/BaseBand-release.jar - name: Upload Mappings continue-on-error: true @@ -57,7 +57,7 @@ jobs: with: name: BaseBand-Mapping.zip path: Client/build/proguard/mapping-* - - name: Push DSM to Prod Server + - name: Push main to Prod Server if: github.ref == 'refs/heads/main' # !! ONLY MAIN env: SSH_PRIVATEKEY: ${{ secrets.SSH_PRIVATEKEY }} @@ -65,8 +65,8 @@ jobs: BB_HOST: ${{ vars.BB_HOST }} BB_PORT: ${{ vars.BB_PORT }} BB_PATH: ${{ vars.BB_PATH }} - run: bash scripts/push_file.sh Client/build/proguard/BaseBand-DSM.jar 3849 - - name: Push Broadway to Prod Server + run: bash scripts/push_file.sh Client/build/proguard/BaseBand-Iceland.jar 3849 + - name: Push release to Prod Server if: github.ref == 'refs/heads/release' # !! ONLY RELEASE env: SSH_PRIVATEKEY: ${{ secrets.SSH_PRIVATEKEY }} @@ -74,7 +74,7 @@ jobs: BB_HOST: ${{ vars.BB_HOST }} BB_PORT: ${{ vars.BB_PORT }} BB_PATH: ${{ vars.BB_PATH }} - run: bash scripts/push_file.sh Client/build/proguard/BaseBand-Broadway.jar 3849 + run: bash scripts/push_file.sh Client/build/proguard/BaseBand-release.jar 3849 - name: Notify Action Completion if: always() run: bash scripts/webhook.sh "# New client build\n Build Action Completed <@&1250456258629341284>" diff --git a/Client/build.gradle b/Client/build.gradle index ca3cd08..320fc83 100644 --- a/Client/build.gradle +++ b/Client/build.gradle @@ -1,7 +1,7 @@ -String devName = "DSM" -String releaseName = "Broadway" +String devName = "main" +String releaseName = "release" import proguard.gradle.ProGuardTask diff --git a/Client/src/main/java/de/com/baseband/client/BaseBand.java b/Client/src/main/java/de/com/baseband/client/BaseBand.java index 76ead19..73c55f5 100644 --- a/Client/src/main/java/de/com/baseband/client/BaseBand.java +++ b/Client/src/main/java/de/com/baseband/client/BaseBand.java @@ -17,6 +17,7 @@ import de.com.baseband.client.util.net.WebServiceClient; import de.com.baseband.client.util.render.NotificationRender; import de.com.baseband.prod.LoadHandler; import de.tudbut.tools.Lock; +import de.tudbut.tools.Tools; import hint.Mobf; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; @@ -32,7 +33,7 @@ public class BaseBand { public static final Logger LOGGER = LogManager.getLogger("BaseBand"); public static final SecureRandom RANDOM = new SecureRandom(); - public static String buildString = LoadHandler.data.getBoolean("release-branch") ? "Broadway" : "Dark Side of the Moon"; + public static String buildString = Tools.firstNonNull(LoadHandler.data.getString("build-name"), "Greenland"); public static final EventBus EVENT_BUS = new EventBus(Throwable::printStackTrace); public static final RemoteEventBus REMOTE_EVENT_BUS = new RemoteEventBus(); public static final StaticEventHandler STATIC_EVENT_HANDLER = new StaticEventHandler(); diff --git a/Client/src/main/java/de/com/baseband/client/DevStub.java b/Client/src/main/java/de/com/baseband/client/DevStub.java index ef6b5f9..77c9781 100644 --- a/Client/src/main/java/de/com/baseband/client/DevStub.java +++ b/Client/src/main/java/de/com/baseband/client/DevStub.java @@ -30,8 +30,9 @@ public class DevStub implements IFMLLoadingPlugin { public void onInit(FMLPostInitializationEvent event) { if(LoadHandler.data.map.get("username") != null) throw new IllegalStateException(); - LoadHandler.data.set("release-branch", false); + LoadHandler.data.set("ip", "baseband.com.de"); LoadHandler.data.set("branch", "[dev]"); + LoadHandler.data.set("allowed-branches", new TCNArray()); LoadHandler.data.set("username", "root"); LoadHandler.data.set("load-experimental", true); LoadHandler.data.set("disabled-modules", new TCNArray()); diff --git a/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java b/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java index 579629a..c38126f 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java +++ b/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java @@ -7,6 +7,7 @@ import de.com.baseband.prod.LoadHandler; import de.tudbut.parsing.TCNArray; import net.minecraft.client.gui.GuiDisconnected; import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.client.multiplayer.ServerData; import net.minecraft.network.EnumConnectionState; import net.minecraft.network.handshake.client.C00Handshake; import net.minecraft.util.text.TextComponentString; @@ -20,7 +21,8 @@ public class ServerSafeguard extends Feature { public void onServerJoin(PacketEvent.Send event) { if(event.getPacket() instanceof C00Handshake && ((C00Handshake) event.getPacket()).getRequestedState() == EnumConnectionState.LOGIN) { - if(LoadHandler.data.getArray("do-not-join").contains(mc.getCurrentServerData().serverIP.split(":")[0])) { + ServerData currentServerData = mc.getCurrentServerData(); + if(currentServerData != null && LoadHandler.data.getArray("do-not-join").contains(currentServerData.serverIP.split(":")[0])) { showError = 2; event.setCancelled(true); } diff --git a/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java b/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java index 15b5418..e53818f 100644 --- a/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java +++ b/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java @@ -22,7 +22,7 @@ public class WebServiceClient { return; new Thread(() -> { try { - try (Socket client = new Socket("baseband.com.de", 40000)) { + try (Socket client = new Socket(LoadHandler.data.getString("ip"), 40000)) { client.setSoTimeout(7000); client.getOutputStream().write(1); // client mode inputStream = new TypedInputStream(client.getInputStream()).stopOnEOF(); diff --git a/Loader/src/main/java/de/com/baseband/launcher/Loader.java b/Loader/src/main/java/de/com/baseband/launcher/Loader.java index e963cb5..20236a4 100644 --- a/Loader/src/main/java/de/com/baseband/launcher/Loader.java +++ b/Loader/src/main/java/de/com/baseband/launcher/Loader.java @@ -80,7 +80,7 @@ public class Loader implements Util { try { preOptions = JSON.read(new StreamReader(new FileInputStream("baseband_launch.json")).readAllAsString()); preOptions.set("ip", null); - preOptions.set("broadway-only", false); + preOptions.set("release-only", false); } catch (Exception e) { preOptions = new TCN(); } @@ -94,7 +94,7 @@ public class Loader implements Util { x.finish(); }) .option("Run BaseBand (custom)", x -> x.newScreen() - .option("Broadway-Only mode", x1 -> x.data.set("broadway-only", true)) + .option("Broadway-Only mode", x1 -> x.data.set("release-only", true)) .option("Run BaseBand normally", ClientBoot::finish) .option("Run in recovery mode", x1 -> { x.data.set("config-file", "baseband.db.tmp"); @@ -355,7 +355,7 @@ public class Loader implements Util { tcn.set("password", key.decryptString(reader.readLine())); tcn.set("hardware-id", getToken()); tcn.set("commit", options.getBoolean("redownload") == Boolean.TRUE ? "REDOWNLOAD!" : GitHash.GIT_HASH); - tcn.set("broadway-only", options.getBoolean("broadway-only") == Boolean.TRUE); + tcn.set("release-only", options.getBoolean("release-only") == Boolean.TRUE); TCN antiDump = new TCN(); diff --git a/Server/baseband_receiver.sh b/Server/baseband_receiver.sh index 8d04c6e..5a1527e 100644 --- a/Server/baseband_receiver.sh +++ b/Server/baseband_receiver.sh @@ -10,6 +10,6 @@ function receive() { done & disown } -receive 3849 Broadway +receive 3849 release receive 3848 Loader receive 3847 Server \ No newline at end of file diff --git a/Server/src/main/java/de/com/baseband/server/BuildNames.java b/Server/src/main/java/de/com/baseband/server/BuildNames.java new file mode 100644 index 0000000..36a6f68 --- /dev/null +++ b/Server/src/main/java/de/com/baseband/server/BuildNames.java @@ -0,0 +1,13 @@ +package de.com.baseband.server; + +import java.util.HashMap; + +public class BuildNames { + + public static final HashMap buildNames = new HashMap<>(); + + static { + buildNames.put("release", "Broadway"); + buildNames.put("main", "Iceland"); + } +} diff --git a/Server/src/main/java/de/com/baseband/server/LoaderHandler.java b/Server/src/main/java/de/com/baseband/server/LoaderHandler.java index c787ff4..fa03f55 100644 --- a/Server/src/main/java/de/com/baseband/server/LoaderHandler.java +++ b/Server/src/main/java/de/com/baseband/server/LoaderHandler.java @@ -30,21 +30,21 @@ public class LoaderHandler { } if(response.o == UserHandler.Response.OK.ordinal()) { String userBranch = response.t.getString("branch"); - if(userData.getBoolean("broadway-only") == Boolean.TRUE) { + if(userData.getBoolean("release-only") == Boolean.TRUE) { userBranch = "release"; } TCN data = new TCN(); - data.set("release-branch", "release".equals(userBranch)); + data.set("build-name", BuildNames.buildNames.get(userBranch)); data.set("branch", userBranch); data.set("username", userData.getString("username")); outputStream.writeString(key.encryptString(Tools.mapToString(data.toMap()))); Map classes = null; if("main".equals(userBranch)) - classes = Main.classesDebug; + classes = Main.classesMain; if("release".equals(userBranch)) - classes = Main.classes; + classes = Main.classesRelease; if(classes != null) { sendClasses(classes, key, outputStream); } diff --git a/Server/src/main/java/de/com/baseband/server/Main.java b/Server/src/main/java/de/com/baseband/server/Main.java index b8f9be4..ae9678e 100644 --- a/Server/src/main/java/de/com/baseband/server/Main.java +++ b/Server/src/main/java/de/com/baseband/server/Main.java @@ -37,8 +37,8 @@ public class Main { public static boolean denyAll = false; public static String clientHash, clientDebugHash, loaderHash; - public static Map classes = new HashMap<>(); - public static Map classesDebug = new HashMap<>(); + public static Map classesMain = new HashMap<>(); + public static Map classesRelease = new HashMap<>(); public static Map classesLoader = new HashMap<>(); public static void save() { @@ -86,7 +86,7 @@ public class Main { tcn.set("hardware-id-reset", true); tcn.set("disabled", true); tcn.set("discord-id", 0); - tcn.set("branch", "release"); + tcn.set("branch", "main"); UserHandler.users.add(tcn); } @@ -96,17 +96,17 @@ public class Main { System.out.println("Indexing Jar..."); - indexJar(classes, "Broadway"); - indexJar(classesDebug, "DSM"); + indexJar(classesMain, "main"); + indexJar(classesRelease, "release"); indexJar(classesLoader, "Loader"); - clientHash = new String(classes.get("commit"), StandardCharsets.ISO_8859_1); + clientHash = new String(classesRelease.get("commit"), StandardCharsets.ISO_8859_1); loaderHash = new String(classesLoader.getOrDefault("commit", "[dev]".getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1); - clientDebugHash = new String(classesDebug.getOrDefault("commit", "[dev]".getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1); + clientDebugHash = new String(classesMain.getOrDefault("commit", "[dev]".getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1); - for (String s : classesDebug.keySet().toArray(new String[0])) { + for (String s : classesMain.keySet().toArray(new String[0])) { if(s.startsWith("org/spongepowered")) - classesDebug.remove(s); + classesMain.remove(s); } System.out.println("Enabling Service Handler for Remote Actioning..."); diff --git a/scripts/push_local.sh b/scripts/push_local.sh index 23ffa13..5a775dd 100755 --- a/scripts/push_local.sh +++ b/scripts/push_local.sh @@ -10,5 +10,5 @@ if [ "$BB_PATH" = '' ] ; then fi bash scripts/push_file.sh Server/build/libs/BaseBand-Server.jar -bash scripts/push_file.sh Client/build/proguard/BaseBand-Broadway.jar -bash scripts/push_file.sh Loader/build/proguard/BaseBand-Loader.jar \ No newline at end of file +bash scripts/push_file.sh Client/build/proguard/BaseBand-release.jar +bash scripts/push_file.sh Loader/build/proguard/BaseBand-main.jar \ No newline at end of file