From ed5e46314185d8b65839068cdcb3425f3f78462a Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sun, 6 Oct 2024 05:46:59 +0200 Subject: [PATCH] fix a crash, display commit at startup --- .../java/de/com/baseband/client/BaseBand.java | 3 +-- .../java/de/com/baseband/client/DevStub.java | 2 ++ .../feature/modules/client/PacketCounter.java | 22 ++++++++++++------- .../java/de/com/baseband/launcher/Loader.java | 3 ++- 4 files changed, 19 insertions(+), 11 deletions(-) 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 644c624..64cc3fd 100644 --- a/Client/src/main/java/de/com/baseband/client/BaseBand.java +++ b/Client/src/main/java/de/com/baseband/client/BaseBand.java @@ -17,7 +17,6 @@ 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; @@ -33,7 +32,7 @@ public class BaseBand { public static final Logger LOGGER = LogManager.getLogger("BaseBand"); public static final SecureRandom RANDOM = new SecureRandom(); - public static String buildString = Tools.firstNonNull(LoadHandler.data.getString("build-name"), "Greenland"); + public static String buildString = LoadHandler.data.getString("build-name"); 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 77c9781..9b62f6f 100644 --- a/Client/src/main/java/de/com/baseband/client/DevStub.java +++ b/Client/src/main/java/de/com/baseband/client/DevStub.java @@ -28,8 +28,10 @@ public class DevStub implements IFMLLoadingPlugin { @Mod.EventHandler public void onInit(FMLPostInitializationEvent event) { + LOGGER.info("Booting BaseBand Greenland..."); if(LoadHandler.data.map.get("username") != null) throw new IllegalStateException(); + LoadHandler.data.set("build-name", "Greenland"); LoadHandler.data.set("ip", "baseband.com.de"); LoadHandler.data.set("branch", "[dev]"); LoadHandler.data.set("allowed-branches", new TCNArray()); diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/PacketCounter.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/PacketCounter.java index 2f20d16..cd9ca59 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/PacketCounter.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/PacketCounter.java @@ -16,7 +16,7 @@ import java.util.Queue; public class PacketCounter extends Feature { long totUp = 0, totDown = 0; - Queue up = new LinkedList<>(), down = new LinkedList<>(); + final Queue up = new LinkedList<>(), down = new LinkedList<>(); @Config("Abbreviate") @Description("Abbreviates numbers with ...K and ...M once they get too large.") @@ -51,11 +51,13 @@ public class PacketCounter extends Feature { } private void processQueue(Queue queue) { - while (!queue.isEmpty()) { - if(queue.peek().passed()) - queue.remove(); - else - break; + synchronized (queue) { + while (!queue.isEmpty()) { + if (queue.peek().passed()) + queue.remove(); + else + break; + } } } @@ -68,11 +70,15 @@ public class PacketCounter extends Feature { public void onPacket(PacketEvent event) { if(event instanceof PacketEvent.Send) { totUp ++; - up.add(new PacketTimestamp()); + synchronized (up) { + up.add(new PacketTimestamp()); + } } if(event instanceof PacketEvent.Receive) { totDown ++; - down.add(new PacketTimestamp()); + synchronized (down) { + down.add(new PacketTimestamp()); + } } } 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 be18263..4b3b0dd 100644 --- a/Loader/src/main/java/de/com/baseband/launcher/Loader.java +++ b/Loader/src/main/java/de/com/baseband/launcher/Loader.java @@ -288,7 +288,7 @@ public class Loader implements Util { LOGGER.warn("No new BaseBand chunk has been downloaded in 2 seconds. Consider restarting your game."); } else if(System.currentTimeMillis() - lastUpdate >= 500) { - LOGGER.info("Downloading at {}KB/s...", (int) ((bytes.get() / 1024f) * (System.currentTimeMillis() - lastUpdate) / 1000f)); + //LOGGER.info("Downloading at {}KB/s...", (int) ((bytes.get() / 1024f) * (System.currentTimeMillis() - lastUpdate) / 1000f)); lastUpdate = System.currentTimeMillis(); bytes.set(0); } @@ -308,6 +308,7 @@ public class Loader implements Util { continueDownload.waitHere(); } LOGGER.info("BaseBand downloaded: {} chunks.", data.size()); + LOGGER.info("Booting BaseBand {} @ {}", clientData.getString("build-name"), new String(data.get("commit")).trim()); classLoader = new CustomClassLoader(data); downloadUpdated.unlock(); classLoader.inject();