From 4cd180141c9112ce26a3419fdc3ef321597d7377 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 13 Aug 2023 09:39:16 -0400 Subject: [PATCH] Read current repo branch using MB Devops script. --- src/engine/gameManager/ConfigManager.java | 34 ++++++++++++++++++- .../handlers/ArcLoginNotifyMsgHandler.java | 5 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 07aa3206..9ca6b598 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -18,6 +18,10 @@ import engine.server.login.LoginServer; import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; @@ -107,11 +111,13 @@ public enum ConfigManager { public static LoginServer loginServer; public static Map regex = new HashMap<>(); + public static String currentRepoBranch = ""; + // Called at bootstrap: ensures that all config values are loaded. public static boolean init() { - Logger.info("Loading config from environment..."); + Logger.info("Loading config from environment."); for (ConfigManager configSetting : ConfigManager.values()) if (configMap.containsKey(configSetting.name())) @@ -123,6 +129,32 @@ public enum ConfigManager { return false; } + Logger.info("Determine current Repo branch"); + + File file = new File("mbbranch.sh"); + + if (file.exists() && !file.isDirectory()) { + + String[] command = {"./mbbranch"}; + + try { + + Process process = Runtime.getRuntime().exec(command); + BufferedReader reader = new BufferedReader(new InputStreamReader( + process.getInputStream())); + String string; + + while (true) { + if ((string = reader.readLine()) == null) + break; + currentRepoBranch += string; + } + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + // compile regex here Logger.info("Compiling regex"); diff --git a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java index b9986be9..02b0518c 100644 --- a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java +++ b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java @@ -67,6 +67,11 @@ public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler { GuildManager.enterWorldMOTD(player); ChatManager.sendSystemMessage(player, ConfigManager.MB_WORLD_GREETING.getValue()); + // Send branch string if available from ConfigManager. + + if (ConfigManager.currentRepoBranch != "") + ChatManager.sendSystemMessage(player, ConfigManager.currentRepoBranch); + // Set player mask for QT if (player.getRace() != null && player.getRace().getToken() == -524731385) player.setObjectTypeMask(MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD);